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