blob: 5e06818d7a131bd7c0167ecb51e5532453675568 [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
Udam Sainib228df32019-06-18 16:50:34 -0700111 const std::set<std::string>& GetSplitNameDependencies() override {
112 UNIMPLEMENTED(FATAL) << "Split Name Dependencies should not be necessary";
113 static std::set<std::string> empty;
114 return empty;
115 }
116
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700117 private:
Adam Lesinskib522f042017-04-21 16:57:59 -0700118 DISALLOW_COPY_AND_ASSIGN(OptimizeContext);
119
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700120 StdErrDiagnostics diagnostics_;
121 bool verbose_ = false;
122 int sdk_version_ = 0;
123};
124
Ryan Mitchell833a1a62018-07-10 13:51:36 -0700125class Optimizer {
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700126 public:
Ryan Mitchell833a1a62018-07-10 13:51:36 -0700127 Optimizer(OptimizeContext* context, const OptimizeOptions& options)
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700128 : options_(options), context_(context) {
129 }
130
131 int Run(std::unique_ptr<LoadedApk> apk) {
132 if (context_->IsVerbose()) {
133 context_->GetDiagnostics()->Note(DiagMessage() << "Optimizing APK...");
134 }
Mohamed Heikald3c5fb62018-01-12 11:37:26 -0500135 if (!options_.resources_blacklist.empty()) {
136 ResourceFilter filter(options_.resources_blacklist);
137 if (!filter.Consume(context_, apk->GetResourceTable())) {
138 context_->GetDiagnostics()->Error(DiagMessage() << "failed filtering resources");
139 return 1;
140 }
141 }
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700142
143 VersionCollapser collapser;
144 if (!collapser.Consume(context_, apk->GetResourceTable())) {
145 return 1;
146 }
147
148 ResourceDeduper deduper;
149 if (!deduper.Consume(context_, apk->GetResourceTable())) {
150 context_->GetDiagnostics()->Error(DiagMessage() << "failed deduping resources");
151 return 1;
152 }
153
Mohamed Heikalc7694032018-11-07 16:49:02 -0500154 if (options_.shorten_resource_paths) {
155 ResourcePathShortener shortener(options_.table_flattener_options.shortened_path_map);
156 if (!shortener.Consume(context_, apk->GetResourceTable())) {
157 context_->GetDiagnostics()->Error(DiagMessage() << "failed shortening resource paths");
158 return 1;
159 }
160 if (options_.shortened_paths_map_path
161 && !WriteShortenedPathsMap(options_.table_flattener_options.shortened_path_map,
162 options_.shortened_paths_map_path.value())) {
163 context_->GetDiagnostics()->Error(DiagMessage()
164 << "failed to write shortened resource paths to file");
165 return 1;
166 }
167 }
168
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700169 // Adjust the SplitConstraints so that their SDK version is stripped if it is less than or
170 // equal to the minSdk.
171 options_.split_constraints =
172 AdjustSplitConstraintsForMinSdk(context_->GetMinSdkVersion(), options_.split_constraints);
173
174 // Stripping the APK using the TableSplitter. The resource table is modified in place in the
175 // LoadedApk.
176 TableSplitter splitter(options_.split_constraints, options_.table_splitter_options);
177 if (!splitter.VerifySplitConstraints(context_)) {
178 return 1;
179 }
180 splitter.SplitTable(apk->GetResourceTable());
181
182 auto path_iter = options_.split_paths.begin();
183 auto split_constraints_iter = options_.split_constraints.begin();
184 for (std::unique_ptr<ResourceTable>& split_table : splitter.splits()) {
185 if (context_->IsVerbose()) {
186 context_->GetDiagnostics()->Note(
187 DiagMessage(*path_iter) << "generating split with configurations '"
188 << util::Joiner(split_constraints_iter->configs, ", ") << "'");
189 }
190
191 // Generate an AndroidManifest.xml for each split.
192 std::unique_ptr<xml::XmlResource> split_manifest =
193 GenerateSplitManifest(options_.app_info, *split_constraints_iter);
194 std::unique_ptr<IArchiveWriter> split_writer =
195 CreateZipFileArchiveWriter(context_->GetDiagnostics(), *path_iter);
196 if (!split_writer) {
197 return 1;
198 }
199
200 if (!WriteSplitApk(split_table.get(), split_manifest.get(), split_writer.get())) {
201 return 1;
202 }
203
204 ++path_iter;
205 ++split_constraints_iter;
206 }
207
Shane Farmercb6c3f92017-11-27 13:19:36 -0800208 if (options_.apk_artifacts && options_.output_dir) {
Shane Farmer0a5b2012017-06-22 12:24:12 -0700209 MultiApkGenerator generator{apk.get(), context_};
Shane Farmer666de342017-11-29 16:07:51 -0800210 MultiApkGeneratorOptions generator_options = {
Shane Farmercb6c3f92017-11-27 13:19:36 -0800211 options_.output_dir.value(), options_.apk_artifacts.value(),
212 options_.table_flattener_options, options_.kept_artifacts};
Shane Farmerefe45392017-08-21 14:39:28 -0700213 if (!generator.FromBaseApk(generator_options)) {
Shane Farmer0a5b2012017-06-22 12:24:12 -0700214 return 1;
Shane Farmer57669432017-06-19 12:52:04 -0700215 }
216 }
217
218 if (options_.output_path) {
219 std::unique_ptr<IArchiveWriter> writer =
220 CreateZipFileArchiveWriter(context_->GetDiagnostics(), options_.output_path.value());
221 if (!apk->WriteToArchive(context_, options_.table_flattener_options, writer.get())) {
222 return 1;
223 }
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700224 }
225
226 return 0;
227 }
228
229 private:
230 bool WriteSplitApk(ResourceTable* table, xml::XmlResource* manifest, IArchiveWriter* writer) {
231 BigBuffer manifest_buffer(4096);
232 XmlFlattener xml_flattener(&manifest_buffer, {});
233 if (!xml_flattener.Consume(context_, manifest)) {
234 return false;
235 }
236
237 io::BigBufferInputStream manifest_buffer_in(&manifest_buffer);
238 if (!io::CopyInputStreamToArchive(context_, &manifest_buffer_in, "AndroidManifest.xml",
239 ArchiveEntry::kCompress, writer)) {
240 return false;
241 }
242
243 std::map<std::pair<ConfigDescription, StringPiece>, FileReference*> config_sorted_files;
244 for (auto& pkg : table->packages) {
245 for (auto& type : pkg->types) {
246 // Sort by config and name, so that we get better locality in the zip file.
247 config_sorted_files.clear();
248
249 for (auto& entry : type->entries) {
250 for (auto& config_value : entry->values) {
Shane Farmer0a5b2012017-06-22 12:24:12 -0700251 auto* file_ref = ValueCast<FileReference>(config_value->value.get());
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700252 if (file_ref == nullptr) {
253 continue;
254 }
255
256 if (file_ref->file == nullptr) {
257 ResourceNameRef name(pkg->name, type->type, entry->name);
Adam Lesinski742888f2017-04-28 15:34:52 -0700258 context_->GetDiagnostics()->Warn(DiagMessage(file_ref->GetSource())
Shane Farmer57669432017-06-19 12:52:04 -0700259 << "file for resource " << name << " with config '"
260 << config_value->config << "' not found");
Adam Lesinski742888f2017-04-28 15:34:52 -0700261 continue;
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700262 }
263
264 const StringPiece entry_name = entry->name;
265 config_sorted_files[std::make_pair(config_value->config, entry_name)] = file_ref;
266 }
267 }
268
269 for (auto& entry : config_sorted_files) {
270 FileReference* file_ref = entry.second;
Pierre Lecesned55bef72017-11-10 22:31:01 +0000271 if (!io::CopyFileToArchivePreserveCompression(context_, file_ref->file, *file_ref->path,
272 writer)) {
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700273 return false;
274 }
275 }
276 }
277 }
278
279 BigBuffer table_buffer(4096);
280 TableFlattener table_flattener(options_.table_flattener_options, &table_buffer);
281 if (!table_flattener.Consume(context_, table)) {
282 return false;
283 }
284
285 io::BigBufferInputStream table_buffer_in(&table_buffer);
Shane Farmer0a5b2012017-06-22 12:24:12 -0700286 return io::CopyInputStreamToArchive(context_, &table_buffer_in, "resources.arsc",
287 ArchiveEntry::kAlign, writer);
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700288 }
289
Mohamed Heikalc7694032018-11-07 16:49:02 -0500290 bool WriteShortenedPathsMap(const std::map<std::string, std::string> &path_map,
291 const std::string &file_path) {
292 std::stringstream ss;
293 for (auto it = path_map.cbegin(); it != path_map.cend(); ++it) {
294 ss << it->first << " -> " << it->second << "\n";
295 }
296 return WriteStringToFile(ss.str(), file_path);
297 }
298
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700299 OptimizeOptions options_;
300 OptimizeContext* context_;
301};
302
Mohamed Heikald3c5fb62018-01-12 11:37:26 -0500303bool ExtractObfuscationWhitelistFromConfig(const std::string& path, OptimizeContext* context,
304 OptimizeOptions* options) {
Luke Nicholsonb0643302017-12-01 15:29:03 -0800305 std::string contents;
306 if (!ReadFileToString(path, &contents, true)) {
307 context->GetDiagnostics()->Error(DiagMessage()
308 << "failed to parse whitelist from config file: " << path);
309 return false;
310 }
Mohamed Heikald3c5fb62018-01-12 11:37:26 -0500311 for (StringPiece resource_name : util::Tokenize(contents, ',')) {
312 options->table_flattener_options.whitelisted_resources.insert(
313 resource_name.to_string());
314 }
315 return true;
316}
317
318bool ExtractConfig(const std::string& path, OptimizeContext* context,
319 OptimizeOptions* options) {
320 std::string content;
321 if (!android::base::ReadFileToString(path, &content, true /*follow_symlinks*/)) {
322 context->GetDiagnostics()->Error(DiagMessage(path) << "failed reading whitelist");
323 return false;
324 }
325
326 size_t line_no = 0;
327 for (StringPiece line : util::Tokenize(content, '\n')) {
328 line_no++;
329 line = util::TrimWhitespace(line);
330 if (line.empty()) {
331 continue;
332 }
333
334 auto split_line = util::Split(line, '#');
335 if (split_line.size() < 2) {
336 context->GetDiagnostics()->Error(DiagMessage(line) << "No # found in line");
337 return false;
338 }
339 StringPiece resource_string = split_line[0];
340 StringPiece directives = split_line[1];
341 ResourceNameRef resource_name;
342 if (!ResourceUtils::ParseResourceName(resource_string, &resource_name)) {
343 context->GetDiagnostics()->Error(DiagMessage(line) << "Malformed resource name");
344 return false;
345 }
346 if (!resource_name.package.empty()) {
347 context->GetDiagnostics()->Error(DiagMessage(line)
348 << "Package set for resource. Only use type/name");
349 return false;
350 }
351 for (StringPiece directive : util::Tokenize(directives, ',')) {
352 if (directive == "remove") {
353 options->resources_blacklist.insert(resource_name.ToResourceName());
354 } else if (directive == "no_obfuscate") {
355 options->table_flattener_options.whitelisted_resources.insert(
356 resource_name.entry.to_string());
357 }
358 }
Luke Nicholsonb0643302017-12-01 15:29:03 -0800359 }
360 return true;
361}
362
Adam Lesinski8780eb62017-10-31 17:44:39 -0700363bool ExtractAppDataFromManifest(OptimizeContext* context, const LoadedApk* apk,
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700364 OptimizeOptions* out_options) {
Adam Lesinski8780eb62017-10-31 17:44:39 -0700365 const xml::XmlResource* manifest = apk->GetManifest();
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700366 if (manifest == nullptr) {
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700367 return false;
368 }
369
Adam Lesinski8780eb62017-10-31 17:44:39 -0700370 Maybe<AppInfo> app_info = ExtractAppInfoFromBinaryManifest(*manifest, context->GetDiagnostics());
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700371 if (!app_info) {
372 context->GetDiagnostics()->Error(DiagMessage()
373 << "failed to extract data from AndroidManifest.xml");
374 return false;
375 }
376
377 out_options->app_info = std::move(app_info.value());
378 context->SetMinSdkVersion(out_options->app_info.min_sdk_version.value_or_default(0));
379 return true;
380}
381
Ryan Mitchell833a1a62018-07-10 13:51:36 -0700382int OptimizeCommand::Action(const std::vector<std::string>& args) {
383 if (args.size() != 1u) {
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700384 std::cerr << "must have one APK as argument.\n\n";
Ryan Mitchell833a1a62018-07-10 13:51:36 -0700385 Usage(&std::cerr);
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700386 return 1;
387 }
388
Ryan Mitchell833a1a62018-07-10 13:51:36 -0700389 const std::string& apk_path = args[0];
390 OptimizeContext context;
391 context.SetVerbose(verbose_);
Shane Farmer9ecc0752017-08-24 15:55:36 -0700392 IDiagnostics* diag = context.GetDiagnostics();
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700393
Ryan Mitchell833a1a62018-07-10 13:51:36 -0700394 if (config_path_) {
395 std::string& path = config_path_.value();
Shane Farmer57669432017-06-19 12:52:04 -0700396 Maybe<ConfigurationParser> for_path = ConfigurationParser::ForPath(path);
397 if (for_path) {
Ryan Mitchell833a1a62018-07-10 13:51:36 -0700398 options_.apk_artifacts = for_path.value().WithDiagnostics(diag).Parse(apk_path);
399 if (!options_.apk_artifacts) {
Shane Farmercb6c3f92017-11-27 13:19:36 -0800400 diag->Error(DiagMessage() << "Failed to parse the output artifact list");
401 return 1;
402 }
403
Shane Farmer57669432017-06-19 12:52:04 -0700404 } else {
Shane Farmer9ecc0752017-08-24 15:55:36 -0700405 diag->Error(DiagMessage() << "Could not parse config file " << path);
Shane Farmer57669432017-06-19 12:52:04 -0700406 return 1;
407 }
Shane Farmer9ecc0752017-08-24 15:55:36 -0700408
Ryan Mitchell833a1a62018-07-10 13:51:36 -0700409 if (print_only_) {
410 for (const OutputArtifact& artifact : options_.apk_artifacts.value()) {
Shane Farmercb6c3f92017-11-27 13:19:36 -0800411 std::cout << artifact.name << std::endl;
Shane Farmer9ecc0752017-08-24 15:55:36 -0700412 }
413 return 0;
414 }
415
Ryan Mitchell833a1a62018-07-10 13:51:36 -0700416 if (!kept_artifacts_.empty()) {
417 for (const std::string& artifact_str : kept_artifacts_) {
Shane Farmercb6c3f92017-11-27 13:19:36 -0800418 for (const StringPiece& artifact : util::Tokenize(artifact_str, ',')) {
Ryan Mitchell833a1a62018-07-10 13:51:36 -0700419 options_.kept_artifacts.insert(artifact.to_string());
Shane Farmer666de342017-11-29 16:07:51 -0800420 }
421 }
422 }
423
Shane Farmer9ecc0752017-08-24 15:55:36 -0700424 // Since we know that we are going to process the APK (not just print targets), make sure we
425 // have somewhere to write them to.
Ryan Mitchell833a1a62018-07-10 13:51:36 -0700426 if (!options_.output_dir) {
Shane Farmer9ecc0752017-08-24 15:55:36 -0700427 diag->Error(DiagMessage() << "Output directory is required when using a configuration file");
428 return 1;
429 }
Ryan Mitchell833a1a62018-07-10 13:51:36 -0700430 } else if (print_only_) {
Shane Farmer9ecc0752017-08-24 15:55:36 -0700431 diag->Error(DiagMessage() << "Asked to print artifacts without providing a configurations");
432 return 1;
Shane Farmer57669432017-06-19 12:52:04 -0700433 }
434
Shane Farmer2c122412017-12-15 16:55:54 -0800435 std::unique_ptr<LoadedApk> apk = LoadedApk::LoadApkFromPath(apk_path, context.GetDiagnostics());
436 if (!apk) {
437 return 1;
438 }
439
Ryan Mitchell833a1a62018-07-10 13:51:36 -0700440 if (target_densities_) {
Shane Farmer2c122412017-12-15 16:55:54 -0800441 // Parse the target screen densities.
Ryan Mitchell833a1a62018-07-10 13:51:36 -0700442 for (const StringPiece& config_str : util::Tokenize(target_densities_.value(), ',')) {
Shane Farmer2c122412017-12-15 16:55:54 -0800443 Maybe<uint16_t> target_density = ParseTargetDensityParameter(config_str, diag);
444 if (!target_density) {
445 return 1;
446 }
Ryan Mitchell833a1a62018-07-10 13:51:36 -0700447 options_.table_splitter_options.preferred_densities.push_back(target_density.value());
Shane Farmer2c122412017-12-15 16:55:54 -0800448 }
449 }
450
451 std::unique_ptr<IConfigFilter> filter;
Ryan Mitchell833a1a62018-07-10 13:51:36 -0700452 if (!configs_.empty()) {
453 filter = ParseConfigFilterParameters(configs_, diag);
Shane Farmer2c122412017-12-15 16:55:54 -0800454 if (filter == nullptr) {
455 return 1;
456 }
Ryan Mitchell833a1a62018-07-10 13:51:36 -0700457 options_.table_splitter_options.config_filter = filter.get();
Shane Farmer2c122412017-12-15 16:55:54 -0800458 }
459
460 // Parse the split parameters.
Ryan Mitchell833a1a62018-07-10 13:51:36 -0700461 for (const std::string& split_arg : split_args_) {
462 options_.split_paths.emplace_back();
463 options_.split_constraints.emplace_back();
464 if (!ParseSplitParameter(split_arg, diag, &options_.split_paths.back(),
465 &options_.split_constraints.back())) {
Shane Farmer2c122412017-12-15 16:55:54 -0800466 return 1;
467 }
468 }
469
Ryan Mitchell833a1a62018-07-10 13:51:36 -0700470 if (options_.table_flattener_options.collapse_key_stringpool) {
471 if (whitelist_path_) {
472 std::string& path = whitelist_path_.value();
473 if (!ExtractObfuscationWhitelistFromConfig(path, &context, &options_)) {
Luke Nicholsonb0643302017-12-01 15:29:03 -0800474 return 1;
475 }
476 }
477 }
478
Ryan Mitchell833a1a62018-07-10 13:51:36 -0700479 if (resources_config_path_) {
480 std::string& path = resources_config_path_.value();
481 if (!ExtractConfig(path, &context, &options_)) {
Mohamed Heikald3c5fb62018-01-12 11:37:26 -0500482 return 1;
483 }
484 }
485
Ryan Mitchell833a1a62018-07-10 13:51:36 -0700486 if (!ExtractAppDataFromManifest(&context, apk.get(), &options_)) {
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700487 return 1;
488 }
489
Ryan Mitchell833a1a62018-07-10 13:51:36 -0700490 Optimizer cmd(&context, options_);
Adam Lesinskid0f492d2017-04-03 18:12:45 -0700491 return cmd.Run(std::move(apk));
492}
493
494} // namespace aapt