Adam Lesinski | d0f492d | 2017-04-03 18:12:45 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <memory> |
| 18 | #include <vector> |
| 19 | |
Shane Farmer | 5766943 | 2017-06-19 12:52:04 -0700 | [diff] [blame] | 20 | #include "android-base/stringprintf.h" |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 21 | #include "androidfw/ResourceTypes.h" |
Adam Lesinski | d0f492d | 2017-04-03 18:12:45 -0700 | [diff] [blame] | 22 | #include "androidfw/StringPiece.h" |
| 23 | |
| 24 | #include "Diagnostics.h" |
| 25 | #include "Flags.h" |
| 26 | #include "LoadedApk.h" |
| 27 | #include "ResourceUtils.h" |
| 28 | #include "SdkConstants.h" |
| 29 | #include "ValueVisitor.h" |
| 30 | #include "cmd/Util.h" |
Shane Farmer | 5766943 | 2017-06-19 12:52:04 -0700 | [diff] [blame] | 31 | #include "configuration/ConfigurationParser.h" |
| 32 | #include "filter/AbiFilter.h" |
Adam Lesinski | d0f492d | 2017-04-03 18:12:45 -0700 | [diff] [blame] | 33 | #include "flatten/TableFlattener.h" |
| 34 | #include "flatten/XmlFlattener.h" |
| 35 | #include "io/BigBufferInputStream.h" |
| 36 | #include "io/Util.h" |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 37 | #include "optimize/MultiApkGenerator.h" |
Adam Lesinski | d0f492d | 2017-04-03 18:12:45 -0700 | [diff] [blame] | 38 | #include "optimize/ResourceDeduper.h" |
| 39 | #include "optimize/VersionCollapser.h" |
| 40 | #include "split/TableSplitter.h" |
Shane Farmer | 5766943 | 2017-06-19 12:52:04 -0700 | [diff] [blame] | 41 | #include "util/Files.h" |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 42 | #include "util/Util.h" |
Adam Lesinski | d0f492d | 2017-04-03 18:12:45 -0700 | [diff] [blame] | 43 | |
Shane Farmer | 5766943 | 2017-06-19 12:52:04 -0700 | [diff] [blame] | 44 | using ::aapt::configuration::Abi; |
| 45 | using ::aapt::configuration::Artifact; |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 46 | using ::aapt::configuration::PostProcessingConfiguration; |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 47 | using ::android::ResTable_config; |
Shane Farmer | 5766943 | 2017-06-19 12:52:04 -0700 | [diff] [blame] | 48 | using ::android::StringPiece; |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 49 | using ::android::base::StringAppendF; |
Shane Farmer | 5766943 | 2017-06-19 12:52:04 -0700 | [diff] [blame] | 50 | using ::android::base::StringPrintf; |
Adam Lesinski | d0f492d | 2017-04-03 18:12:45 -0700 | [diff] [blame] | 51 | |
| 52 | namespace aapt { |
| 53 | |
| 54 | struct OptimizeOptions { |
| 55 | // Path to the output APK. |
Shane Farmer | 5766943 | 2017-06-19 12:52:04 -0700 | [diff] [blame] | 56 | Maybe<std::string> output_path; |
| 57 | // Path to the output APK directory for splits. |
| 58 | Maybe<std::string> output_dir; |
Adam Lesinski | d0f492d | 2017-04-03 18:12:45 -0700 | [diff] [blame] | 59 | |
| 60 | // Details of the app extracted from the AndroidManifest.xml |
| 61 | AppInfo app_info; |
| 62 | |
| 63 | // Split APK options. |
| 64 | TableSplitterOptions table_splitter_options; |
| 65 | |
| 66 | // List of output split paths. These are in the same order as `split_constraints`. |
| 67 | std::vector<std::string> split_paths; |
| 68 | |
| 69 | // List of SplitConstraints governing what resources go into each split. Ordered by `split_paths`. |
| 70 | std::vector<SplitConstraints> split_constraints; |
| 71 | |
| 72 | TableFlattenerOptions table_flattener_options; |
Shane Farmer | 5766943 | 2017-06-19 12:52:04 -0700 | [diff] [blame] | 73 | |
Shane Farmer | 280be34 | 2017-06-21 15:20:15 -0700 | [diff] [blame] | 74 | Maybe<PostProcessingConfiguration> configuration; |
Adam Lesinski | d0f492d | 2017-04-03 18:12:45 -0700 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | class OptimizeContext : public IAaptContext { |
| 78 | public: |
Adam Lesinski | b522f04 | 2017-04-21 16:57:59 -0700 | [diff] [blame] | 79 | OptimizeContext() = default; |
| 80 | |
| 81 | PackageType GetPackageType() override { |
| 82 | // Not important here. Using anything other than kApp adds EXTRA validation, which we want to |
| 83 | // avoid. |
| 84 | return PackageType::kApp; |
| 85 | } |
| 86 | |
Adam Lesinski | d0f492d | 2017-04-03 18:12:45 -0700 | [diff] [blame] | 87 | IDiagnostics* GetDiagnostics() override { |
| 88 | return &diagnostics_; |
| 89 | } |
| 90 | |
| 91 | NameMangler* GetNameMangler() override { |
| 92 | UNIMPLEMENTED(FATAL); |
| 93 | return nullptr; |
| 94 | } |
| 95 | |
| 96 | const std::string& GetCompilationPackage() override { |
| 97 | static std::string empty; |
| 98 | return empty; |
| 99 | } |
| 100 | |
| 101 | uint8_t GetPackageId() override { |
| 102 | return 0; |
| 103 | } |
| 104 | |
| 105 | SymbolTable* GetExternalSymbols() override { |
| 106 | UNIMPLEMENTED(FATAL); |
| 107 | return nullptr; |
| 108 | } |
| 109 | |
| 110 | bool IsVerbose() override { |
| 111 | return verbose_; |
| 112 | } |
| 113 | |
| 114 | void SetVerbose(bool val) { |
| 115 | verbose_ = val; |
| 116 | } |
| 117 | |
| 118 | void SetMinSdkVersion(int sdk_version) { |
| 119 | sdk_version_ = sdk_version; |
| 120 | } |
| 121 | |
| 122 | int GetMinSdkVersion() override { |
| 123 | return sdk_version_; |
| 124 | } |
| 125 | |
| 126 | private: |
Adam Lesinski | b522f04 | 2017-04-21 16:57:59 -0700 | [diff] [blame] | 127 | DISALLOW_COPY_AND_ASSIGN(OptimizeContext); |
| 128 | |
Adam Lesinski | d0f492d | 2017-04-03 18:12:45 -0700 | [diff] [blame] | 129 | StdErrDiagnostics diagnostics_; |
| 130 | bool verbose_ = false; |
| 131 | int sdk_version_ = 0; |
| 132 | }; |
| 133 | |
| 134 | class OptimizeCommand { |
| 135 | public: |
| 136 | OptimizeCommand(OptimizeContext* context, const OptimizeOptions& options) |
| 137 | : options_(options), context_(context) { |
| 138 | } |
| 139 | |
| 140 | int Run(std::unique_ptr<LoadedApk> apk) { |
| 141 | if (context_->IsVerbose()) { |
| 142 | context_->GetDiagnostics()->Note(DiagMessage() << "Optimizing APK..."); |
| 143 | } |
| 144 | |
| 145 | VersionCollapser collapser; |
| 146 | if (!collapser.Consume(context_, apk->GetResourceTable())) { |
| 147 | return 1; |
| 148 | } |
| 149 | |
| 150 | ResourceDeduper deduper; |
| 151 | if (!deduper.Consume(context_, apk->GetResourceTable())) { |
| 152 | context_->GetDiagnostics()->Error(DiagMessage() << "failed deduping resources"); |
| 153 | return 1; |
| 154 | } |
| 155 | |
| 156 | // Adjust the SplitConstraints so that their SDK version is stripped if it is less than or |
| 157 | // equal to the minSdk. |
| 158 | options_.split_constraints = |
| 159 | AdjustSplitConstraintsForMinSdk(context_->GetMinSdkVersion(), options_.split_constraints); |
| 160 | |
| 161 | // Stripping the APK using the TableSplitter. The resource table is modified in place in the |
| 162 | // LoadedApk. |
| 163 | TableSplitter splitter(options_.split_constraints, options_.table_splitter_options); |
| 164 | if (!splitter.VerifySplitConstraints(context_)) { |
| 165 | return 1; |
| 166 | } |
| 167 | splitter.SplitTable(apk->GetResourceTable()); |
| 168 | |
| 169 | auto path_iter = options_.split_paths.begin(); |
| 170 | auto split_constraints_iter = options_.split_constraints.begin(); |
| 171 | for (std::unique_ptr<ResourceTable>& split_table : splitter.splits()) { |
| 172 | if (context_->IsVerbose()) { |
| 173 | context_->GetDiagnostics()->Note( |
| 174 | DiagMessage(*path_iter) << "generating split with configurations '" |
| 175 | << util::Joiner(split_constraints_iter->configs, ", ") << "'"); |
| 176 | } |
| 177 | |
| 178 | // Generate an AndroidManifest.xml for each split. |
| 179 | std::unique_ptr<xml::XmlResource> split_manifest = |
| 180 | GenerateSplitManifest(options_.app_info, *split_constraints_iter); |
| 181 | std::unique_ptr<IArchiveWriter> split_writer = |
| 182 | CreateZipFileArchiveWriter(context_->GetDiagnostics(), *path_iter); |
| 183 | if (!split_writer) { |
| 184 | return 1; |
| 185 | } |
| 186 | |
| 187 | if (!WriteSplitApk(split_table.get(), split_manifest.get(), split_writer.get())) { |
| 188 | return 1; |
| 189 | } |
| 190 | |
| 191 | ++path_iter; |
| 192 | ++split_constraints_iter; |
| 193 | } |
| 194 | |
Shane Farmer | 5766943 | 2017-06-19 12:52:04 -0700 | [diff] [blame] | 195 | if (options_.configuration && options_.output_dir) { |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 196 | MultiApkGenerator generator{apk.get(), context_}; |
| 197 | if (!generator.FromBaseApk(options_.output_dir.value(), options_.configuration.value(), |
| 198 | options_.table_flattener_options)) { |
| 199 | return 1; |
Shane Farmer | 5766943 | 2017-06-19 12:52:04 -0700 | [diff] [blame] | 200 | } |
| 201 | } |
| 202 | |
| 203 | if (options_.output_path) { |
| 204 | std::unique_ptr<IArchiveWriter> writer = |
| 205 | CreateZipFileArchiveWriter(context_->GetDiagnostics(), options_.output_path.value()); |
| 206 | if (!apk->WriteToArchive(context_, options_.table_flattener_options, writer.get())) { |
| 207 | return 1; |
| 208 | } |
Adam Lesinski | d0f492d | 2017-04-03 18:12:45 -0700 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | return 0; |
| 212 | } |
| 213 | |
| 214 | private: |
| 215 | bool WriteSplitApk(ResourceTable* table, xml::XmlResource* manifest, IArchiveWriter* writer) { |
| 216 | BigBuffer manifest_buffer(4096); |
| 217 | XmlFlattener xml_flattener(&manifest_buffer, {}); |
| 218 | if (!xml_flattener.Consume(context_, manifest)) { |
| 219 | return false; |
| 220 | } |
| 221 | |
| 222 | io::BigBufferInputStream manifest_buffer_in(&manifest_buffer); |
| 223 | if (!io::CopyInputStreamToArchive(context_, &manifest_buffer_in, "AndroidManifest.xml", |
| 224 | ArchiveEntry::kCompress, writer)) { |
| 225 | return false; |
| 226 | } |
| 227 | |
| 228 | std::map<std::pair<ConfigDescription, StringPiece>, FileReference*> config_sorted_files; |
| 229 | for (auto& pkg : table->packages) { |
| 230 | for (auto& type : pkg->types) { |
| 231 | // Sort by config and name, so that we get better locality in the zip file. |
| 232 | config_sorted_files.clear(); |
| 233 | |
| 234 | for (auto& entry : type->entries) { |
| 235 | for (auto& config_value : entry->values) { |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 236 | auto* file_ref = ValueCast<FileReference>(config_value->value.get()); |
Adam Lesinski | d0f492d | 2017-04-03 18:12:45 -0700 | [diff] [blame] | 237 | if (file_ref == nullptr) { |
| 238 | continue; |
| 239 | } |
| 240 | |
| 241 | if (file_ref->file == nullptr) { |
| 242 | ResourceNameRef name(pkg->name, type->type, entry->name); |
Adam Lesinski | 742888f | 2017-04-28 15:34:52 -0700 | [diff] [blame] | 243 | context_->GetDiagnostics()->Warn(DiagMessage(file_ref->GetSource()) |
Shane Farmer | 5766943 | 2017-06-19 12:52:04 -0700 | [diff] [blame] | 244 | << "file for resource " << name << " with config '" |
| 245 | << config_value->config << "' not found"); |
Adam Lesinski | 742888f | 2017-04-28 15:34:52 -0700 | [diff] [blame] | 246 | continue; |
Adam Lesinski | d0f492d | 2017-04-03 18:12:45 -0700 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | const StringPiece entry_name = entry->name; |
| 250 | config_sorted_files[std::make_pair(config_value->config, entry_name)] = file_ref; |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | for (auto& entry : config_sorted_files) { |
| 255 | FileReference* file_ref = entry.second; |
| 256 | uint32_t compression_flags = |
| 257 | file_ref->file->WasCompressed() ? ArchiveEntry::kCompress : 0u; |
| 258 | if (!io::CopyFileToArchive(context_, file_ref->file, *file_ref->path, compression_flags, |
| 259 | writer)) { |
| 260 | return false; |
| 261 | } |
| 262 | } |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | BigBuffer table_buffer(4096); |
| 267 | TableFlattener table_flattener(options_.table_flattener_options, &table_buffer); |
| 268 | if (!table_flattener.Consume(context_, table)) { |
| 269 | return false; |
| 270 | } |
| 271 | |
| 272 | io::BigBufferInputStream table_buffer_in(&table_buffer); |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 273 | return io::CopyInputStreamToArchive(context_, &table_buffer_in, "resources.arsc", |
| 274 | ArchiveEntry::kAlign, writer); |
Adam Lesinski | d0f492d | 2017-04-03 18:12:45 -0700 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | OptimizeOptions options_; |
| 278 | OptimizeContext* context_; |
| 279 | }; |
| 280 | |
| 281 | bool ExtractAppDataFromManifest(OptimizeContext* context, LoadedApk* apk, |
| 282 | OptimizeOptions* out_options) { |
| 283 | io::IFile* manifest_file = apk->GetFileCollection()->FindFile("AndroidManifest.xml"); |
| 284 | if (manifest_file == nullptr) { |
| 285 | context->GetDiagnostics()->Error(DiagMessage(apk->GetSource()) |
| 286 | << "missing AndroidManifest.xml"); |
| 287 | return false; |
| 288 | } |
| 289 | |
| 290 | std::unique_ptr<io::IData> data = manifest_file->OpenAsData(); |
| 291 | if (data == nullptr) { |
| 292 | context->GetDiagnostics()->Error(DiagMessage(manifest_file->GetSource()) |
| 293 | << "failed to open file"); |
| 294 | return false; |
| 295 | } |
| 296 | |
| 297 | std::unique_ptr<xml::XmlResource> manifest = xml::Inflate( |
| 298 | data->data(), data->size(), context->GetDiagnostics(), manifest_file->GetSource()); |
| 299 | if (manifest == nullptr) { |
| 300 | context->GetDiagnostics()->Error(DiagMessage() << "failed to read binary AndroidManifest.xml"); |
| 301 | return false; |
| 302 | } |
| 303 | |
| 304 | Maybe<AppInfo> app_info = |
| 305 | ExtractAppInfoFromBinaryManifest(manifest.get(), context->GetDiagnostics()); |
| 306 | if (!app_info) { |
| 307 | context->GetDiagnostics()->Error(DiagMessage() |
| 308 | << "failed to extract data from AndroidManifest.xml"); |
| 309 | return false; |
| 310 | } |
| 311 | |
| 312 | out_options->app_info = std::move(app_info.value()); |
| 313 | context->SetMinSdkVersion(out_options->app_info.min_sdk_version.value_or_default(0)); |
| 314 | return true; |
| 315 | } |
| 316 | |
| 317 | int Optimize(const std::vector<StringPiece>& args) { |
| 318 | OptimizeContext context; |
| 319 | OptimizeOptions options; |
Shane Farmer | 5766943 | 2017-06-19 12:52:04 -0700 | [diff] [blame] | 320 | Maybe<std::string> config_path; |
Adam Lesinski | d0f492d | 2017-04-03 18:12:45 -0700 | [diff] [blame] | 321 | Maybe<std::string> target_densities; |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 322 | Maybe<std::string> target_abis; |
Adam Lesinski | d0f492d | 2017-04-03 18:12:45 -0700 | [diff] [blame] | 323 | std::vector<std::string> configs; |
| 324 | std::vector<std::string> split_args; |
| 325 | bool verbose = false; |
| 326 | Flags flags = |
| 327 | Flags() |
Shane Farmer | 5766943 | 2017-06-19 12:52:04 -0700 | [diff] [blame] | 328 | .OptionalFlag("-o", "Path to the output APK.", &options.output_path) |
| 329 | .OptionalFlag("-d", "Path to the output directory (for splits).", &options.output_dir) |
| 330 | .OptionalFlag("-x", "Path to XML configuration file.", &config_path) |
Adam Lesinski | d0f492d | 2017-04-03 18:12:45 -0700 | [diff] [blame] | 331 | .OptionalFlag( |
| 332 | "--target-densities", |
| 333 | "Comma separated list of the screen densities that the APK will be optimized for.\n" |
| 334 | "All the resources that would be unused on devices of the given densities will be \n" |
| 335 | "removed from the APK.", |
| 336 | &target_densities) |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 337 | .OptionalFlag( |
| 338 | "--target-abis", |
| 339 | "Comma separated list of the CPU ABIs that the APK will be optimized for.\n" |
| 340 | "All the native libraries that would be unused on devices of the given ABIs will \n" |
| 341 | "be removed from the APK.", |
| 342 | &target_abis) |
Adam Lesinski | d0f492d | 2017-04-03 18:12:45 -0700 | [diff] [blame] | 343 | .OptionalFlagList("-c", |
| 344 | "Comma separated list of configurations to include. The default\n" |
| 345 | "is all configurations.", |
| 346 | &configs) |
| 347 | .OptionalFlagList("--split", |
| 348 | "Split resources matching a set of configs out to a " |
Adam Lesinski | db09157 | 2017-04-13 12:48:56 -0700 | [diff] [blame] | 349 | "Split APK.\nSyntax: path/to/output.apk;<config>[,<config>[...]].\n" |
| 350 | "On Windows, use a semicolon ';' separator instead.", |
Adam Lesinski | d0f492d | 2017-04-03 18:12:45 -0700 | [diff] [blame] | 351 | &split_args) |
| 352 | .OptionalSwitch("--enable-sparse-encoding", |
| 353 | "Enables encoding sparse entries using a binary search tree.\n" |
| 354 | "This decreases APK size at the cost of resource retrieval performance.", |
| 355 | &options.table_flattener_options.use_sparse_entries) |
| 356 | .OptionalSwitch("-v", "Enables verbose logging", &verbose); |
| 357 | |
| 358 | if (!flags.Parse("aapt2 optimize", args, &std::cerr)) { |
| 359 | return 1; |
| 360 | } |
| 361 | |
| 362 | if (flags.GetArgs().size() != 1u) { |
| 363 | std::cerr << "must have one APK as argument.\n\n"; |
| 364 | flags.Usage("aapt2 optimize", &std::cerr); |
| 365 | return 1; |
| 366 | } |
| 367 | |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 368 | const std::string& apk_path = flags.GetArgs()[0]; |
| 369 | std::unique_ptr<LoadedApk> apk = LoadedApk::LoadApkFromPath(&context, apk_path); |
Adam Lesinski | d0f492d | 2017-04-03 18:12:45 -0700 | [diff] [blame] | 370 | if (!apk) { |
| 371 | return 1; |
| 372 | } |
| 373 | |
| 374 | context.SetVerbose(verbose); |
| 375 | |
| 376 | if (target_densities) { |
| 377 | // Parse the target screen densities. |
| 378 | for (const StringPiece& config_str : util::Tokenize(target_densities.value(), ',')) { |
| 379 | Maybe<uint16_t> target_density = |
| 380 | ParseTargetDensityParameter(config_str, context.GetDiagnostics()); |
| 381 | if (!target_density) { |
| 382 | return 1; |
| 383 | } |
| 384 | options.table_splitter_options.preferred_densities.push_back(target_density.value()); |
| 385 | } |
| 386 | } |
| 387 | |
| 388 | std::unique_ptr<IConfigFilter> filter; |
| 389 | if (!configs.empty()) { |
| 390 | filter = ParseConfigFilterParameters(configs, context.GetDiagnostics()); |
| 391 | if (filter == nullptr) { |
| 392 | return 1; |
| 393 | } |
| 394 | options.table_splitter_options.config_filter = filter.get(); |
| 395 | } |
| 396 | |
| 397 | // Parse the split parameters. |
| 398 | for (const std::string& split_arg : split_args) { |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 399 | options.split_paths.emplace_back(); |
| 400 | options.split_constraints.emplace_back(); |
Adam Lesinski | d0f492d | 2017-04-03 18:12:45 -0700 | [diff] [blame] | 401 | if (!ParseSplitParameter(split_arg, context.GetDiagnostics(), &options.split_paths.back(), |
| 402 | &options.split_constraints.back())) { |
| 403 | return 1; |
| 404 | } |
| 405 | } |
| 406 | |
Shane Farmer | 5766943 | 2017-06-19 12:52:04 -0700 | [diff] [blame] | 407 | if (config_path) { |
| 408 | if (!options.output_dir) { |
| 409 | context.GetDiagnostics()->Error( |
| 410 | DiagMessage() << "Output directory is required when using a configuration file"); |
| 411 | return 1; |
| 412 | } |
| 413 | std::string& path = config_path.value(); |
| 414 | Maybe<ConfigurationParser> for_path = ConfigurationParser::ForPath(path); |
| 415 | if (for_path) { |
| 416 | options.configuration = for_path.value().WithDiagnostics(context.GetDiagnostics()).Parse(); |
| 417 | } else { |
| 418 | context.GetDiagnostics()->Error(DiagMessage() << "Could not parse config file " << path); |
| 419 | return 1; |
| 420 | } |
| 421 | } |
| 422 | |
Adam Lesinski | d0f492d | 2017-04-03 18:12:45 -0700 | [diff] [blame] | 423 | if (!ExtractAppDataFromManifest(&context, apk.get(), &options)) { |
| 424 | return 1; |
| 425 | } |
| 426 | |
| 427 | OptimizeCommand cmd(&context, options); |
| 428 | return cmd.Run(std::move(apk)); |
| 429 | } |
| 430 | |
| 431 | } // namespace aapt |