blob: c424cc516b56ed2b6d72163fd77b4ecd3b03a9ec [file] [log] [blame]
Adam Lesinski282e1812014-01-23 18:17:42 -08001//
2// Copyright 2006 The Android Open Source Project
3//
4// Android Asset Packaging Tool main entry point.
5//
6#include "Main.h"
7#include "Bundle.h"
8
Elliott Hughes9ec96f92015-07-29 14:35:18 -07009#include <utils/Compat.h>
Adam Lesinski282e1812014-01-23 18:17:42 -080010#include <utils/Log.h>
11#include <utils/threads.h>
12#include <utils/List.h>
13#include <utils/Errors.h>
14
Adam Lesinski4bf58102014-11-03 11:21:19 -080015#include <cstdlib>
Adam Lesinski282e1812014-01-23 18:17:42 -080016#include <getopt.h>
Adam Lesinski4bf58102014-11-03 11:21:19 -080017#include <cassert>
Adam Lesinski282e1812014-01-23 18:17:42 -080018
19using namespace android;
20
21static const char* gProgName = "aapt";
22
23/*
24 * When running under Cygwin on Windows, this will convert slash-based
25 * paths into back-slash-based ones. Otherwise the ApptAssets file comparisons
26 * fail later as they use back-slash separators under Windows.
27 *
28 * This operates in-place on the path string.
29 */
30void convertPath(char *path) {
31 if (path != NULL && OS_PATH_SEPARATOR != '/') {
32 for (; *path; path++) {
33 if (*path == '/') {
34 *path = OS_PATH_SEPARATOR;
35 }
36 }
37 }
38}
39
40/*
41 * Print usage info.
42 */
43void usage(void)
44{
45 fprintf(stderr, "Android Asset Packaging Tool\n\n");
46 fprintf(stderr, "Usage:\n");
47 fprintf(stderr,
48 " %s l[ist] [-v] [-a] file.{zip,jar,apk}\n"
49 " List contents of Zip-compatible archive.\n\n", gProgName);
50 fprintf(stderr,
51 " %s d[ump] [--values] [--include-meta-data] WHAT file.{apk} [asset [asset ...]]\n"
52 " strings Print the contents of the resource table string pool in the APK.\n"
53 " badging Print the label and icon for the app declared in APK.\n"
54 " permissions Print the permissions from the APK.\n"
55 " resources Print the resource table from the APK.\n"
56 " configurations Print the configurations in the APK.\n"
57 " xmltree Print the compiled xmls in the given assets.\n"
58 " xmlstrings Print the strings of the given compiled xml assets.\n\n", gProgName);
59 fprintf(stderr,
60 " %s p[ackage] [-d][-f][-m][-u][-v][-x][-z][-M AndroidManifest.xml] \\\n"
61 " [-0 extension [-0 extension ...]] [-g tolerance] [-j jarfile] \\\n"
62 " [--debug-mode] [--min-sdk-version VAL] [--target-sdk-version VAL] \\\n"
63 " [--app-version VAL] [--app-version-name TEXT] [--custom-package VAL] \\\n"
64 " [--rename-manifest-package PACKAGE] \\\n"
65 " [--rename-instrumentation-target-package PACKAGE] \\\n"
66 " [--utf16] [--auto-add-overlay] \\\n"
67 " [--max-res-version VAL] \\\n"
68 " [-I base-package [-I base-package ...]] \\\n"
69 " [-A asset-source-dir] [-G class-list-file] [-P public-definitions-file] \\\n"
70 " [-S resource-sources [-S resource-sources ...]] \\\n"
71 " [-F apk-file] [-J R-file-dir] \\\n"
72 " [--product product1,product2,...] \\\n"
Johan Redestig6ab7a782015-01-07 09:24:39 +010073 " [-c CONFIGS] [--preferred-density DENSITY] \\\n"
Adam Lesinskifab50872014-04-16 14:40:42 -070074 " [--split CONFIGS [--split CONFIGS]] \\\n"
Adam Lesinski833f3cc2014-06-18 15:06:01 -070075 " [--feature-of package [--feature-after package]] \\\n"
Adam Lesinski282e1812014-01-23 18:17:42 -080076 " [raw-files-dir [raw-files-dir] ...] \\\n"
77 " [--output-text-symbols DIR]\n"
78 "\n"
79 " Package the android resources. It will read assets and resources that are\n"
80 " supplied with the -M -A -S or raw-files-dir arguments. The -J -P -F and -R\n"
81 " options control which files are output.\n\n"
82 , gProgName);
83 fprintf(stderr,
84 " %s r[emove] [-v] file.{zip,jar,apk} file1 [file2 ...]\n"
85 " Delete specified files from Zip-compatible archive.\n\n",
86 gProgName);
87 fprintf(stderr,
88 " %s a[dd] [-v] file.{zip,jar,apk} file1 [file2 ...]\n"
89 " Add specified files to Zip-compatible archive.\n\n", gProgName);
90 fprintf(stderr,
91 " %s c[runch] [-v] -S resource-sources ... -C output-folder ...\n"
92 " Do PNG preprocessing on one or several resource folders\n"
93 " and store the results in the output folder.\n\n", gProgName);
94 fprintf(stderr,
95 " %s s[ingleCrunch] [-v] -i input-file -o outputfile\n"
96 " Do PNG preprocessing on a single file.\n\n", gProgName);
97 fprintf(stderr,
98 " %s v[ersion]\n"
99 " Print program version.\n\n", gProgName);
100 fprintf(stderr,
101 " Modifiers:\n"
102 " -a print Android-specific data (resources, manifest) when listing\n"
103 " -c specify which configurations to include. The default is all\n"
104 " configurations. The value of the parameter should be a comma\n"
105 " separated list of configuration values. Locales should be specified\n"
106 " as either a language or language-region pair. Some examples:\n"
107 " en\n"
108 " port,en\n"
109 " port,land,en_US\n"
Adam Lesinski282e1812014-01-23 18:17:42 -0800110 " -d one or more device assets to include, separated by commas\n"
111 " -f force overwrite of existing files\n"
112 " -g specify a pixel tolerance to force images to grayscale, default 0\n"
113 " -j specify a jar or zip file containing classes to include\n"
114 " -k junk path of file(s) added\n"
115 " -m make package directories under location specified by -J\n"
Adam Lesinski282e1812014-01-23 18:17:42 -0800116 " -u update existing packages (add new, replace older, remove deleted files)\n"
117 " -v verbose output\n"
118 " -x create extending (non-application) resource IDs\n"
119 " -z require localization of resource attributes marked with\n"
120 " localization=\"suggested\"\n"
121 " -A additional directory in which to find raw asset files\n"
122 " -G A file to output proguard options into.\n"
123 " -F specify the apk file to output\n"
124 " -I add an existing package to base include set\n"
125 " -J specify where to output R.java resource constant definitions\n"
126 " -M specify full path to AndroidManifest.xml to include in zip\n"
127 " -P specify where to output public resource definitions\n"
128 " -S directory in which to find resources. Multiple directories will be scanned\n"
129 " and the first match found (left to right) will take precedence.\n"
130 " -0 specifies an additional extension for which such files will not\n"
131 " be stored compressed in the .apk. An empty string means to not\n"
132 " compress any files at all.\n"
133 " --debug-mode\n"
134 " inserts android:debuggable=\"true\" in to the application node of the\n"
135 " manifest, making the application debuggable even on production devices.\n"
136 " --include-meta-data\n"
137 " when used with \"dump badging\" also includes meta-data tags.\n"
Igor Viarheichyka191d042014-06-02 17:16:24 -0700138 " --pseudo-localize\n"
139 " generate resources for pseudo-locales (en-XA and ar-XB).\n"
Adam Lesinski282e1812014-01-23 18:17:42 -0800140 " --min-sdk-version\n"
141 " inserts android:minSdkVersion in to manifest. If the version is 7 or\n"
142 " higher, the default encoding for resources will be in UTF-8.\n"
143 " --target-sdk-version\n"
144 " inserts android:targetSdkVersion in to manifest.\n"
145 " --max-res-version\n"
146 " ignores versioned resource directories above the given value.\n"
147 " --values\n"
148 " when used with \"dump resources\" also includes resource values.\n"
149 " --version-code\n"
150 " inserts android:versionCode in to manifest.\n"
151 " --version-name\n"
152 " inserts android:versionName in to manifest.\n"
Jeff Davidsondf08d1c2014-02-25 12:28:08 -0800153 " --replace-version\n"
154 " If --version-code and/or --version-name are specified, these\n"
155 " values will replace any value already in the manifest. By\n"
156 " default, nothing is changed if the manifest already defines\n"
157 " these attributes.\n"
Adam Lesinski282e1812014-01-23 18:17:42 -0800158 " --custom-package\n"
159 " generates R.java into a different package.\n"
160 " --extra-packages\n"
161 " generate R.java for libraries. Separate libraries with ':'.\n"
162 " --generate-dependencies\n"
163 " generate dependency files in the same directories for R.java and resource package\n"
164 " --auto-add-overlay\n"
165 " Automatically add resources that are only in overlays.\n"
Adam Lesinskifab50872014-04-16 14:40:42 -0700166 " --preferred-density\n"
167 " Specifies a preference for a particular density. Resources that do not\n"
168 " match this density and have variants that are a closer match are removed.\n"
169 " --split\n"
170 " Builds a separate split APK for the configurations listed. This can\n"
171 " be loaded alongside the base APK at runtime.\n"
Adam Lesinski833f3cc2014-06-18 15:06:01 -0700172 " --feature-of\n"
173 " Builds a split APK that is a feature of the apk specified here. Resources\n"
174 " in the base APK can be referenced from the the feature APK.\n"
175 " --feature-after\n"
176 " An app can have multiple Feature Split APKs which must be totally ordered.\n"
177 " If --feature-of is specified, this flag specifies which Feature Split APK\n"
178 " comes before this one. The first Feature Split APK should not define\n"
179 " anything here.\n"
Adam Lesinski282e1812014-01-23 18:17:42 -0800180 " --rename-manifest-package\n"
181 " Rewrite the manifest so that its package name is the package name\n"
182 " given here. Relative class names (for example .Foo) will be\n"
183 " changed to absolute names with the old package so that the code\n"
184 " does not need to change.\n"
185 " --rename-instrumentation-target-package\n"
186 " Rewrite the manifest so that all of its instrumentation\n"
187 " components target the given package. Useful when used in\n"
188 " conjunction with --rename-manifest-package to fix tests against\n"
189 " a package that has been renamed.\n"
190 " --product\n"
191 " Specifies which variant to choose for strings that have\n"
192 " product variants\n"
193 " --utf16\n"
194 " changes default encoding for resources to UTF-16. Only useful when API\n"
195 " level is set to 7 or higher where the default encoding is UTF-8.\n"
196 " --non-constant-id\n"
197 " Make the resources ID non constant. This is required to make an R java class\n"
198 " that does not contain the final value but is used to make reusable compiled\n"
199 " libraries that need to access resources.\n"
Adam Lesinskide898ff2014-01-29 18:20:45 -0800200 " --shared-lib\n"
201 " Make a shared library resource package that can be loaded by an application\n"
202 " at runtime to access the libraries resources. Implies --non-constant-id.\n"
Tao Baia6d7e3f2015-09-01 18:49:54 -0700203 " --app-as-shared-lib\n"
204 " Make an app resource package that also can be loaded as shared library at runtime.\n"
205 " Implies --non-constant-id.\n"
Adam Lesinski282e1812014-01-23 18:17:42 -0800206 " --error-on-failed-insert\n"
207 " Forces aapt to return an error if it fails to insert values into the manifest\n"
208 " with --debug-mode, --min-sdk-version, --target-sdk-version --version-code\n"
209 " and --version-name.\n"
210 " Insertion typically fails if the manifest already defines the attribute.\n"
Ying Wangcd28bd32013-11-14 17:12:10 -0800211 " --error-on-missing-config-entry\n"
212 " Forces aapt to return an error if it fails to find an entry for a configuration.\n"
Adam Lesinski282e1812014-01-23 18:17:42 -0800213 " --output-text-symbols\n"
214 " Generates a text file containing the resource symbols of the R class in the\n"
215 " specified folder.\n"
216 " --ignore-assets\n"
217 " Assets to be ignored. Default pattern is:\n"
Adam Lesinski6e460562015-04-21 14:20:15 -0700218 " %s\n"
Adrian Roos58922482015-06-01 17:59:41 -0700219 " --skip-symbols-without-default-localization\n"
220 " Prevents symbols from being generated for strings that do not have a default\n"
221 " localization\n"
Adam Lesinski6e460562015-04-21 14:20:15 -0700222 " --no-version-vectors\n"
Adam Lesinski78713992015-12-07 14:02:15 -0800223 " Do not automatically generate versioned copies of vector XML resources.\n"
224 " --private-symbols\n"
225 " Java package name to use when generating R.java for private resources.\n",
Adam Lesinski282e1812014-01-23 18:17:42 -0800226 gDefaultIgnoreAssets);
227}
228
229/*
230 * Dispatch the command.
231 */
232int handleCommand(Bundle* bundle)
233{
234 //printf("--- command %d (verbose=%d force=%d):\n",
235 // bundle->getCommand(), bundle->getVerbose(), bundle->getForce());
236 //for (int i = 0; i < bundle->getFileSpecCount(); i++)
237 // printf(" %d: '%s'\n", i, bundle->getFileSpecEntry(i));
238
239 switch (bundle->getCommand()) {
240 case kCommandVersion: return doVersion(bundle);
241 case kCommandList: return doList(bundle);
242 case kCommandDump: return doDump(bundle);
243 case kCommandAdd: return doAdd(bundle);
244 case kCommandRemove: return doRemove(bundle);
245 case kCommandPackage: return doPackage(bundle);
246 case kCommandCrunch: return doCrunch(bundle);
247 case kCommandSingleCrunch: return doSingleCrunch(bundle);
Jerome Dochez6f1280c2014-09-26 10:21:21 -0700248 case kCommandDaemon: return runInDaemonMode(bundle);
Adam Lesinski282e1812014-01-23 18:17:42 -0800249 default:
250 fprintf(stderr, "%s: requested command not yet supported\n", gProgName);
251 return 1;
252 }
253}
254
255/*
256 * Parse args.
257 */
258int main(int argc, char* const argv[])
259{
260 char *prog = argv[0];
261 Bundle bundle;
262 bool wantUsage = false;
263 int result = 1; // pessimistically assume an error.
264 int tolerance = 0;
265
266 /* default to compression */
267 bundle.setCompressionMethod(ZipEntry::kCompressDeflated);
268
269 if (argc < 2) {
270 wantUsage = true;
271 goto bail;
272 }
273
274 if (argv[1][0] == 'v')
275 bundle.setCommand(kCommandVersion);
276 else if (argv[1][0] == 'd')
277 bundle.setCommand(kCommandDump);
278 else if (argv[1][0] == 'l')
279 bundle.setCommand(kCommandList);
280 else if (argv[1][0] == 'a')
281 bundle.setCommand(kCommandAdd);
282 else if (argv[1][0] == 'r')
283 bundle.setCommand(kCommandRemove);
284 else if (argv[1][0] == 'p')
285 bundle.setCommand(kCommandPackage);
286 else if (argv[1][0] == 'c')
287 bundle.setCommand(kCommandCrunch);
288 else if (argv[1][0] == 's')
289 bundle.setCommand(kCommandSingleCrunch);
Jerome Dochez6f1280c2014-09-26 10:21:21 -0700290 else if (argv[1][0] == 'm')
291 bundle.setCommand(kCommandDaemon);
Adam Lesinski282e1812014-01-23 18:17:42 -0800292 else {
293 fprintf(stderr, "ERROR: Unknown command '%s'\n", argv[1]);
294 wantUsage = true;
295 goto bail;
296 }
297 argc -= 2;
298 argv += 2;
299
300 /*
301 * Pull out flags. We support "-fv" and "-f -v".
302 */
303 while (argc && argv[0][0] == '-') {
304 /* flag(s) found */
305 const char* cp = argv[0] +1;
306
307 while (*cp != '\0') {
308 switch (*cp) {
309 case 'v':
310 bundle.setVerbose(true);
311 break;
312 case 'a':
313 bundle.setAndroidList(true);
314 break;
315 case 'c':
316 argc--;
317 argv++;
318 if (!argc) {
319 fprintf(stderr, "ERROR: No argument supplied for '-c' option\n");
320 wantUsage = true;
321 goto bail;
322 }
323 bundle.addConfigurations(argv[0]);
324 break;
325 case 'f':
326 bundle.setForce(true);
327 break;
328 case 'g':
329 argc--;
330 argv++;
331 if (!argc) {
332 fprintf(stderr, "ERROR: No argument supplied for '-g' option\n");
333 wantUsage = true;
334 goto bail;
335 }
336 tolerance = atoi(argv[0]);
337 bundle.setGrayscaleTolerance(tolerance);
338 printf("%s: Images with deviation <= %d will be forced to grayscale.\n", prog, tolerance);
339 break;
340 case 'k':
341 bundle.setJunkPath(true);
342 break;
343 case 'm':
344 bundle.setMakePackageDirs(true);
345 break;
346#if 0
347 case 'p':
348 bundle.setPseudolocalize(true);
349 break;
350#endif
351 case 'u':
352 bundle.setUpdate(true);
353 break;
354 case 'x':
355 bundle.setExtending(true);
356 break;
357 case 'z':
358 bundle.setRequireLocalization(true);
359 break;
360 case 'j':
361 argc--;
362 argv++;
363 if (!argc) {
364 fprintf(stderr, "ERROR: No argument supplied for '-j' option\n");
365 wantUsage = true;
366 goto bail;
367 }
368 convertPath(argv[0]);
369 bundle.addJarFile(argv[0]);
370 break;
371 case 'A':
372 argc--;
373 argv++;
374 if (!argc) {
375 fprintf(stderr, "ERROR: No argument supplied for '-A' option\n");
376 wantUsage = true;
377 goto bail;
378 }
379 convertPath(argv[0]);
Adam Lesinski09384302014-01-22 16:07:42 -0800380 bundle.addAssetSourceDir(argv[0]);
Adam Lesinski282e1812014-01-23 18:17:42 -0800381 break;
382 case 'G':
383 argc--;
384 argv++;
385 if (!argc) {
386 fprintf(stderr, "ERROR: No argument supplied for '-G' option\n");
387 wantUsage = true;
388 goto bail;
389 }
390 convertPath(argv[0]);
391 bundle.setProguardFile(argv[0]);
392 break;
393 case 'I':
394 argc--;
395 argv++;
396 if (!argc) {
397 fprintf(stderr, "ERROR: No argument supplied for '-I' option\n");
398 wantUsage = true;
399 goto bail;
400 }
401 convertPath(argv[0]);
402 bundle.addPackageInclude(argv[0]);
403 break;
404 case 'F':
405 argc--;
406 argv++;
407 if (!argc) {
408 fprintf(stderr, "ERROR: No argument supplied for '-F' option\n");
409 wantUsage = true;
410 goto bail;
411 }
412 convertPath(argv[0]);
413 bundle.setOutputAPKFile(argv[0]);
414 break;
415 case 'J':
416 argc--;
417 argv++;
418 if (!argc) {
419 fprintf(stderr, "ERROR: No argument supplied for '-J' option\n");
420 wantUsage = true;
421 goto bail;
422 }
423 convertPath(argv[0]);
424 bundle.setRClassDir(argv[0]);
425 break;
426 case 'M':
427 argc--;
428 argv++;
429 if (!argc) {
430 fprintf(stderr, "ERROR: No argument supplied for '-M' option\n");
431 wantUsage = true;
432 goto bail;
433 }
434 convertPath(argv[0]);
435 bundle.setAndroidManifestFile(argv[0]);
436 break;
437 case 'P':
438 argc--;
439 argv++;
440 if (!argc) {
441 fprintf(stderr, "ERROR: No argument supplied for '-P' option\n");
442 wantUsage = true;
443 goto bail;
444 }
445 convertPath(argv[0]);
446 bundle.setPublicOutputFile(argv[0]);
447 break;
448 case 'S':
449 argc--;
450 argv++;
451 if (!argc) {
452 fprintf(stderr, "ERROR: No argument supplied for '-S' option\n");
453 wantUsage = true;
454 goto bail;
455 }
456 convertPath(argv[0]);
457 bundle.addResourceSourceDir(argv[0]);
458 break;
459 case 'C':
460 argc--;
461 argv++;
462 if (!argc) {
463 fprintf(stderr, "ERROR: No argument supplied for '-C' option\n");
464 wantUsage = true;
465 goto bail;
466 }
467 convertPath(argv[0]);
468 bundle.setCrunchedOutputDir(argv[0]);
469 break;
470 case 'i':
471 argc--;
472 argv++;
473 if (!argc) {
474 fprintf(stderr, "ERROR: No argument supplied for '-i' option\n");
475 wantUsage = true;
476 goto bail;
477 }
478 convertPath(argv[0]);
479 bundle.setSingleCrunchInputFile(argv[0]);
480 break;
481 case 'o':
482 argc--;
483 argv++;
484 if (!argc) {
485 fprintf(stderr, "ERROR: No argument supplied for '-o' option\n");
486 wantUsage = true;
487 goto bail;
488 }
489 convertPath(argv[0]);
490 bundle.setSingleCrunchOutputFile(argv[0]);
491 break;
492 case '0':
493 argc--;
494 argv++;
495 if (!argc) {
496 fprintf(stderr, "ERROR: No argument supplied for '-e' option\n");
497 wantUsage = true;
498 goto bail;
499 }
500 if (argv[0][0] != 0) {
501 bundle.addNoCompressExtension(argv[0]);
502 } else {
503 bundle.setCompressionMethod(ZipEntry::kCompressStored);
504 }
505 break;
506 case '-':
507 if (strcmp(cp, "-debug-mode") == 0) {
508 bundle.setDebugMode(true);
509 } else if (strcmp(cp, "-min-sdk-version") == 0) {
510 argc--;
511 argv++;
512 if (!argc) {
513 fprintf(stderr, "ERROR: No argument supplied for '--min-sdk-version' option\n");
514 wantUsage = true;
515 goto bail;
516 }
517 bundle.setMinSdkVersion(argv[0]);
518 } else if (strcmp(cp, "-target-sdk-version") == 0) {
519 argc--;
520 argv++;
521 if (!argc) {
522 fprintf(stderr, "ERROR: No argument supplied for '--target-sdk-version' option\n");
523 wantUsage = true;
524 goto bail;
525 }
526 bundle.setTargetSdkVersion(argv[0]);
527 } else if (strcmp(cp, "-max-sdk-version") == 0) {
528 argc--;
529 argv++;
530 if (!argc) {
531 fprintf(stderr, "ERROR: No argument supplied for '--max-sdk-version' option\n");
532 wantUsage = true;
533 goto bail;
534 }
535 bundle.setMaxSdkVersion(argv[0]);
536 } else if (strcmp(cp, "-max-res-version") == 0) {
537 argc--;
538 argv++;
539 if (!argc) {
540 fprintf(stderr, "ERROR: No argument supplied for '--max-res-version' option\n");
541 wantUsage = true;
542 goto bail;
543 }
544 bundle.setMaxResVersion(argv[0]);
545 } else if (strcmp(cp, "-version-code") == 0) {
546 argc--;
547 argv++;
548 if (!argc) {
549 fprintf(stderr, "ERROR: No argument supplied for '--version-code' option\n");
550 wantUsage = true;
551 goto bail;
552 }
553 bundle.setVersionCode(argv[0]);
554 } else if (strcmp(cp, "-version-name") == 0) {
555 argc--;
556 argv++;
557 if (!argc) {
558 fprintf(stderr, "ERROR: No argument supplied for '--version-name' option\n");
559 wantUsage = true;
560 goto bail;
561 }
562 bundle.setVersionName(argv[0]);
Jeff Davidsondf08d1c2014-02-25 12:28:08 -0800563 } else if (strcmp(cp, "-replace-version") == 0) {
564 bundle.setReplaceVersion(true);
Adam Lesinski282e1812014-01-23 18:17:42 -0800565 } else if (strcmp(cp, "-values") == 0) {
566 bundle.setValues(true);
567 } else if (strcmp(cp, "-include-meta-data") == 0) {
568 bundle.setIncludeMetaData(true);
569 } else if (strcmp(cp, "-custom-package") == 0) {
570 argc--;
571 argv++;
572 if (!argc) {
573 fprintf(stderr, "ERROR: No argument supplied for '--custom-package' option\n");
574 wantUsage = true;
575 goto bail;
576 }
577 bundle.setCustomPackage(argv[0]);
578 } else if (strcmp(cp, "-extra-packages") == 0) {
579 argc--;
580 argv++;
581 if (!argc) {
582 fprintf(stderr, "ERROR: No argument supplied for '--extra-packages' option\n");
583 wantUsage = true;
584 goto bail;
585 }
586 bundle.setExtraPackages(argv[0]);
587 } else if (strcmp(cp, "-generate-dependencies") == 0) {
588 bundle.setGenDependencies(true);
589 } else if (strcmp(cp, "-utf16") == 0) {
590 bundle.setWantUTF16(true);
Adam Lesinskifab50872014-04-16 14:40:42 -0700591 } else if (strcmp(cp, "-preferred-density") == 0) {
Adam Lesinski282e1812014-01-23 18:17:42 -0800592 argc--;
593 argv++;
594 if (!argc) {
Adam Lesinskifab50872014-04-16 14:40:42 -0700595 fprintf(stderr, "ERROR: No argument supplied for '--preferred-density' option\n");
Adam Lesinski282e1812014-01-23 18:17:42 -0800596 wantUsage = true;
597 goto bail;
598 }
Adam Lesinskifab50872014-04-16 14:40:42 -0700599 bundle.setPreferredDensity(argv[0]);
600 } else if (strcmp(cp, "-split") == 0) {
601 argc--;
602 argv++;
603 if (!argc) {
604 fprintf(stderr, "ERROR: No argument supplied for '--split' option\n");
605 wantUsage = true;
606 goto bail;
607 }
608 bundle.addSplitConfigurations(argv[0]);
Adam Lesinski833f3cc2014-06-18 15:06:01 -0700609 } else if (strcmp(cp, "-feature-of") == 0) {
610 argc--;
611 argv++;
612 if (!argc) {
613 fprintf(stderr, "ERROR: No argument supplied for '--feature-of' option\n");
614 wantUsage = true;
615 goto bail;
616 }
617 bundle.setFeatureOfPackage(argv[0]);
618 } else if (strcmp(cp, "-feature-after") == 0) {
619 argc--;
620 argv++;
621 if (!argc) {
622 fprintf(stderr, "ERROR: No argument supplied for '--feature-after' option\n");
623 wantUsage = true;
624 goto bail;
625 }
626 bundle.setFeatureAfterPackage(argv[0]);
Adam Lesinski282e1812014-01-23 18:17:42 -0800627 } else if (strcmp(cp, "-rename-manifest-package") == 0) {
628 argc--;
629 argv++;
630 if (!argc) {
631 fprintf(stderr, "ERROR: No argument supplied for '--rename-manifest-package' option\n");
632 wantUsage = true;
633 goto bail;
634 }
635 bundle.setManifestPackageNameOverride(argv[0]);
636 } else if (strcmp(cp, "-rename-instrumentation-target-package") == 0) {
637 argc--;
638 argv++;
639 if (!argc) {
640 fprintf(stderr, "ERROR: No argument supplied for '--rename-instrumentation-target-package' option\n");
641 wantUsage = true;
642 goto bail;
643 }
644 bundle.setInstrumentationPackageNameOverride(argv[0]);
645 } else if (strcmp(cp, "-auto-add-overlay") == 0) {
646 bundle.setAutoAddOverlay(true);
647 } else if (strcmp(cp, "-error-on-failed-insert") == 0) {
648 bundle.setErrorOnFailedInsert(true);
Ying Wangcd28bd32013-11-14 17:12:10 -0800649 } else if (strcmp(cp, "-error-on-missing-config-entry") == 0) {
650 bundle.setErrorOnMissingConfigEntry(true);
Adam Lesinski282e1812014-01-23 18:17:42 -0800651 } else if (strcmp(cp, "-output-text-symbols") == 0) {
652 argc--;
653 argv++;
654 if (!argc) {
655 fprintf(stderr, "ERROR: No argument supplied for '-output-text-symbols' option\n");
656 wantUsage = true;
657 goto bail;
658 }
659 bundle.setOutputTextSymbols(argv[0]);
660 } else if (strcmp(cp, "-product") == 0) {
661 argc--;
662 argv++;
663 if (!argc) {
664 fprintf(stderr, "ERROR: No argument supplied for '--product' option\n");
665 wantUsage = true;
666 goto bail;
667 }
668 bundle.setProduct(argv[0]);
669 } else if (strcmp(cp, "-non-constant-id") == 0) {
670 bundle.setNonConstantId(true);
Adrian Roos58922482015-06-01 17:59:41 -0700671 } else if (strcmp(cp, "-skip-symbols-without-default-localization") == 0) {
672 bundle.setSkipSymbolsWithoutDefaultLocalization(true);
Adam Lesinskide898ff2014-01-29 18:20:45 -0800673 } else if (strcmp(cp, "-shared-lib") == 0) {
674 bundle.setNonConstantId(true);
675 bundle.setBuildSharedLibrary(true);
Tao Baia6d7e3f2015-09-01 18:49:54 -0700676 } else if (strcmp(cp, "-app-as-shared-lib") == 0) {
677 bundle.setNonConstantId(true);
678 bundle.setBuildAppAsSharedLibrary(true);
Adam Lesinski282e1812014-01-23 18:17:42 -0800679 } else if (strcmp(cp, "-no-crunch") == 0) {
680 bundle.setUseCrunchCache(true);
681 } else if (strcmp(cp, "-ignore-assets") == 0) {
682 argc--;
683 argv++;
684 if (!argc) {
685 fprintf(stderr, "ERROR: No argument supplied for '--ignore-assets' option\n");
686 wantUsage = true;
687 goto bail;
688 }
689 gUserIgnoreAssets = argv[0];
Igor Viarheichyka191d042014-06-02 17:16:24 -0700690 } else if (strcmp(cp, "-pseudo-localize") == 0) {
691 bundle.setPseudolocalize(PSEUDO_ACCENTED | PSEUDO_BIDI);
Adam Lesinski6e460562015-04-21 14:20:15 -0700692 } else if (strcmp(cp, "-no-version-vectors") == 0) {
693 bundle.setNoVersionVectors(true);
Adam Lesinski78713992015-12-07 14:02:15 -0800694 } else if (strcmp(cp, "-private-symbols") == 0) {
695 argc--;
696 argv++;
697 if (!argc) {
698 fprintf(stderr, "ERROR: No argument supplied for "
699 "'--private-symbols' option\n");
700 wantUsage = true;
701 goto bail;
702 }
703 bundle.setPrivateSymbolsPackage(String8(argv[0]));
Adam Lesinski282e1812014-01-23 18:17:42 -0800704 } else {
705 fprintf(stderr, "ERROR: Unknown option '-%s'\n", cp);
706 wantUsage = true;
707 goto bail;
708 }
709 cp += strlen(cp) - 1;
710 break;
711 default:
712 fprintf(stderr, "ERROR: Unknown flag '-%c'\n", *cp);
713 wantUsage = true;
714 goto bail;
715 }
716
717 cp++;
718 }
719 argc--;
720 argv++;
721 }
722
723 /*
724 * We're past the flags. The rest all goes straight in.
725 */
726 bundle.setFileSpec(argv, argc);
727
728 result = handleCommand(&bundle);
729
730bail:
731 if (wantUsage) {
732 usage();
733 result = 2;
734 }
735
736 //printf("--> returning %d\n", result);
737 return result;
738}