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