blob: eeee2fa5f9da7d0247682d7fe251d199da2c939a [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"
Adam Lesinski282e1812014-01-23 18:17:42 -0800203 " --error-on-failed-insert\n"
204 " Forces aapt to return an error if it fails to insert values into the manifest\n"
205 " with --debug-mode, --min-sdk-version, --target-sdk-version --version-code\n"
206 " and --version-name.\n"
207 " Insertion typically fails if the manifest already defines the attribute.\n"
Ying Wangcd28bd32013-11-14 17:12:10 -0800208 " --error-on-missing-config-entry\n"
209 " Forces aapt to return an error if it fails to find an entry for a configuration.\n"
Adam Lesinski282e1812014-01-23 18:17:42 -0800210 " --output-text-symbols\n"
211 " Generates a text file containing the resource symbols of the R class in the\n"
212 " specified folder.\n"
213 " --ignore-assets\n"
214 " Assets to be ignored. Default pattern is:\n"
215 " %s\n",
216 gDefaultIgnoreAssets);
217}
218
219/*
220 * Dispatch the command.
221 */
222int handleCommand(Bundle* bundle)
223{
224 //printf("--- command %d (verbose=%d force=%d):\n",
225 // bundle->getCommand(), bundle->getVerbose(), bundle->getForce());
226 //for (int i = 0; i < bundle->getFileSpecCount(); i++)
227 // printf(" %d: '%s'\n", i, bundle->getFileSpecEntry(i));
228
229 switch (bundle->getCommand()) {
230 case kCommandVersion: return doVersion(bundle);
231 case kCommandList: return doList(bundle);
232 case kCommandDump: return doDump(bundle);
233 case kCommandAdd: return doAdd(bundle);
234 case kCommandRemove: return doRemove(bundle);
235 case kCommandPackage: return doPackage(bundle);
236 case kCommandCrunch: return doCrunch(bundle);
237 case kCommandSingleCrunch: return doSingleCrunch(bundle);
Jerome Dochez6f1280c2014-09-26 10:21:21 -0700238 case kCommandDaemon: return runInDaemonMode(bundle);
Adam Lesinski282e1812014-01-23 18:17:42 -0800239 default:
240 fprintf(stderr, "%s: requested command not yet supported\n", gProgName);
241 return 1;
242 }
243}
244
245/*
246 * Parse args.
247 */
248int main(int argc, char* const argv[])
249{
250 char *prog = argv[0];
251 Bundle bundle;
252 bool wantUsage = false;
253 int result = 1; // pessimistically assume an error.
254 int tolerance = 0;
255
256 /* default to compression */
257 bundle.setCompressionMethod(ZipEntry::kCompressDeflated);
258
259 if (argc < 2) {
260 wantUsage = true;
261 goto bail;
262 }
263
264 if (argv[1][0] == 'v')
265 bundle.setCommand(kCommandVersion);
266 else if (argv[1][0] == 'd')
267 bundle.setCommand(kCommandDump);
268 else if (argv[1][0] == 'l')
269 bundle.setCommand(kCommandList);
270 else if (argv[1][0] == 'a')
271 bundle.setCommand(kCommandAdd);
272 else if (argv[1][0] == 'r')
273 bundle.setCommand(kCommandRemove);
274 else if (argv[1][0] == 'p')
275 bundle.setCommand(kCommandPackage);
276 else if (argv[1][0] == 'c')
277 bundle.setCommand(kCommandCrunch);
278 else if (argv[1][0] == 's')
279 bundle.setCommand(kCommandSingleCrunch);
Jerome Dochez6f1280c2014-09-26 10:21:21 -0700280 else if (argv[1][0] == 'm')
281 bundle.setCommand(kCommandDaemon);
Adam Lesinski282e1812014-01-23 18:17:42 -0800282 else {
283 fprintf(stderr, "ERROR: Unknown command '%s'\n", argv[1]);
284 wantUsage = true;
285 goto bail;
286 }
287 argc -= 2;
288 argv += 2;
289
290 /*
291 * Pull out flags. We support "-fv" and "-f -v".
292 */
293 while (argc && argv[0][0] == '-') {
294 /* flag(s) found */
295 const char* cp = argv[0] +1;
296
297 while (*cp != '\0') {
298 switch (*cp) {
299 case 'v':
300 bundle.setVerbose(true);
301 break;
302 case 'a':
303 bundle.setAndroidList(true);
304 break;
305 case 'c':
306 argc--;
307 argv++;
308 if (!argc) {
309 fprintf(stderr, "ERROR: No argument supplied for '-c' option\n");
310 wantUsage = true;
311 goto bail;
312 }
313 bundle.addConfigurations(argv[0]);
314 break;
315 case 'f':
316 bundle.setForce(true);
317 break;
318 case 'g':
319 argc--;
320 argv++;
321 if (!argc) {
322 fprintf(stderr, "ERROR: No argument supplied for '-g' option\n");
323 wantUsage = true;
324 goto bail;
325 }
326 tolerance = atoi(argv[0]);
327 bundle.setGrayscaleTolerance(tolerance);
328 printf("%s: Images with deviation <= %d will be forced to grayscale.\n", prog, tolerance);
329 break;
330 case 'k':
331 bundle.setJunkPath(true);
332 break;
333 case 'm':
334 bundle.setMakePackageDirs(true);
335 break;
336#if 0
337 case 'p':
338 bundle.setPseudolocalize(true);
339 break;
340#endif
341 case 'u':
342 bundle.setUpdate(true);
343 break;
344 case 'x':
345 bundle.setExtending(true);
346 break;
347 case 'z':
348 bundle.setRequireLocalization(true);
349 break;
350 case 'j':
351 argc--;
352 argv++;
353 if (!argc) {
354 fprintf(stderr, "ERROR: No argument supplied for '-j' option\n");
355 wantUsage = true;
356 goto bail;
357 }
358 convertPath(argv[0]);
359 bundle.addJarFile(argv[0]);
360 break;
361 case 'A':
362 argc--;
363 argv++;
364 if (!argc) {
365 fprintf(stderr, "ERROR: No argument supplied for '-A' option\n");
366 wantUsage = true;
367 goto bail;
368 }
369 convertPath(argv[0]);
Adam Lesinski09384302014-01-22 16:07:42 -0800370 bundle.addAssetSourceDir(argv[0]);
Adam Lesinski282e1812014-01-23 18:17:42 -0800371 break;
372 case 'G':
373 argc--;
374 argv++;
375 if (!argc) {
376 fprintf(stderr, "ERROR: No argument supplied for '-G' option\n");
377 wantUsage = true;
378 goto bail;
379 }
380 convertPath(argv[0]);
381 bundle.setProguardFile(argv[0]);
382 break;
383 case 'I':
384 argc--;
385 argv++;
386 if (!argc) {
387 fprintf(stderr, "ERROR: No argument supplied for '-I' option\n");
388 wantUsage = true;
389 goto bail;
390 }
391 convertPath(argv[0]);
392 bundle.addPackageInclude(argv[0]);
393 break;
394 case 'F':
395 argc--;
396 argv++;
397 if (!argc) {
398 fprintf(stderr, "ERROR: No argument supplied for '-F' option\n");
399 wantUsage = true;
400 goto bail;
401 }
402 convertPath(argv[0]);
403 bundle.setOutputAPKFile(argv[0]);
404 break;
405 case 'J':
406 argc--;
407 argv++;
408 if (!argc) {
409 fprintf(stderr, "ERROR: No argument supplied for '-J' option\n");
410 wantUsage = true;
411 goto bail;
412 }
413 convertPath(argv[0]);
414 bundle.setRClassDir(argv[0]);
415 break;
416 case 'M':
417 argc--;
418 argv++;
419 if (!argc) {
420 fprintf(stderr, "ERROR: No argument supplied for '-M' option\n");
421 wantUsage = true;
422 goto bail;
423 }
424 convertPath(argv[0]);
425 bundle.setAndroidManifestFile(argv[0]);
426 break;
427 case 'P':
428 argc--;
429 argv++;
430 if (!argc) {
431 fprintf(stderr, "ERROR: No argument supplied for '-P' option\n");
432 wantUsage = true;
433 goto bail;
434 }
435 convertPath(argv[0]);
436 bundle.setPublicOutputFile(argv[0]);
437 break;
438 case 'S':
439 argc--;
440 argv++;
441 if (!argc) {
442 fprintf(stderr, "ERROR: No argument supplied for '-S' option\n");
443 wantUsage = true;
444 goto bail;
445 }
446 convertPath(argv[0]);
447 bundle.addResourceSourceDir(argv[0]);
448 break;
449 case 'C':
450 argc--;
451 argv++;
452 if (!argc) {
453 fprintf(stderr, "ERROR: No argument supplied for '-C' option\n");
454 wantUsage = true;
455 goto bail;
456 }
457 convertPath(argv[0]);
458 bundle.setCrunchedOutputDir(argv[0]);
459 break;
460 case 'i':
461 argc--;
462 argv++;
463 if (!argc) {
464 fprintf(stderr, "ERROR: No argument supplied for '-i' option\n");
465 wantUsage = true;
466 goto bail;
467 }
468 convertPath(argv[0]);
469 bundle.setSingleCrunchInputFile(argv[0]);
470 break;
471 case 'o':
472 argc--;
473 argv++;
474 if (!argc) {
475 fprintf(stderr, "ERROR: No argument supplied for '-o' option\n");
476 wantUsage = true;
477 goto bail;
478 }
479 convertPath(argv[0]);
480 bundle.setSingleCrunchOutputFile(argv[0]);
481 break;
482 case '0':
483 argc--;
484 argv++;
485 if (!argc) {
486 fprintf(stderr, "ERROR: No argument supplied for '-e' option\n");
487 wantUsage = true;
488 goto bail;
489 }
490 if (argv[0][0] != 0) {
491 bundle.addNoCompressExtension(argv[0]);
492 } else {
493 bundle.setCompressionMethod(ZipEntry::kCompressStored);
494 }
495 break;
496 case '-':
497 if (strcmp(cp, "-debug-mode") == 0) {
498 bundle.setDebugMode(true);
499 } else if (strcmp(cp, "-min-sdk-version") == 0) {
500 argc--;
501 argv++;
502 if (!argc) {
503 fprintf(stderr, "ERROR: No argument supplied for '--min-sdk-version' option\n");
504 wantUsage = true;
505 goto bail;
506 }
507 bundle.setMinSdkVersion(argv[0]);
508 } else if (strcmp(cp, "-target-sdk-version") == 0) {
509 argc--;
510 argv++;
511 if (!argc) {
512 fprintf(stderr, "ERROR: No argument supplied for '--target-sdk-version' option\n");
513 wantUsage = true;
514 goto bail;
515 }
516 bundle.setTargetSdkVersion(argv[0]);
517 } else if (strcmp(cp, "-max-sdk-version") == 0) {
518 argc--;
519 argv++;
520 if (!argc) {
521 fprintf(stderr, "ERROR: No argument supplied for '--max-sdk-version' option\n");
522 wantUsage = true;
523 goto bail;
524 }
525 bundle.setMaxSdkVersion(argv[0]);
526 } else if (strcmp(cp, "-max-res-version") == 0) {
527 argc--;
528 argv++;
529 if (!argc) {
530 fprintf(stderr, "ERROR: No argument supplied for '--max-res-version' option\n");
531 wantUsage = true;
532 goto bail;
533 }
534 bundle.setMaxResVersion(argv[0]);
535 } else if (strcmp(cp, "-version-code") == 0) {
536 argc--;
537 argv++;
538 if (!argc) {
539 fprintf(stderr, "ERROR: No argument supplied for '--version-code' option\n");
540 wantUsage = true;
541 goto bail;
542 }
543 bundle.setVersionCode(argv[0]);
544 } else if (strcmp(cp, "-version-name") == 0) {
545 argc--;
546 argv++;
547 if (!argc) {
548 fprintf(stderr, "ERROR: No argument supplied for '--version-name' option\n");
549 wantUsage = true;
550 goto bail;
551 }
552 bundle.setVersionName(argv[0]);
Jeff Davidsondf08d1c2014-02-25 12:28:08 -0800553 } else if (strcmp(cp, "-replace-version") == 0) {
554 bundle.setReplaceVersion(true);
Adam Lesinski282e1812014-01-23 18:17:42 -0800555 } else if (strcmp(cp, "-values") == 0) {
556 bundle.setValues(true);
557 } else if (strcmp(cp, "-include-meta-data") == 0) {
558 bundle.setIncludeMetaData(true);
559 } else if (strcmp(cp, "-custom-package") == 0) {
560 argc--;
561 argv++;
562 if (!argc) {
563 fprintf(stderr, "ERROR: No argument supplied for '--custom-package' option\n");
564 wantUsage = true;
565 goto bail;
566 }
567 bundle.setCustomPackage(argv[0]);
568 } else if (strcmp(cp, "-extra-packages") == 0) {
569 argc--;
570 argv++;
571 if (!argc) {
572 fprintf(stderr, "ERROR: No argument supplied for '--extra-packages' option\n");
573 wantUsage = true;
574 goto bail;
575 }
576 bundle.setExtraPackages(argv[0]);
577 } else if (strcmp(cp, "-generate-dependencies") == 0) {
578 bundle.setGenDependencies(true);
579 } else if (strcmp(cp, "-utf16") == 0) {
580 bundle.setWantUTF16(true);
Adam Lesinskifab50872014-04-16 14:40:42 -0700581 } else if (strcmp(cp, "-preferred-density") == 0) {
Adam Lesinski282e1812014-01-23 18:17:42 -0800582 argc--;
583 argv++;
584 if (!argc) {
Adam Lesinskifab50872014-04-16 14:40:42 -0700585 fprintf(stderr, "ERROR: No argument supplied for '--preferred-density' option\n");
Adam Lesinski282e1812014-01-23 18:17:42 -0800586 wantUsage = true;
587 goto bail;
588 }
Adam Lesinskifab50872014-04-16 14:40:42 -0700589 bundle.setPreferredDensity(argv[0]);
590 } else if (strcmp(cp, "-split") == 0) {
591 argc--;
592 argv++;
593 if (!argc) {
594 fprintf(stderr, "ERROR: No argument supplied for '--split' option\n");
595 wantUsage = true;
596 goto bail;
597 }
598 bundle.addSplitConfigurations(argv[0]);
Adam Lesinski833f3cc2014-06-18 15:06:01 -0700599 } else if (strcmp(cp, "-feature-of") == 0) {
600 argc--;
601 argv++;
602 if (!argc) {
603 fprintf(stderr, "ERROR: No argument supplied for '--feature-of' option\n");
604 wantUsage = true;
605 goto bail;
606 }
607 bundle.setFeatureOfPackage(argv[0]);
608 } else if (strcmp(cp, "-feature-after") == 0) {
609 argc--;
610 argv++;
611 if (!argc) {
612 fprintf(stderr, "ERROR: No argument supplied for '--feature-after' option\n");
613 wantUsage = true;
614 goto bail;
615 }
616 bundle.setFeatureAfterPackage(argv[0]);
Adam Lesinski282e1812014-01-23 18:17:42 -0800617 } else if (strcmp(cp, "-rename-manifest-package") == 0) {
618 argc--;
619 argv++;
620 if (!argc) {
621 fprintf(stderr, "ERROR: No argument supplied for '--rename-manifest-package' option\n");
622 wantUsage = true;
623 goto bail;
624 }
625 bundle.setManifestPackageNameOverride(argv[0]);
626 } else if (strcmp(cp, "-rename-instrumentation-target-package") == 0) {
627 argc--;
628 argv++;
629 if (!argc) {
630 fprintf(stderr, "ERROR: No argument supplied for '--rename-instrumentation-target-package' option\n");
631 wantUsage = true;
632 goto bail;
633 }
634 bundle.setInstrumentationPackageNameOverride(argv[0]);
635 } else if (strcmp(cp, "-auto-add-overlay") == 0) {
636 bundle.setAutoAddOverlay(true);
637 } else if (strcmp(cp, "-error-on-failed-insert") == 0) {
638 bundle.setErrorOnFailedInsert(true);
Ying Wangcd28bd32013-11-14 17:12:10 -0800639 } else if (strcmp(cp, "-error-on-missing-config-entry") == 0) {
640 bundle.setErrorOnMissingConfigEntry(true);
Adam Lesinski282e1812014-01-23 18:17:42 -0800641 } else if (strcmp(cp, "-output-text-symbols") == 0) {
642 argc--;
643 argv++;
644 if (!argc) {
645 fprintf(stderr, "ERROR: No argument supplied for '-output-text-symbols' option\n");
646 wantUsage = true;
647 goto bail;
648 }
649 bundle.setOutputTextSymbols(argv[0]);
650 } else if (strcmp(cp, "-product") == 0) {
651 argc--;
652 argv++;
653 if (!argc) {
654 fprintf(stderr, "ERROR: No argument supplied for '--product' option\n");
655 wantUsage = true;
656 goto bail;
657 }
658 bundle.setProduct(argv[0]);
659 } else if (strcmp(cp, "-non-constant-id") == 0) {
660 bundle.setNonConstantId(true);
Adam Lesinskide898ff2014-01-29 18:20:45 -0800661 } else if (strcmp(cp, "-shared-lib") == 0) {
662 bundle.setNonConstantId(true);
663 bundle.setBuildSharedLibrary(true);
Adam Lesinski282e1812014-01-23 18:17:42 -0800664 } else if (strcmp(cp, "-no-crunch") == 0) {
665 bundle.setUseCrunchCache(true);
666 } else if (strcmp(cp, "-ignore-assets") == 0) {
667 argc--;
668 argv++;
669 if (!argc) {
670 fprintf(stderr, "ERROR: No argument supplied for '--ignore-assets' option\n");
671 wantUsage = true;
672 goto bail;
673 }
674 gUserIgnoreAssets = argv[0];
Igor Viarheichyka191d042014-06-02 17:16:24 -0700675 } else if (strcmp(cp, "-pseudo-localize") == 0) {
676 bundle.setPseudolocalize(PSEUDO_ACCENTED | PSEUDO_BIDI);
Adam Lesinski282e1812014-01-23 18:17:42 -0800677 } else {
678 fprintf(stderr, "ERROR: Unknown option '-%s'\n", cp);
679 wantUsage = true;
680 goto bail;
681 }
682 cp += strlen(cp) - 1;
683 break;
684 default:
685 fprintf(stderr, "ERROR: Unknown flag '-%c'\n", *cp);
686 wantUsage = true;
687 goto bail;
688 }
689
690 cp++;
691 }
692 argc--;
693 argv++;
694 }
695
696 /*
697 * We're past the flags. The rest all goes straight in.
698 */
699 bundle.setFileSpec(argv, argc);
700
701 result = handleCommand(&bundle);
702
703bail:
704 if (wantUsage) {
705 usage();
706 result = 2;
707 }
708
709 //printf("--> returning %d\n", result);
710 return result;
711}