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