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