blob: 28bdf44b08bd0ebba4bc85f42b948004be75ebf4 [file] [log] [blame]
Adam Lesinski282e1812014-01-23 18:17:42 -08001//
2// Copyright 2006 The Android Open Source Project
3//
4// Android Asset Packaging Tool main entry point.
5//
6#include "Main.h"
7#include "Bundle.h"
8
Elliott Hughes9ec96f92015-07-29 14:35:18 -07009#include <utils/Compat.h>
Adam Lesinski282e1812014-01-23 18:17:42 -080010#include <utils/Log.h>
11#include <utils/threads.h>
12#include <utils/List.h>
13#include <utils/Errors.h>
14
Adam Lesinski4bf58102014-11-03 11:21:19 -080015#include <cstdlib>
Adam Lesinski282e1812014-01-23 18:17:42 -080016#include <getopt.h>
Adam Lesinski4bf58102014-11-03 11:21:19 -080017#include <cassert>
Adam Lesinski282e1812014-01-23 18:17:42 -080018
19using namespace android;
20
21static const char* gProgName = "aapt";
22
23/*
24 * When running under Cygwin on Windows, this will convert slash-based
25 * paths into back-slash-based ones. Otherwise the ApptAssets file comparisons
26 * fail later as they use back-slash separators under Windows.
27 *
28 * This operates in-place on the path string.
29 */
30void convertPath(char *path) {
31 if (path != NULL && OS_PATH_SEPARATOR != '/') {
32 for (; *path; path++) {
33 if (*path == '/') {
34 *path = OS_PATH_SEPARATOR;
35 }
36 }
37 }
38}
39
40/*
41 * Print usage info.
42 */
43void usage(void)
44{
45 fprintf(stderr, "Android Asset Packaging Tool\n\n");
46 fprintf(stderr, "Usage:\n");
47 fprintf(stderr,
48 " %s l[ist] [-v] [-a] file.{zip,jar,apk}\n"
49 " List contents of Zip-compatible archive.\n\n", gProgName);
50 fprintf(stderr,
51 " %s d[ump] [--values] [--include-meta-data] WHAT file.{apk} [asset [asset ...]]\n"
52 " strings Print the contents of the resource table string pool in the APK.\n"
53 " badging Print the label and icon for the app declared in APK.\n"
54 " permissions Print the permissions from the APK.\n"
55 " resources Print the resource table from the APK.\n"
56 " configurations Print the configurations in the APK.\n"
57 " xmltree Print the compiled xmls in the given assets.\n"
58 " xmlstrings Print the strings of the given compiled xml assets.\n\n", gProgName);
59 fprintf(stderr,
60 " %s p[ackage] [-d][-f][-m][-u][-v][-x][-z][-M AndroidManifest.xml] \\\n"
61 " [-0 extension [-0 extension ...]] [-g tolerance] [-j jarfile] \\\n"
62 " [--debug-mode] [--min-sdk-version VAL] [--target-sdk-version VAL] \\\n"
63 " [--app-version VAL] [--app-version-name TEXT] [--custom-package VAL] \\\n"
64 " [--rename-manifest-package PACKAGE] \\\n"
65 " [--rename-instrumentation-target-package PACKAGE] \\\n"
66 " [--utf16] [--auto-add-overlay] \\\n"
67 " [--max-res-version VAL] \\\n"
68 " [-I base-package [-I base-package ...]] \\\n"
69 " [-A asset-source-dir] [-G class-list-file] [-P public-definitions-file] \\\n"
Rohit Agrawal6ba873f2016-04-21 16:29:58 -070070 " [-D main-dex-class-list-file] \\\n"
Adam Lesinski282e1812014-01-23 18:17:42 -080071 " [-S resource-sources [-S resource-sources ...]] \\\n"
72 " [-F apk-file] [-J R-file-dir] \\\n"
73 " [--product product1,product2,...] \\\n"
Johan Redestig6ab7a782015-01-07 09:24:39 +010074 " [-c CONFIGS] [--preferred-density DENSITY] \\\n"
Adam Lesinskifab50872014-04-16 14:40:42 -070075 " [--split CONFIGS [--split CONFIGS]] \\\n"
Adam Lesinski833f3cc2014-06-18 15:06:01 -070076 " [--feature-of package [--feature-after package]] \\\n"
Adam Lesinski282e1812014-01-23 18:17:42 -080077 " [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"
Adam Lesinski282e1812014-01-23 18:17:42 -0800111 " -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"
Adam Lesinski282e1812014-01-23 18:17:42 -0800117 " -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"
Rohit Agrawal6ba873f2016-04-21 16:29:58 -0700124 " -D A file to output proguard options for the main dex into.\n"
Adam Lesinski282e1812014-01-23 18:17:42 -0800125 " -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"
Igor Viarheichyka191d042014-06-02 17:16:24 -0700140 " --pseudo-localize\n"
141 " generate resources for pseudo-locales (en-XA and ar-XB).\n"
Adam Lesinski282e1812014-01-23 18:17:42 -0800142 " --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"
Jeff Davidsondf08d1c2014-02-25 12:28:08 -0800155 " --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"
Adam Lesinski282e1812014-01-23 18:17:42 -0800160 " --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"
Adam Lesinskifab50872014-04-16 14:40:42 -0700168 " --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"
Adam Lesinski833f3cc2014-06-18 15:06:01 -0700174 " --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"
Adam Lesinski282e1812014-01-23 18:17:42 -0800182 " --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"
Adam Lesinskide898ff2014-01-29 18:20:45 -0800202 " --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"
Adam Lesinski282e1812014-01-23 18:17:42 -0800205 " --error-on-failed-insert\n"
206 " Forces aapt to return an error if it fails to insert values into the manifest\n"
207 " with --debug-mode, --min-sdk-version, --target-sdk-version --version-code\n"
208 " and --version-name.\n"
209 " Insertion typically fails if the manifest already defines the attribute.\n"
Ying Wangcd28bd32013-11-14 17:12:10 -0800210 " --error-on-missing-config-entry\n"
211 " Forces aapt to return an error if it fails to find an entry for a configuration.\n"
Adam Lesinski282e1812014-01-23 18:17:42 -0800212 " --output-text-symbols\n"
213 " Generates a text file containing the resource symbols of the R class in the\n"
214 " specified folder.\n"
215 " --ignore-assets\n"
216 " Assets to be ignored. Default pattern is:\n"
Adam Lesinski6e460562015-04-21 14:20:15 -0700217 " %s\n"
Adrian Roos58922482015-06-01 17:59:41 -0700218 " --skip-symbols-without-default-localization\n"
219 " Prevents symbols from being generated for strings that do not have a default\n"
220 " localization\n"
Adam Lesinski6e460562015-04-21 14:20:15 -0700221 " --no-version-vectors\n"
222 " Do not automatically generate versioned copies of vector XML resources.\n",
Adam Lesinski282e1812014-01-23 18:17:42 -0800223 gDefaultIgnoreAssets);
224}
225
226/*
227 * Dispatch the command.
228 */
229int handleCommand(Bundle* bundle)
230{
231 //printf("--- command %d (verbose=%d force=%d):\n",
232 // bundle->getCommand(), bundle->getVerbose(), bundle->getForce());
233 //for (int i = 0; i < bundle->getFileSpecCount(); i++)
234 // printf(" %d: '%s'\n", i, bundle->getFileSpecEntry(i));
235
236 switch (bundle->getCommand()) {
237 case kCommandVersion: return doVersion(bundle);
238 case kCommandList: return doList(bundle);
239 case kCommandDump: return doDump(bundle);
240 case kCommandAdd: return doAdd(bundle);
241 case kCommandRemove: return doRemove(bundle);
242 case kCommandPackage: return doPackage(bundle);
243 case kCommandCrunch: return doCrunch(bundle);
244 case kCommandSingleCrunch: return doSingleCrunch(bundle);
Jerome Dochez6f1280c2014-09-26 10:21:21 -0700245 case kCommandDaemon: return runInDaemonMode(bundle);
Adam Lesinski282e1812014-01-23 18:17:42 -0800246 default:
247 fprintf(stderr, "%s: requested command not yet supported\n", gProgName);
248 return 1;
249 }
250}
251
252/*
253 * Parse args.
254 */
255int main(int argc, char* const argv[])
256{
257 char *prog = argv[0];
258 Bundle bundle;
259 bool wantUsage = false;
260 int result = 1; // pessimistically assume an error.
261 int tolerance = 0;
262
263 /* default to compression */
264 bundle.setCompressionMethod(ZipEntry::kCompressDeflated);
265
266 if (argc < 2) {
267 wantUsage = true;
268 goto bail;
269 }
270
271 if (argv[1][0] == 'v')
272 bundle.setCommand(kCommandVersion);
273 else if (argv[1][0] == 'd')
274 bundle.setCommand(kCommandDump);
275 else if (argv[1][0] == 'l')
276 bundle.setCommand(kCommandList);
277 else if (argv[1][0] == 'a')
278 bundle.setCommand(kCommandAdd);
279 else if (argv[1][0] == 'r')
280 bundle.setCommand(kCommandRemove);
281 else if (argv[1][0] == 'p')
282 bundle.setCommand(kCommandPackage);
283 else if (argv[1][0] == 'c')
284 bundle.setCommand(kCommandCrunch);
285 else if (argv[1][0] == 's')
286 bundle.setCommand(kCommandSingleCrunch);
Jerome Dochez6f1280c2014-09-26 10:21:21 -0700287 else if (argv[1][0] == 'm')
288 bundle.setCommand(kCommandDaemon);
Adam Lesinski282e1812014-01-23 18:17:42 -0800289 else {
290 fprintf(stderr, "ERROR: Unknown command '%s'\n", argv[1]);
291 wantUsage = true;
292 goto bail;
293 }
294 argc -= 2;
295 argv += 2;
296
297 /*
298 * Pull out flags. We support "-fv" and "-f -v".
299 */
300 while (argc && argv[0][0] == '-') {
301 /* flag(s) found */
302 const char* cp = argv[0] +1;
303
304 while (*cp != '\0') {
305 switch (*cp) {
306 case 'v':
307 bundle.setVerbose(true);
308 break;
309 case 'a':
310 bundle.setAndroidList(true);
311 break;
312 case 'c':
313 argc--;
314 argv++;
315 if (!argc) {
316 fprintf(stderr, "ERROR: No argument supplied for '-c' option\n");
317 wantUsage = true;
318 goto bail;
319 }
320 bundle.addConfigurations(argv[0]);
321 break;
322 case 'f':
323 bundle.setForce(true);
324 break;
325 case 'g':
326 argc--;
327 argv++;
328 if (!argc) {
329 fprintf(stderr, "ERROR: No argument supplied for '-g' option\n");
330 wantUsage = true;
331 goto bail;
332 }
333 tolerance = atoi(argv[0]);
334 bundle.setGrayscaleTolerance(tolerance);
335 printf("%s: Images with deviation <= %d will be forced to grayscale.\n", prog, tolerance);
336 break;
337 case 'k':
338 bundle.setJunkPath(true);
339 break;
340 case 'm':
341 bundle.setMakePackageDirs(true);
342 break;
343#if 0
344 case 'p':
345 bundle.setPseudolocalize(true);
346 break;
347#endif
348 case 'u':
349 bundle.setUpdate(true);
350 break;
351 case 'x':
352 bundle.setExtending(true);
353 break;
354 case 'z':
355 bundle.setRequireLocalization(true);
356 break;
357 case 'j':
358 argc--;
359 argv++;
360 if (!argc) {
361 fprintf(stderr, "ERROR: No argument supplied for '-j' option\n");
362 wantUsage = true;
363 goto bail;
364 }
365 convertPath(argv[0]);
366 bundle.addJarFile(argv[0]);
367 break;
368 case 'A':
369 argc--;
370 argv++;
371 if (!argc) {
372 fprintf(stderr, "ERROR: No argument supplied for '-A' option\n");
373 wantUsage = true;
374 goto bail;
375 }
376 convertPath(argv[0]);
Adam Lesinski09384302014-01-22 16:07:42 -0800377 bundle.addAssetSourceDir(argv[0]);
Adam Lesinski282e1812014-01-23 18:17:42 -0800378 break;
379 case 'G':
380 argc--;
381 argv++;
382 if (!argc) {
383 fprintf(stderr, "ERROR: No argument supplied for '-G' option\n");
384 wantUsage = true;
385 goto bail;
386 }
387 convertPath(argv[0]);
388 bundle.setProguardFile(argv[0]);
389 break;
Rohit Agrawal6ba873f2016-04-21 16:29:58 -0700390 case 'D':
391 argc--;
392 argv++;
393 if (!argc) {
394 fprintf(stderr, "ERROR: No argument supplied for '-D' option\n");
395 wantUsage = true;
396 goto bail;
397 }
398 convertPath(argv[0]);
399 bundle.setMainDexProguardFile(argv[0]);
400 break;
Adam Lesinski282e1812014-01-23 18:17:42 -0800401 case 'I':
402 argc--;
403 argv++;
404 if (!argc) {
405 fprintf(stderr, "ERROR: No argument supplied for '-I' option\n");
406 wantUsage = true;
407 goto bail;
408 }
409 convertPath(argv[0]);
410 bundle.addPackageInclude(argv[0]);
411 break;
412 case 'F':
413 argc--;
414 argv++;
415 if (!argc) {
416 fprintf(stderr, "ERROR: No argument supplied for '-F' option\n");
417 wantUsage = true;
418 goto bail;
419 }
420 convertPath(argv[0]);
421 bundle.setOutputAPKFile(argv[0]);
422 break;
423 case 'J':
424 argc--;
425 argv++;
426 if (!argc) {
427 fprintf(stderr, "ERROR: No argument supplied for '-J' option\n");
428 wantUsage = true;
429 goto bail;
430 }
431 convertPath(argv[0]);
432 bundle.setRClassDir(argv[0]);
433 break;
434 case 'M':
435 argc--;
436 argv++;
437 if (!argc) {
438 fprintf(stderr, "ERROR: No argument supplied for '-M' option\n");
439 wantUsage = true;
440 goto bail;
441 }
442 convertPath(argv[0]);
443 bundle.setAndroidManifestFile(argv[0]);
444 break;
445 case 'P':
446 argc--;
447 argv++;
448 if (!argc) {
449 fprintf(stderr, "ERROR: No argument supplied for '-P' option\n");
450 wantUsage = true;
451 goto bail;
452 }
453 convertPath(argv[0]);
454 bundle.setPublicOutputFile(argv[0]);
455 break;
456 case 'S':
457 argc--;
458 argv++;
459 if (!argc) {
460 fprintf(stderr, "ERROR: No argument supplied for '-S' option\n");
461 wantUsage = true;
462 goto bail;
463 }
464 convertPath(argv[0]);
465 bundle.addResourceSourceDir(argv[0]);
466 break;
467 case 'C':
468 argc--;
469 argv++;
470 if (!argc) {
471 fprintf(stderr, "ERROR: No argument supplied for '-C' option\n");
472 wantUsage = true;
473 goto bail;
474 }
475 convertPath(argv[0]);
476 bundle.setCrunchedOutputDir(argv[0]);
477 break;
478 case 'i':
479 argc--;
480 argv++;
481 if (!argc) {
482 fprintf(stderr, "ERROR: No argument supplied for '-i' option\n");
483 wantUsage = true;
484 goto bail;
485 }
486 convertPath(argv[0]);
487 bundle.setSingleCrunchInputFile(argv[0]);
488 break;
489 case 'o':
490 argc--;
491 argv++;
492 if (!argc) {
493 fprintf(stderr, "ERROR: No argument supplied for '-o' option\n");
494 wantUsage = true;
495 goto bail;
496 }
497 convertPath(argv[0]);
498 bundle.setSingleCrunchOutputFile(argv[0]);
499 break;
500 case '0':
501 argc--;
502 argv++;
503 if (!argc) {
504 fprintf(stderr, "ERROR: No argument supplied for '-e' option\n");
505 wantUsage = true;
506 goto bail;
507 }
508 if (argv[0][0] != 0) {
509 bundle.addNoCompressExtension(argv[0]);
510 } else {
511 bundle.setCompressionMethod(ZipEntry::kCompressStored);
512 }
513 break;
514 case '-':
515 if (strcmp(cp, "-debug-mode") == 0) {
516 bundle.setDebugMode(true);
517 } else if (strcmp(cp, "-min-sdk-version") == 0) {
518 argc--;
519 argv++;
520 if (!argc) {
521 fprintf(stderr, "ERROR: No argument supplied for '--min-sdk-version' option\n");
522 wantUsage = true;
523 goto bail;
524 }
525 bundle.setMinSdkVersion(argv[0]);
526 } else if (strcmp(cp, "-target-sdk-version") == 0) {
527 argc--;
528 argv++;
529 if (!argc) {
530 fprintf(stderr, "ERROR: No argument supplied for '--target-sdk-version' option\n");
531 wantUsage = true;
532 goto bail;
533 }
534 bundle.setTargetSdkVersion(argv[0]);
535 } else if (strcmp(cp, "-max-sdk-version") == 0) {
536 argc--;
537 argv++;
538 if (!argc) {
539 fprintf(stderr, "ERROR: No argument supplied for '--max-sdk-version' option\n");
540 wantUsage = true;
541 goto bail;
542 }
543 bundle.setMaxSdkVersion(argv[0]);
544 } else if (strcmp(cp, "-max-res-version") == 0) {
545 argc--;
546 argv++;
547 if (!argc) {
548 fprintf(stderr, "ERROR: No argument supplied for '--max-res-version' option\n");
549 wantUsage = true;
550 goto bail;
551 }
552 bundle.setMaxResVersion(argv[0]);
553 } else if (strcmp(cp, "-version-code") == 0) {
554 argc--;
555 argv++;
556 if (!argc) {
557 fprintf(stderr, "ERROR: No argument supplied for '--version-code' option\n");
558 wantUsage = true;
559 goto bail;
560 }
561 bundle.setVersionCode(argv[0]);
562 } else if (strcmp(cp, "-version-name") == 0) {
563 argc--;
564 argv++;
565 if (!argc) {
566 fprintf(stderr, "ERROR: No argument supplied for '--version-name' option\n");
567 wantUsage = true;
568 goto bail;
569 }
570 bundle.setVersionName(argv[0]);
Jeff Davidsondf08d1c2014-02-25 12:28:08 -0800571 } else if (strcmp(cp, "-replace-version") == 0) {
572 bundle.setReplaceVersion(true);
Adam Lesinski282e1812014-01-23 18:17:42 -0800573 } else if (strcmp(cp, "-values") == 0) {
574 bundle.setValues(true);
575 } else if (strcmp(cp, "-include-meta-data") == 0) {
576 bundle.setIncludeMetaData(true);
577 } else if (strcmp(cp, "-custom-package") == 0) {
578 argc--;
579 argv++;
580 if (!argc) {
581 fprintf(stderr, "ERROR: No argument supplied for '--custom-package' option\n");
582 wantUsage = true;
583 goto bail;
584 }
585 bundle.setCustomPackage(argv[0]);
586 } else if (strcmp(cp, "-extra-packages") == 0) {
587 argc--;
588 argv++;
589 if (!argc) {
590 fprintf(stderr, "ERROR: No argument supplied for '--extra-packages' option\n");
591 wantUsage = true;
592 goto bail;
593 }
594 bundle.setExtraPackages(argv[0]);
595 } else if (strcmp(cp, "-generate-dependencies") == 0) {
596 bundle.setGenDependencies(true);
597 } else if (strcmp(cp, "-utf16") == 0) {
598 bundle.setWantUTF16(true);
Adam Lesinskifab50872014-04-16 14:40:42 -0700599 } else if (strcmp(cp, "-preferred-density") == 0) {
Adam Lesinski282e1812014-01-23 18:17:42 -0800600 argc--;
601 argv++;
602 if (!argc) {
Adam Lesinskifab50872014-04-16 14:40:42 -0700603 fprintf(stderr, "ERROR: No argument supplied for '--preferred-density' option\n");
Adam Lesinski282e1812014-01-23 18:17:42 -0800604 wantUsage = true;
605 goto bail;
606 }
Adam Lesinskifab50872014-04-16 14:40:42 -0700607 bundle.setPreferredDensity(argv[0]);
608 } else if (strcmp(cp, "-split") == 0) {
609 argc--;
610 argv++;
611 if (!argc) {
612 fprintf(stderr, "ERROR: No argument supplied for '--split' option\n");
613 wantUsage = true;
614 goto bail;
615 }
616 bundle.addSplitConfigurations(argv[0]);
Adam Lesinski833f3cc2014-06-18 15:06:01 -0700617 } else if (strcmp(cp, "-feature-of") == 0) {
618 argc--;
619 argv++;
620 if (!argc) {
621 fprintf(stderr, "ERROR: No argument supplied for '--feature-of' option\n");
622 wantUsage = true;
623 goto bail;
624 }
625 bundle.setFeatureOfPackage(argv[0]);
626 } else if (strcmp(cp, "-feature-after") == 0) {
627 argc--;
628 argv++;
629 if (!argc) {
630 fprintf(stderr, "ERROR: No argument supplied for '--feature-after' option\n");
631 wantUsage = true;
632 goto bail;
633 }
634 bundle.setFeatureAfterPackage(argv[0]);
Adam Lesinski282e1812014-01-23 18:17:42 -0800635 } else if (strcmp(cp, "-rename-manifest-package") == 0) {
636 argc--;
637 argv++;
638 if (!argc) {
639 fprintf(stderr, "ERROR: No argument supplied for '--rename-manifest-package' option\n");
640 wantUsage = true;
641 goto bail;
642 }
643 bundle.setManifestPackageNameOverride(argv[0]);
644 } else if (strcmp(cp, "-rename-instrumentation-target-package") == 0) {
645 argc--;
646 argv++;
647 if (!argc) {
648 fprintf(stderr, "ERROR: No argument supplied for '--rename-instrumentation-target-package' option\n");
649 wantUsage = true;
650 goto bail;
651 }
652 bundle.setInstrumentationPackageNameOverride(argv[0]);
653 } else if (strcmp(cp, "-auto-add-overlay") == 0) {
654 bundle.setAutoAddOverlay(true);
655 } else if (strcmp(cp, "-error-on-failed-insert") == 0) {
656 bundle.setErrorOnFailedInsert(true);
Ying Wangcd28bd32013-11-14 17:12:10 -0800657 } else if (strcmp(cp, "-error-on-missing-config-entry") == 0) {
658 bundle.setErrorOnMissingConfigEntry(true);
Adam Lesinski282e1812014-01-23 18:17:42 -0800659 } else if (strcmp(cp, "-output-text-symbols") == 0) {
660 argc--;
661 argv++;
662 if (!argc) {
663 fprintf(stderr, "ERROR: No argument supplied for '-output-text-symbols' option\n");
664 wantUsage = true;
665 goto bail;
666 }
667 bundle.setOutputTextSymbols(argv[0]);
668 } else if (strcmp(cp, "-product") == 0) {
669 argc--;
670 argv++;
671 if (!argc) {
672 fprintf(stderr, "ERROR: No argument supplied for '--product' option\n");
673 wantUsage = true;
674 goto bail;
675 }
676 bundle.setProduct(argv[0]);
677 } else if (strcmp(cp, "-non-constant-id") == 0) {
678 bundle.setNonConstantId(true);
Adrian Roos58922482015-06-01 17:59:41 -0700679 } else if (strcmp(cp, "-skip-symbols-without-default-localization") == 0) {
680 bundle.setSkipSymbolsWithoutDefaultLocalization(true);
Adam Lesinskide898ff2014-01-29 18:20:45 -0800681 } else if (strcmp(cp, "-shared-lib") == 0) {
682 bundle.setNonConstantId(true);
683 bundle.setBuildSharedLibrary(true);
Adam Lesinski282e1812014-01-23 18:17:42 -0800684 } else if (strcmp(cp, "-no-crunch") == 0) {
685 bundle.setUseCrunchCache(true);
686 } else if (strcmp(cp, "-ignore-assets") == 0) {
687 argc--;
688 argv++;
689 if (!argc) {
690 fprintf(stderr, "ERROR: No argument supplied for '--ignore-assets' option\n");
691 wantUsage = true;
692 goto bail;
693 }
694 gUserIgnoreAssets = argv[0];
Igor Viarheichyka191d042014-06-02 17:16:24 -0700695 } else if (strcmp(cp, "-pseudo-localize") == 0) {
696 bundle.setPseudolocalize(PSEUDO_ACCENTED | PSEUDO_BIDI);
Adam Lesinski6e460562015-04-21 14:20:15 -0700697 } else if (strcmp(cp, "-no-version-vectors") == 0) {
698 bundle.setNoVersionVectors(true);
Adam Lesinski282e1812014-01-23 18:17:42 -0800699 } else {
700 fprintf(stderr, "ERROR: Unknown option '-%s'\n", cp);
701 wantUsage = true;
702 goto bail;
703 }
704 cp += strlen(cp) - 1;
705 break;
706 default:
707 fprintf(stderr, "ERROR: Unknown flag '-%c'\n", *cp);
708 wantUsage = true;
709 goto bail;
710 }
711
712 cp++;
713 }
714 argc--;
715 argv++;
716 }
717
718 /*
719 * We're past the flags. The rest all goes straight in.
720 */
721 bundle.setFileSpec(argv, argc);
722
723 result = handleCommand(&bundle);
724
725bail:
726 if (wantUsage) {
727 usage();
728 result = 2;
729 }
730
731 //printf("--> returning %d\n", result);
732 return result;
733}