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 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 " [-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 " --no-version-transitions\n" 227 " Do not automatically generate versioned copies of transition XML resources.\n" 228 " --private-symbols\n" 229 " Java package name to use when generating R.java for private resources.\n", 230 gDefaultIgnoreAssets); 231} 232 233/* 234 * Dispatch the command. 235 */ 236int handleCommand(Bundle* bundle) 237{ 238 //printf("--- command %d (verbose=%d force=%d):\n", 239 // bundle->getCommand(), bundle->getVerbose(), bundle->getForce()); 240 //for (int i = 0; i < bundle->getFileSpecCount(); i++) 241 // printf(" %d: '%s'\n", i, bundle->getFileSpecEntry(i)); 242 243 switch (bundle->getCommand()) { 244 case kCommandVersion: return doVersion(bundle); 245 case kCommandList: return doList(bundle); 246 case kCommandDump: return doDump(bundle); 247 case kCommandAdd: return doAdd(bundle); 248 case kCommandRemove: return doRemove(bundle); 249 case kCommandPackage: return doPackage(bundle); 250 case kCommandCrunch: return doCrunch(bundle); 251 case kCommandSingleCrunch: return doSingleCrunch(bundle); 252 case kCommandDaemon: return runInDaemonMode(bundle); 253 default: 254 fprintf(stderr, "%s: requested command not yet supported\n", gProgName); 255 return 1; 256 } 257} 258 259/* 260 * Parse args. 261 */ 262int main(int argc, char* const argv[]) 263{ 264 char *prog = argv[0]; 265 Bundle bundle; 266 bool wantUsage = false; 267 int result = 1; // pessimistically assume an error. 268 int tolerance = 0; 269 270 /* default to compression */ 271 bundle.setCompressionMethod(ZipEntry::kCompressDeflated); 272 273 if (argc < 2) { 274 wantUsage = true; 275 goto bail; 276 } 277 278 if (argv[1][0] == 'v') 279 bundle.setCommand(kCommandVersion); 280 else if (argv[1][0] == 'd') 281 bundle.setCommand(kCommandDump); 282 else if (argv[1][0] == 'l') 283 bundle.setCommand(kCommandList); 284 else if (argv[1][0] == 'a') 285 bundle.setCommand(kCommandAdd); 286 else if (argv[1][0] == 'r') 287 bundle.setCommand(kCommandRemove); 288 else if (argv[1][0] == 'p') 289 bundle.setCommand(kCommandPackage); 290 else if (argv[1][0] == 'c') 291 bundle.setCommand(kCommandCrunch); 292 else if (argv[1][0] == 's') 293 bundle.setCommand(kCommandSingleCrunch); 294 else if (argv[1][0] == 'm') 295 bundle.setCommand(kCommandDaemon); 296 else { 297 fprintf(stderr, "ERROR: Unknown command '%s'\n", argv[1]); 298 wantUsage = true; 299 goto bail; 300 } 301 argc -= 2; 302 argv += 2; 303 304 /* 305 * Pull out flags. We support "-fv" and "-f -v". 306 */ 307 while (argc && argv[0][0] == '-') { 308 /* flag(s) found */ 309 const char* cp = argv[0] +1; 310 311 while (*cp != '\0') { 312 switch (*cp) { 313 case 'v': 314 bundle.setVerbose(true); 315 break; 316 case 'a': 317 bundle.setAndroidList(true); 318 break; 319 case 'c': 320 argc--; 321 argv++; 322 if (!argc) { 323 fprintf(stderr, "ERROR: No argument supplied for '-c' option\n"); 324 wantUsage = true; 325 goto bail; 326 } 327 bundle.addConfigurations(argv[0]); 328 break; 329 case 'f': 330 bundle.setForce(true); 331 break; 332 case 'g': 333 argc--; 334 argv++; 335 if (!argc) { 336 fprintf(stderr, "ERROR: No argument supplied for '-g' option\n"); 337 wantUsage = true; 338 goto bail; 339 } 340 tolerance = atoi(argv[0]); 341 bundle.setGrayscaleTolerance(tolerance); 342 printf("%s: Images with deviation <= %d will be forced to grayscale.\n", prog, tolerance); 343 break; 344 case 'k': 345 bundle.setJunkPath(true); 346 break; 347 case 'm': 348 bundle.setMakePackageDirs(true); 349 break; 350#if 0 351 case 'p': 352 bundle.setPseudolocalize(true); 353 break; 354#endif 355 case 'u': 356 bundle.setUpdate(true); 357 break; 358 case 'x': 359 bundle.setExtending(true); 360 break; 361 case 'z': 362 bundle.setRequireLocalization(true); 363 break; 364 case 'j': 365 argc--; 366 argv++; 367 if (!argc) { 368 fprintf(stderr, "ERROR: No argument supplied for '-j' option\n"); 369 wantUsage = true; 370 goto bail; 371 } 372 convertPath(argv[0]); 373 bundle.addJarFile(argv[0]); 374 break; 375 case 'A': 376 argc--; 377 argv++; 378 if (!argc) { 379 fprintf(stderr, "ERROR: No argument supplied for '-A' option\n"); 380 wantUsage = true; 381 goto bail; 382 } 383 convertPath(argv[0]); 384 bundle.addAssetSourceDir(argv[0]); 385 break; 386 case 'G': 387 argc--; 388 argv++; 389 if (!argc) { 390 fprintf(stderr, "ERROR: No argument supplied for '-G' option\n"); 391 wantUsage = true; 392 goto bail; 393 } 394 convertPath(argv[0]); 395 bundle.setProguardFile(argv[0]); 396 break; 397 case 'D': 398 argc--; 399 argv++; 400 if (!argc) { 401 fprintf(stderr, "ERROR: No argument supplied for '-D' option\n"); 402 wantUsage = true; 403 goto bail; 404 } 405 convertPath(argv[0]); 406 bundle.setMainDexProguardFile(argv[0]); 407 break; 408 case 'I': 409 argc--; 410 argv++; 411 if (!argc) { 412 fprintf(stderr, "ERROR: No argument supplied for '-I' option\n"); 413 wantUsage = true; 414 goto bail; 415 } 416 convertPath(argv[0]); 417 bundle.addPackageInclude(argv[0]); 418 break; 419 case 'F': 420 argc--; 421 argv++; 422 if (!argc) { 423 fprintf(stderr, "ERROR: No argument supplied for '-F' option\n"); 424 wantUsage = true; 425 goto bail; 426 } 427 convertPath(argv[0]); 428 bundle.setOutputAPKFile(argv[0]); 429 break; 430 case 'J': 431 argc--; 432 argv++; 433 if (!argc) { 434 fprintf(stderr, "ERROR: No argument supplied for '-J' option\n"); 435 wantUsage = true; 436 goto bail; 437 } 438 convertPath(argv[0]); 439 bundle.setRClassDir(argv[0]); 440 break; 441 case 'M': 442 argc--; 443 argv++; 444 if (!argc) { 445 fprintf(stderr, "ERROR: No argument supplied for '-M' option\n"); 446 wantUsage = true; 447 goto bail; 448 } 449 convertPath(argv[0]); 450 bundle.setAndroidManifestFile(argv[0]); 451 break; 452 case 'P': 453 argc--; 454 argv++; 455 if (!argc) { 456 fprintf(stderr, "ERROR: No argument supplied for '-P' option\n"); 457 wantUsage = true; 458 goto bail; 459 } 460 convertPath(argv[0]); 461 bundle.setPublicOutputFile(argv[0]); 462 break; 463 case 'S': 464 argc--; 465 argv++; 466 if (!argc) { 467 fprintf(stderr, "ERROR: No argument supplied for '-S' option\n"); 468 wantUsage = true; 469 goto bail; 470 } 471 convertPath(argv[0]); 472 bundle.addResourceSourceDir(argv[0]); 473 break; 474 case 'C': 475 argc--; 476 argv++; 477 if (!argc) { 478 fprintf(stderr, "ERROR: No argument supplied for '-C' option\n"); 479 wantUsage = true; 480 goto bail; 481 } 482 convertPath(argv[0]); 483 bundle.setCrunchedOutputDir(argv[0]); 484 break; 485 case 'i': 486 argc--; 487 argv++; 488 if (!argc) { 489 fprintf(stderr, "ERROR: No argument supplied for '-i' option\n"); 490 wantUsage = true; 491 goto bail; 492 } 493 convertPath(argv[0]); 494 bundle.setSingleCrunchInputFile(argv[0]); 495 break; 496 case 'o': 497 argc--; 498 argv++; 499 if (!argc) { 500 fprintf(stderr, "ERROR: No argument supplied for '-o' option\n"); 501 wantUsage = true; 502 goto bail; 503 } 504 convertPath(argv[0]); 505 bundle.setSingleCrunchOutputFile(argv[0]); 506 break; 507 case '0': 508 argc--; 509 argv++; 510 if (!argc) { 511 fprintf(stderr, "ERROR: No argument supplied for '-e' option\n"); 512 wantUsage = true; 513 goto bail; 514 } 515 if (argv[0][0] != 0) { 516 bundle.addNoCompressExtension(argv[0]); 517 } else { 518 bundle.setCompressionMethod(ZipEntry::kCompressStored); 519 } 520 break; 521 case '-': 522 if (strcmp(cp, "-debug-mode") == 0) { 523 bundle.setDebugMode(true); 524 } else if (strcmp(cp, "-min-sdk-version") == 0) { 525 argc--; 526 argv++; 527 if (!argc) { 528 fprintf(stderr, "ERROR: No argument supplied for '--min-sdk-version' option\n"); 529 wantUsage = true; 530 goto bail; 531 } 532 bundle.setMinSdkVersion(argv[0]); 533 } else if (strcmp(cp, "-target-sdk-version") == 0) { 534 argc--; 535 argv++; 536 if (!argc) { 537 fprintf(stderr, "ERROR: No argument supplied for '--target-sdk-version' option\n"); 538 wantUsage = true; 539 goto bail; 540 } 541 bundle.setTargetSdkVersion(argv[0]); 542 } else if (strcmp(cp, "-max-sdk-version") == 0) { 543 argc--; 544 argv++; 545 if (!argc) { 546 fprintf(stderr, "ERROR: No argument supplied for '--max-sdk-version' option\n"); 547 wantUsage = true; 548 goto bail; 549 } 550 bundle.setMaxSdkVersion(argv[0]); 551 } else if (strcmp(cp, "-max-res-version") == 0) { 552 argc--; 553 argv++; 554 if (!argc) { 555 fprintf(stderr, "ERROR: No argument supplied for '--max-res-version' option\n"); 556 wantUsage = true; 557 goto bail; 558 } 559 bundle.setMaxResVersion(argv[0]); 560 } else if (strcmp(cp, "-version-code") == 0) { 561 argc--; 562 argv++; 563 if (!argc) { 564 fprintf(stderr, "ERROR: No argument supplied for '--version-code' option\n"); 565 wantUsage = true; 566 goto bail; 567 } 568 bundle.setVersionCode(argv[0]); 569 } else if (strcmp(cp, "-version-name") == 0) { 570 argc--; 571 argv++; 572 if (!argc) { 573 fprintf(stderr, "ERROR: No argument supplied for '--version-name' option\n"); 574 wantUsage = true; 575 goto bail; 576 } 577 bundle.setVersionName(argv[0]); 578 } else if (strcmp(cp, "-replace-version") == 0) { 579 bundle.setReplaceVersion(true); 580 } else if (strcmp(cp, "-values") == 0) { 581 bundle.setValues(true); 582 } else if (strcmp(cp, "-include-meta-data") == 0) { 583 bundle.setIncludeMetaData(true); 584 } else if (strcmp(cp, "-custom-package") == 0) { 585 argc--; 586 argv++; 587 if (!argc) { 588 fprintf(stderr, "ERROR: No argument supplied for '--custom-package' option\n"); 589 wantUsage = true; 590 goto bail; 591 } 592 bundle.setCustomPackage(argv[0]); 593 } else if (strcmp(cp, "-extra-packages") == 0) { 594 argc--; 595 argv++; 596 if (!argc) { 597 fprintf(stderr, "ERROR: No argument supplied for '--extra-packages' option\n"); 598 wantUsage = true; 599 goto bail; 600 } 601 bundle.setExtraPackages(argv[0]); 602 } else if (strcmp(cp, "-generate-dependencies") == 0) { 603 bundle.setGenDependencies(true); 604 } else if (strcmp(cp, "-utf16") == 0) { 605 bundle.setWantUTF16(true); 606 } else if (strcmp(cp, "-preferred-density") == 0) { 607 argc--; 608 argv++; 609 if (!argc) { 610 fprintf(stderr, "ERROR: No argument supplied for '--preferred-density' option\n"); 611 wantUsage = true; 612 goto bail; 613 } 614 bundle.setPreferredDensity(argv[0]); 615 } else if (strcmp(cp, "-split") == 0) { 616 argc--; 617 argv++; 618 if (!argc) { 619 fprintf(stderr, "ERROR: No argument supplied for '--split' option\n"); 620 wantUsage = true; 621 goto bail; 622 } 623 bundle.addSplitConfigurations(argv[0]); 624 } else if (strcmp(cp, "-feature-of") == 0) { 625 argc--; 626 argv++; 627 if (!argc) { 628 fprintf(stderr, "ERROR: No argument supplied for '--feature-of' option\n"); 629 wantUsage = true; 630 goto bail; 631 } 632 bundle.setFeatureOfPackage(argv[0]); 633 } else if (strcmp(cp, "-feature-after") == 0) { 634 argc--; 635 argv++; 636 if (!argc) { 637 fprintf(stderr, "ERROR: No argument supplied for '--feature-after' option\n"); 638 wantUsage = true; 639 goto bail; 640 } 641 bundle.setFeatureAfterPackage(argv[0]); 642 } else if (strcmp(cp, "-rename-manifest-package") == 0) { 643 argc--; 644 argv++; 645 if (!argc) { 646 fprintf(stderr, "ERROR: No argument supplied for '--rename-manifest-package' option\n"); 647 wantUsage = true; 648 goto bail; 649 } 650 bundle.setManifestPackageNameOverride(argv[0]); 651 } else if (strcmp(cp, "-rename-instrumentation-target-package") == 0) { 652 argc--; 653 argv++; 654 if (!argc) { 655 fprintf(stderr, "ERROR: No argument supplied for '--rename-instrumentation-target-package' option\n"); 656 wantUsage = true; 657 goto bail; 658 } 659 bundle.setInstrumentationPackageNameOverride(argv[0]); 660 } else if (strcmp(cp, "-auto-add-overlay") == 0) { 661 bundle.setAutoAddOverlay(true); 662 } else if (strcmp(cp, "-error-on-failed-insert") == 0) { 663 bundle.setErrorOnFailedInsert(true); 664 } else if (strcmp(cp, "-error-on-missing-config-entry") == 0) { 665 bundle.setErrorOnMissingConfigEntry(true); 666 } else if (strcmp(cp, "-output-text-symbols") == 0) { 667 argc--; 668 argv++; 669 if (!argc) { 670 fprintf(stderr, "ERROR: No argument supplied for '-output-text-symbols' option\n"); 671 wantUsage = true; 672 goto bail; 673 } 674 bundle.setOutputTextSymbols(argv[0]); 675 } else if (strcmp(cp, "-product") == 0) { 676 argc--; 677 argv++; 678 if (!argc) { 679 fprintf(stderr, "ERROR: No argument supplied for '--product' option\n"); 680 wantUsage = true; 681 goto bail; 682 } 683 bundle.setProduct(argv[0]); 684 } else if (strcmp(cp, "-non-constant-id") == 0) { 685 bundle.setNonConstantId(true); 686 } else if (strcmp(cp, "-skip-symbols-without-default-localization") == 0) { 687 bundle.setSkipSymbolsWithoutDefaultLocalization(true); 688 } else if (strcmp(cp, "-shared-lib") == 0) { 689 bundle.setNonConstantId(true); 690 bundle.setBuildSharedLibrary(true); 691 } else if (strcmp(cp, "-app-as-shared-lib") == 0) { 692 bundle.setNonConstantId(true); 693 bundle.setBuildAppAsSharedLibrary(true); 694 } else if (strcmp(cp, "-no-crunch") == 0) { 695 bundle.setUseCrunchCache(true); 696 } else if (strcmp(cp, "-ignore-assets") == 0) { 697 argc--; 698 argv++; 699 if (!argc) { 700 fprintf(stderr, "ERROR: No argument supplied for '--ignore-assets' option\n"); 701 wantUsage = true; 702 goto bail; 703 } 704 gUserIgnoreAssets = argv[0]; 705 } else if (strcmp(cp, "-pseudo-localize") == 0) { 706 bundle.setPseudolocalize(PSEUDO_ACCENTED | PSEUDO_BIDI); 707 } else if (strcmp(cp, "-no-version-vectors") == 0) { 708 bundle.setNoVersionVectors(true); 709 } else if (strcmp(cp, "-no-version-transitions") == 0) { 710 bundle.setNoVersionTransitions(true); 711 } else if (strcmp(cp, "-private-symbols") == 0) { 712 argc--; 713 argv++; 714 if (!argc) { 715 fprintf(stderr, "ERROR: No argument supplied for " 716 "'--private-symbols' option\n"); 717 wantUsage = true; 718 goto bail; 719 } 720 bundle.setPrivateSymbolsPackage(String8(argv[0])); 721 } else { 722 fprintf(stderr, "ERROR: Unknown option '-%s'\n", cp); 723 wantUsage = true; 724 goto bail; 725 } 726 cp += strlen(cp) - 1; 727 break; 728 default: 729 fprintf(stderr, "ERROR: Unknown flag '-%c'\n", *cp); 730 wantUsage = true; 731 goto bail; 732 } 733 734 cp++; 735 } 736 argc--; 737 argv++; 738 } 739 740 /* 741 * We're past the flags. The rest all goes straight in. 742 */ 743 bundle.setFileSpec(argv, argc); 744 745 result = handleCommand(&bundle); 746 747bail: 748 if (wantUsage) { 749 usage(); 750 result = 2; 751 } 752 753 //printf("--> returning %d\n", result); 754 return result; 755} 756