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