blob: 2e6af18c1948bd623b2fb8c9a9d4366e483e78e8 [file] [log] [blame]
Adam Lesinskid0f492d2017-04-03 18:12:45 -07001/*
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
Ryan Mitchell833a1a62018-07-10 13:51:36 -070017#include "Optimize.h"
18
Adam Lesinskid0f492d2017-04-03 18:12:45 -070019#include <memory>
20#include <vector>
21
Luke Nicholsonb0643302017-12-01 15:29:03 -080022#include "android-base/file.h"
Shane Farmer57669432017-06-19 12:52:04 -070023#include "android-base/stringprintf.h"
Adam Lesinskid3ffa8442017-09-28 13:34:35 -070024
Mårten Kongstad24c9aa62018-06-20 08:46:41 +020025#include "androidfw/ConfigDescription.h"
Shane Farmer0a5b2012017-06-22 12:24:12 -070026#include "androidfw/ResourceTypes.h"
Adam Lesinskid0f492d2017-04-03 18:12:45 -070027#include "androidfw/StringPiece.h"
28
29#include "Diagnostics.h"
Adam Lesinskid0f492d2017-04-03 18:12:45 -070030#include "LoadedApk.h"
31#include "ResourceUtils.h"
32#include "SdkConstants.h"
33#include "ValueVisitor.h"
34#include "cmd/Util.h"
Shane Farmer57669432017-06-19 12:52:04 -070035#include "configuration/ConfigurationParser.h"
36#include "filter/AbiFilter.h"
Adam Lesinski46708052017-09-29 14:49:15 -070037#include "format/binary/TableFlattener.h"
38#include "format/binary/XmlFlattener.h"
Adam Lesinski00451162017-10-03 07:44:08 -070039#include "io/BigBufferStream.h"
Adam Lesinskid0f492d2017-04-03 18:12:45 -070040#include "io/Util.h"
Shane Farmer0a5b2012017-06-22 12:24:12 -070041#include "optimize/MultiApkGenerator.h"
Adam Lesinskid0f492d2017-04-03 18:12:45 -070042#include "optimize/ResourceDeduper.h"
Mohamed Heikald3c5fb62018-01-12 11:37:26 -050043#include "optimize/ResourceFilter.h"
Mohamed Heikalc7694032018-11-07 16:49:02 -050044#include "optimize/ResourcePathShortener.h"
Adam Lesinskid0f492d2017-04-03 18:12:45 -070045#include "optimize/VersionCollapser.h"
46#include "split/TableSplitter.h"
Shane Farmer57669432017-06-19 12:52:04 -070047#include "util/Files.h"
Shane Farmer0a5b2012017-06-22 12:24:12 -070048#include "util/Util.h"
Adam Lesinskid0f492d2017-04-03 18:12:45 -070049
Shane Farmer57669432017-06-19 12:52:04 -070050using ::aapt::configuration::Abi;
Shane Farmercb6c3f92017-11-27 13:19:36 -080051using ::aapt::configuration::OutputArtifact;
Mårten Kongstad24c9aa62018-06-20 08:46:41 +020052using ::android::ConfigDescription;
Shane Farmer0a5b2012017-06-22 12:24:12 -070053using ::android::ResTable_config;
Shane Farmer57669432017-06-19 12:52:04 -070054using ::android::StringPiece;
Luke Nicholsonb0643302017-12-01 15:29:03 -080055using ::android::base::ReadFileToString;
Mohamed Heikalc7694032018-11-07 16:49:02 -050056using ::android::base::WriteStringToFile;
Shane Farmer0a5b2012017-06-22 12:24:12 -070057using ::android::base::StringAppendF;
Shane Farmer57669432017-06-19 12:52:04 -070058using ::android::base::StringPrintf;
Adam Lesinskid0f492d2017-04-03 18:12:45 -070059
60namespace aapt {
61
Adam Lesinskid0f492d2017-04-03 18:12:45 -070062class OptimizeContext : public IAaptContext {
63 public:
Adam Lesinskib522f042017-04-21 16:57:59 -070064 OptimizeContext() = default;
65
66 PackageType GetPackageType() override {
67 // Not important here. Using anything other than kApp adds EXTRA validation, which we want to
68 // avoid.
69 return PackageType::kApp;
70 }
71
Adam Lesinskid0f492d2017-04-03 18:12:45 -070072 IDiagnostics* GetDiagnostics() override {
73 return &diagnostics_;
74 }
75
76 NameMangler* GetNameMangler() override {
77 UNIMPLEMENTED(FATAL);
78 return nullptr;
79 }
80
81 const std::string& GetCompilationPackage() override {
82 static std::string empty;
83 return empty;
84 }
85
86 uint8_t GetPackageId() override {
87 return 0;
88 }
89
90 SymbolTable* GetExternalSymbols() override {
91 UNIMPLEMENTED(FATAL);
92 return nullptr;
93 }
94
95 bool IsVerbose() override {
96 return verbose_;
97 }
98
99 void SetVerbose(bool val) {
100 verbose_ = val;
101 }
102
103 void SetMinSdkVersion(int sdk_version) {
104 sdk_version_ = sdk_version;
105 }
106
107 int GetMinSdkVersion() override {
108 return sdk_version_;
109 }
110
111 private:
Adam Lesinskib522f042017-04-21 16:57:59 -0700112 DISALLOW_COPY_AND_ASSIGN(OptimizeContext);
113
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700114 StdErrDiagnostics diagnostics_;
115 bool verbose_ = false;
116 int sdk_version_ = 0;
117};
118
Ryan Mitchell833a1a62018-07-10 13:51:36 -0700119class Optimizer {
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700120 public:
Ryan Mitchell833a1a62018-07-10 13:51:36 -0700121 Optimizer(OptimizeContext* context, const OptimizeOptions& options)
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700122 : options_(options), context_(context) {
123 }
124
125 int Run(std::unique_ptr<LoadedApk> apk) {
126 if (context_->IsVerbose()) {
127 context_->GetDiagnostics()->Note(DiagMessage() << "Optimizing APK...");
128 }
Mohamed Heikald3c5fb62018-01-12 11:37:26 -0500129 if (!options_.resources_blacklist.empty()) {
130 ResourceFilter filter(options_.resources_blacklist);
131 if (!filter.Consume(context_, apk->GetResourceTable())) {
132 context_->GetDiagnostics()->Error(DiagMessage() << "failed filtering resources");
133 return 1;
134 }
135 }
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700136
137 VersionCollapser collapser;
138 if (!collapser.Consume(context_, apk->GetResourceTable())) {
139 return 1;
140 }
141
142 ResourceDeduper deduper;
143 if (!deduper.Consume(context_, apk->GetResourceTable())) {
144 context_->GetDiagnostics()->Error(DiagMessage() << "failed deduping resources");
145 return 1;
146 }
147
Mohamed Heikalc7694032018-11-07 16:49:02 -0500148 if (options_.shorten_resource_paths) {
149 ResourcePathShortener shortener(options_.table_flattener_options.shortened_path_map);
150 if (!shortener.Consume(context_, apk->GetResourceTable())) {
151 context_->GetDiagnostics()->Error(DiagMessage() << "failed shortening resource paths");
152 return 1;
153 }
154 if (options_.shortened_paths_map_path
155 && !WriteShortenedPathsMap(options_.table_flattener_options.shortened_path_map,
156 options_.shortened_paths_map_path.value())) {
157 context_->GetDiagnostics()->Error(DiagMessage()
158 << "failed to write shortened resource paths to file");
159 return 1;
160 }
161 }
162
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700163 // Adjust the SplitConstraints so that their SDK version is stripped if it is less than or
164 // equal to the minSdk.
165 options_.split_constraints =
166 AdjustSplitConstraintsForMinSdk(context_->GetMinSdkVersion(), options_.split_constraints);
167
168 // Stripping the APK using the TableSplitter. The resource table is modified in place in the
169 // LoadedApk.
170 TableSplitter splitter(options_.split_constraints, options_.table_splitter_options);
171 if (!splitter.VerifySplitConstraints(context_)) {
172 return 1;
173 }
174 splitter.SplitTable(apk->GetResourceTable());
175
176 auto path_iter = options_.split_paths.begin();
177 auto split_constraints_iter = options_.split_constraints.begin();
178 for (std::unique_ptr<ResourceTable>& split_table : splitter.splits()) {
179 if (context_->IsVerbose()) {
180 context_->GetDiagnostics()->Note(
181 DiagMessage(*path_iter) << "generating split with configurations '"
182 << util::Joiner(split_constraints_iter->configs, ", ") << "'");
183 }
184
185 // Generate an AndroidManifest.xml for each split.
186 std::unique_ptr<xml::XmlResource> split_manifest =
187 GenerateSplitManifest(options_.app_info, *split_constraints_iter);
188 std::unique_ptr<IArchiveWriter> split_writer =
189 CreateZipFileArchiveWriter(context_->GetDiagnostics(), *path_iter);
190 if (!split_writer) {
191 return 1;
192 }
193
194 if (!WriteSplitApk(split_table.get(), split_manifest.get(), split_writer.get())) {
195 return 1;
196 }
197
198 ++path_iter;
199 ++split_constraints_iter;
200 }
201
Shane Farmercb6c3f92017-11-27 13:19:36 -0800202 if (options_.apk_artifacts && options_.output_dir) {
Shane Farmer0a5b2012017-06-22 12:24:12 -0700203 MultiApkGenerator generator{apk.get(), context_};
Shane Farmer666de342017-11-29 16:07:51 -0800204 MultiApkGeneratorOptions generator_options = {
Shane Farmercb6c3f92017-11-27 13:19:36 -0800205 options_.output_dir.value(), options_.apk_artifacts.value(),
206 options_.table_flattener_options, options_.kept_artifacts};
Shane Farmerefe45392017-08-21 14:39:28 -0700207 if (!generator.FromBaseApk(generator_options)) {
Shane Farmer0a5b2012017-06-22 12:24:12 -0700208 return 1;
Shane Farmer57669432017-06-19 12:52:04 -0700209 }
210 }
211
212 if (options_.output_path) {
213 std::unique_ptr<IArchiveWriter> writer =
214 CreateZipFileArchiveWriter(context_->GetDiagnostics(), options_.output_path.value());
215 if (!apk->WriteToArchive(context_, options_.table_flattener_options, writer.get())) {
216 return 1;
217 }
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700218 }
219
220 return 0;
221 }
222
223 private:
224 bool WriteSplitApk(ResourceTable* table, xml::XmlResource* manifest, IArchiveWriter* writer) {
225 BigBuffer manifest_buffer(4096);
226 XmlFlattener xml_flattener(&manifest_buffer, {});
227 if (!xml_flattener.Consume(context_, manifest)) {
228 return false;
229 }
230
231 io::BigBufferInputStream manifest_buffer_in(&manifest_buffer);
232 if (!io::CopyInputStreamToArchive(context_, &manifest_buffer_in, "AndroidManifest.xml",
233 ArchiveEntry::kCompress, writer)) {
234 return false;
235 }
236
237 std::map<std::pair<ConfigDescription, StringPiece>, FileReference*> config_sorted_files;
238 for (auto& pkg : table->packages) {
239 for (auto& type : pkg->types) {
240 // Sort by config and name, so that we get better locality in the zip file.
241 config_sorted_files.clear();
242
243 for (auto& entry : type->entries) {
244 for (auto& config_value : entry->values) {
Shane Farmer0a5b2012017-06-22 12:24:12 -0700245 auto* file_ref = ValueCast<FileReference>(config_value->value.get());
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700246 if (file_ref == nullptr) {
247 continue;
248 }
249
250 if (file_ref->file == nullptr) {
251 ResourceNameRef name(pkg->name, type->type, entry->name);
Adam Lesinski742888f2017-04-28 15:34:52 -0700252 context_->GetDiagnostics()->Warn(DiagMessage(file_ref->GetSource())
Shane Farmer57669432017-06-19 12:52:04 -0700253 << "file for resource " << name << " with config '"
254 << config_value->config << "' not found");
Adam Lesinski742888f2017-04-28 15:34:52 -0700255 continue;
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700256 }
257
258 const StringPiece entry_name = entry->name;
259 config_sorted_files[std::make_pair(config_value->config, entry_name)] = file_ref;
260 }
261 }
262
263 for (auto& entry : config_sorted_files) {
264 FileReference* file_ref = entry.second;
Pierre Lecesned55bef72017-11-10 22:31:01 +0000265 if (!io::CopyFileToArchivePreserveCompression(context_, file_ref->file, *file_ref->path,
266 writer)) {
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700267 return false;
268 }
269 }
270 }
271 }
272
273 BigBuffer table_buffer(4096);
274 TableFlattener table_flattener(options_.table_flattener_options, &table_buffer);
275 if (!table_flattener.Consume(context_, table)) {
276 return false;
277 }
278
279 io::BigBufferInputStream table_buffer_in(&table_buffer);
Shane Farmer0a5b2012017-06-22 12:24:12 -0700280 return io::CopyInputStreamToArchive(context_, &table_buffer_in, "resources.arsc",
281 ArchiveEntry::kAlign, writer);
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700282 }
283
Mohamed Heikalc7694032018-11-07 16:49:02 -0500284 bool WriteShortenedPathsMap(const std::map<std::string, std::string> &path_map,
285 const std::string &file_path) {
286 std::stringstream ss;
287 for (auto it = path_map.cbegin(); it != path_map.cend(); ++it) {
288 ss << it->first << " -> " << it->second << "\n";
289 }
290 return WriteStringToFile(ss.str(), file_path);
291 }
292
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700293 OptimizeOptions options_;
294 OptimizeContext* context_;
295};
296
Mohamed Heikald3c5fb62018-01-12 11:37:26 -0500297bool ExtractObfuscationWhitelistFromConfig(const std::string& path, OptimizeContext* context,
298 OptimizeOptions* options) {
Luke Nicholsonb0643302017-12-01 15:29:03 -0800299 std::string contents;
300 if (!ReadFileToString(path, &contents, true)) {
301 context->GetDiagnostics()->Error(DiagMessage()
302 << "failed to parse whitelist from config file: " << path);
303 return false;
304 }
Mohamed Heikald3c5fb62018-01-12 11:37:26 -0500305 for (StringPiece resource_name : util::Tokenize(contents, ',')) {
306 options->table_flattener_options.whitelisted_resources.insert(
307 resource_name.to_string());
308 }
309 return true;
310}
311
312bool ExtractConfig(const std::string& path, OptimizeContext* context,
313 OptimizeOptions* options) {
314 std::string content;
315 if (!android::base::ReadFileToString(path, &content, true /*follow_symlinks*/)) {
316 context->GetDiagnostics()->Error(DiagMessage(path) << "failed reading whitelist");
317 return false;
318 }
319
320 size_t line_no = 0;
321 for (StringPiece line : util::Tokenize(content, '\n')) {
322 line_no++;
323 line = util::TrimWhitespace(line);
324 if (line.empty()) {
325 continue;
326 }
327
328 auto split_line = util::Split(line, '#');
329 if (split_line.size() < 2) {
330 context->GetDiagnostics()->Error(DiagMessage(line) << "No # found in line");
331 return false;
332 }
333 StringPiece resource_string = split_line[0];
334 StringPiece directives = split_line[1];
335 ResourceNameRef resource_name;
336 if (!ResourceUtils::ParseResourceName(resource_string, &resource_name)) {
337 context->GetDiagnostics()->Error(DiagMessage(line) << "Malformed resource name");
338 return false;
339 }
340 if (!resource_name.package.empty()) {
341 context->GetDiagnostics()->Error(DiagMessage(line)
342 << "Package set for resource. Only use type/name");
343 return false;
344 }
345 for (StringPiece directive : util::Tokenize(directives, ',')) {
346 if (directive == "remove") {
347 options->resources_blacklist.insert(resource_name.ToResourceName());
348 } else if (directive == "no_obfuscate") {
349 options->table_flattener_options.whitelisted_resources.insert(
350 resource_name.entry.to_string());
351 }
352 }
Luke Nicholsonb0643302017-12-01 15:29:03 -0800353 }
354 return true;
355}
356
Adam Lesinski8780eb62017-10-31 17:44:39 -0700357bool ExtractAppDataFromManifest(OptimizeContext* context, const LoadedApk* apk,
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700358 OptimizeOptions* out_options) {
Adam Lesinski8780eb62017-10-31 17:44:39 -0700359 const xml::XmlResource* manifest = apk->GetManifest();
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700360 if (manifest == nullptr) {
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700361 return false;
362 }
363
Adam Lesinski8780eb62017-10-31 17:44:39 -0700364 Maybe<AppInfo> app_info = ExtractAppInfoFromBinaryManifest(*manifest, context->GetDiagnostics());
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700365 if (!app_info) {
366 context->GetDiagnostics()->Error(DiagMessage()
367 << "failed to extract data from AndroidManifest.xml");
368 return false;
369 }
370
371 out_options->app_info = std::move(app_info.value());
372 context->SetMinSdkVersion(out_options->app_info.min_sdk_version.value_or_default(0));
373 return true;
374}
375
Ryan Mitchell833a1a62018-07-10 13:51:36 -0700376int OptimizeCommand::Action(const std::vector<std::string>& args) {
377 if (args.size() != 1u) {
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700378 std::cerr << "must have one APK as argument.\n\n";
Ryan Mitchell833a1a62018-07-10 13:51:36 -0700379 Usage(&std::cerr);
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700380 return 1;
381 }
382
Ryan Mitchell833a1a62018-07-10 13:51:36 -0700383 const std::string& apk_path = args[0];
384 OptimizeContext context;
385 context.SetVerbose(verbose_);
Shane Farmer9ecc0752017-08-24 15:55:36 -0700386 IDiagnostics* diag = context.GetDiagnostics();
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700387
Ryan Mitchell833a1a62018-07-10 13:51:36 -0700388 if (config_path_) {
389 std::string& path = config_path_.value();
Shane Farmer57669432017-06-19 12:52:04 -0700390 Maybe<ConfigurationParser> for_path = ConfigurationParser::ForPath(path);
391 if (for_path) {
Ryan Mitchell833a1a62018-07-10 13:51:36 -0700392 options_.apk_artifacts = for_path.value().WithDiagnostics(diag).Parse(apk_path);
393 if (!options_.apk_artifacts) {
Shane Farmercb6c3f92017-11-27 13:19:36 -0800394 diag->Error(DiagMessage() << "Failed to parse the output artifact list");
395 return 1;
396 }
397
Shane Farmer57669432017-06-19 12:52:04 -0700398 } else {
Shane Farmer9ecc0752017-08-24 15:55:36 -0700399 diag->Error(DiagMessage() << "Could not parse config file " << path);
Shane Farmer57669432017-06-19 12:52:04 -0700400 return 1;
401 }
Shane Farmer9ecc0752017-08-24 15:55:36 -0700402
Ryan Mitchell833a1a62018-07-10 13:51:36 -0700403 if (print_only_) {
404 for (const OutputArtifact& artifact : options_.apk_artifacts.value()) {
Shane Farmercb6c3f92017-11-27 13:19:36 -0800405 std::cout << artifact.name << std::endl;
Shane Farmer9ecc0752017-08-24 15:55:36 -0700406 }
407 return 0;
408 }
409
Ryan Mitchell833a1a62018-07-10 13:51:36 -0700410 if (!kept_artifacts_.empty()) {
411 for (const std::string& artifact_str : kept_artifacts_) {
Shane Farmercb6c3f92017-11-27 13:19:36 -0800412 for (const StringPiece& artifact : util::Tokenize(artifact_str, ',')) {
Ryan Mitchell833a1a62018-07-10 13:51:36 -0700413 options_.kept_artifacts.insert(artifact.to_string());
Shane Farmer666de342017-11-29 16:07:51 -0800414 }
415 }
416 }
417
Shane Farmer9ecc0752017-08-24 15:55:36 -0700418 // Since we know that we are going to process the APK (not just print targets), make sure we
419 // have somewhere to write them to.
Ryan Mitchell833a1a62018-07-10 13:51:36 -0700420 if (!options_.output_dir) {
Shane Farmer9ecc0752017-08-24 15:55:36 -0700421 diag->Error(DiagMessage() << "Output directory is required when using a configuration file");
422 return 1;
423 }
Ryan Mitchell833a1a62018-07-10 13:51:36 -0700424 } else if (print_only_) {
Shane Farmer9ecc0752017-08-24 15:55:36 -0700425 diag->Error(DiagMessage() << "Asked to print artifacts without providing a configurations");
426 return 1;
Shane Farmer57669432017-06-19 12:52:04 -0700427 }
428
Shane Farmer2c122412017-12-15 16:55:54 -0800429 std::unique_ptr<LoadedApk> apk = LoadedApk::LoadApkFromPath(apk_path, context.GetDiagnostics());
430 if (!apk) {
431 return 1;
432 }
433
Ryan Mitchell833a1a62018-07-10 13:51:36 -0700434 if (target_densities_) {
Shane Farmer2c122412017-12-15 16:55:54 -0800435 // Parse the target screen densities.
Ryan Mitchell833a1a62018-07-10 13:51:36 -0700436 for (const StringPiece& config_str : util::Tokenize(target_densities_.value(), ',')) {
Shane Farmer2c122412017-12-15 16:55:54 -0800437 Maybe<uint16_t> target_density = ParseTargetDensityParameter(config_str, diag);
438 if (!target_density) {
439 return 1;
440 }
Ryan Mitchell833a1a62018-07-10 13:51:36 -0700441 options_.table_splitter_options.preferred_densities.push_back(target_density.value());
Shane Farmer2c122412017-12-15 16:55:54 -0800442 }
443 }
444
445 std::unique_ptr<IConfigFilter> filter;
Ryan Mitchell833a1a62018-07-10 13:51:36 -0700446 if (!configs_.empty()) {
447 filter = ParseConfigFilterParameters(configs_, diag);
Shane Farmer2c122412017-12-15 16:55:54 -0800448 if (filter == nullptr) {
449 return 1;
450 }
Ryan Mitchell833a1a62018-07-10 13:51:36 -0700451 options_.table_splitter_options.config_filter = filter.get();
Shane Farmer2c122412017-12-15 16:55:54 -0800452 }
453
454 // Parse the split parameters.
Ryan Mitchell833a1a62018-07-10 13:51:36 -0700455 for (const std::string& split_arg : split_args_) {
456 options_.split_paths.emplace_back();
457 options_.split_constraints.emplace_back();
458 if (!ParseSplitParameter(split_arg, diag, &options_.split_paths.back(),
459 &options_.split_constraints.back())) {
Shane Farmer2c122412017-12-15 16:55:54 -0800460 return 1;
461 }
462 }
463
Ryan Mitchell833a1a62018-07-10 13:51:36 -0700464 if (options_.table_flattener_options.collapse_key_stringpool) {
465 if (whitelist_path_) {
466 std::string& path = whitelist_path_.value();
467 if (!ExtractObfuscationWhitelistFromConfig(path, &context, &options_)) {
Luke Nicholsonb0643302017-12-01 15:29:03 -0800468 return 1;
469 }
470 }
471 }
472
Ryan Mitchell833a1a62018-07-10 13:51:36 -0700473 if (resources_config_path_) {
474 std::string& path = resources_config_path_.value();
475 if (!ExtractConfig(path, &context, &options_)) {
Mohamed Heikald3c5fb62018-01-12 11:37:26 -0500476 return 1;
477 }
478 }
479
Ryan Mitchell833a1a62018-07-10 13:51:36 -0700480 if (!ExtractAppDataFromManifest(&context, apk.get(), &options_)) {
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700481 return 1;
482 }
483
Ryan Mitchell833a1a62018-07-10 13:51:36 -0700484 Optimizer cmd(&context, options_);
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700485 return cmd.Run(std::move(apk));
486}
487
488} // namespace aapt