blob: 977226b61471d3cccdabf668e9756013ebf81575 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -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
Mathias Agopian3b4062e2009-05-31 19:13:00 -07009#include <utils/Log.h>
10#include <utils/threads.h>
11#include <utils/List.h>
12#include <utils/Errors.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080013
14#include <stdlib.h>
15#include <getopt.h>
16#include <assert.h>
17
18using namespace android;
19
20static const char* gProgName = "aapt";
21
22/*
23 * When running under Cygwin on Windows, this will convert slash-based
24 * paths into back-slash-based ones. Otherwise the ApptAssets file comparisons
25 * fail later as they use back-slash separators under Windows.
26 *
27 * This operates in-place on the path string.
28 */
29void convertPath(char *path) {
30 if (path != NULL && OS_PATH_SEPARATOR != '/') {
31 for (; *path; path++) {
32 if (*path == '/') {
33 *path = OS_PATH_SEPARATOR;
34 }
35 }
36 }
37}
38
39/*
40 * Print usage info.
41 */
42void usage(void)
43{
44 fprintf(stderr, "Android Asset Packaging Tool\n\n");
45 fprintf(stderr, "Usage:\n");
46 fprintf(stderr,
47 " %s l[ist] [-v] [-a] file.{zip,jar,apk}\n"
48 " List contents of Zip-compatible archive.\n\n", gProgName);
49 fprintf(stderr,
Dianne Hackborne17086b2009-06-19 15:13:28 -070050 " %s d[ump] [--values] WHAT file.{apk} [asset [asset ...]]\n"
MÃ¥rten Kongstad08822df2012-12-20 10:08:54 +010051 " strings Print the contents of the resource table string pool in the APK.\n"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080052 " badging Print the label and icon for the app declared in APK.\n"
53 " permissions Print the permissions from the APK.\n"
54 " resources Print the resource table from the APK.\n"
55 " configurations Print the configurations in the APK.\n"
56 " xmltree Print the compiled xmls in the given assets.\n"
57 " xmlstrings Print the strings of the given compiled xml assets.\n\n", gProgName);
58 fprintf(stderr,
59 " %s p[ackage] [-d][-f][-m][-u][-v][-x][-z][-M AndroidManifest.xml] \\\n"
Dianne Hackborn62da8462009-05-13 15:06:13 -070060 " [-0 extension [-0 extension ...]] [-g tolerance] [-j jarfile] \\\n"
Xavier Ducrohet6487b092010-08-31 10:45:31 -070061 " [--debug-mode] [--min-sdk-version VAL] [--target-sdk-version VAL] \\\n"
Dianne Hackbornef05e072010-03-01 17:43:39 -080062 " [--app-version VAL] [--app-version-name TEXT] [--custom-package VAL] \\\n"
63 " [--rename-manifest-package PACKAGE] \\\n"
64 " [--rename-instrumentation-target-package PACKAGE] \\\n"
65 " [--utf16] [--auto-add-overlay] \\\n"
Ficus Kirkpatrick588f2282010-08-13 14:13:08 -070066 " [--max-res-version VAL] \\\n"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067 " [-I base-package [-I base-package ...]] \\\n"
Joe Onorato1553c822009-08-30 13:36:22 -070068 " [-A asset-source-dir] [-G class-list-file] [-P public-definitions-file] \\\n"
Dianne Hackborne6b68032011-10-13 16:26:02 -070069 " [-S resource-sources [-S resource-sources ...]] \\\n"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080070 " [-F apk-file] [-J R-file-dir] \\\n"
Eric Fischer90964042010-09-15 15:59:21 -070071 " [--product product1,product2,...] \\\n"
Dianne Hackborne6b68032011-10-13 16:26:02 -070072 " [-c CONFIGS] [--preferred-configurations CONFIGS] \\\n"
Xavier Ducrohetf5de6502012-09-11 14:45:22 -070073 " [raw-files-dir [raw-files-dir] ...] \\\n"
74 " [--output-text-symbols DIR]\n"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080075 "\n"
76 " Package the android resources. It will read assets and resources that are\n"
77 " supplied with the -M -A -S or raw-files-dir arguments. The -J -P -F and -R\n"
78 " options control which files are output.\n\n"
79 , gProgName);
80 fprintf(stderr,
81 " %s r[emove] [-v] file.{zip,jar,apk} file1 [file2 ...]\n"
82 " Delete specified files from Zip-compatible archive.\n\n",
83 gProgName);
84 fprintf(stderr,
85 " %s a[dd] [-v] file.{zip,jar,apk} file1 [file2 ...]\n"
86 " Add specified files to Zip-compatible archive.\n\n", gProgName);
87 fprintf(stderr,
Josiah Gaskin8a39da82011-06-06 17:00:35 -070088 " %s c[runch] [-v] -S resource-sources ... -C output-folder ...\n"
Xavier Ducrohetb1f6ad82012-12-21 09:54:02 -080089 " Do PNG preprocessing on one or several resource folders\n"
90 " and store the results in the output folder.\n\n", gProgName);
91 fprintf(stderr,
92 " %s s[ingleCrunch] [-v] -i input-file -o outputfile\n"
93 " Do PNG preprocessing on a single file.\n\n", gProgName);
Josiah Gaskin8a39da82011-06-06 17:00:35 -070094 fprintf(stderr,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080095 " %s v[ersion]\n"
96 " Print program version.\n\n", gProgName);
97 fprintf(stderr,
98 " Modifiers:\n"
99 " -a print Android-specific data (resources, manifest) when listing\n"
100 " -c specify which configurations to include. The default is all\n"
101 " configurations. The value of the parameter should be a comma\n"
102 " separated list of configuration values. Locales should be specified\n"
103 " as either a language or language-region pair. Some examples:\n"
104 " en\n"
105 " port,en\n"
106 " port,land,en_US\n"
107 " If you put the special locale, zz_ZZ on the list, it will perform\n"
108 " pseudolocalization on the default locale, modifying all of the\n"
109 " strings so you can look for strings that missed the\n"
110 " internationalization process. For example:\n"
111 " port,land,zz_ZZ\n"
112 " -d one or more device assets to include, separated by commas\n"
113 " -f force overwrite of existing files\n"
114 " -g specify a pixel tolerance to force images to grayscale, default 0\n"
115 " -j specify a jar or zip file containing classes to include\n"
Doug Zongkerdbe7a682009-10-09 11:24:51 -0700116 " -k junk path of file(s) added\n"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800117 " -m make package directories under location specified by -J\n"
118#if 0
119 " -p pseudolocalize the default configuration\n"
120#endif
121 " -u update existing packages (add new, replace older, remove deleted files)\n"
122 " -v verbose output\n"
123 " -x create extending (non-application) resource IDs\n"
124 " -z require localization of resource attributes marked with\n"
125 " localization=\"suggested\"\n"
126 " -A additional directory in which to find raw asset files\n"
Joe Onorato1553c822009-08-30 13:36:22 -0700127 " -G A file to output proguard options into.\n"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800128 " -F specify the apk file to output\n"
129 " -I add an existing package to base include set\n"
130 " -J specify where to output R.java resource constant definitions\n"
131 " -M specify full path to AndroidManifest.xml to include in zip\n"
132 " -P specify where to output public resource definitions\n"
Xavier Ducrohet63459ad2009-11-30 18:05:10 -0800133 " -S directory in which to find resources. Multiple directories will be scanned\n"
134 " and the first match found (left to right) will take precedence.\n"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800135 " -0 specifies an additional extension for which such files will not\n"
136 " be stored compressed in the .apk. An empty string means to not\n"
Dianne Hackborn62da8462009-05-13 15:06:13 -0700137 " compress any files at all.\n"
Xavier Ducrohet6487b092010-08-31 10:45:31 -0700138 " --debug-mode\n"
139 " inserts android:debuggable=\"true\" in to the application node of the\n"
140 " manifest, making the application debuggable even on production devices.\n"
Dianne Hackborn62da8462009-05-13 15:06:13 -0700141 " --min-sdk-version\n"
Kenny Root745e17a2009-12-11 08:15:16 -0800142 " inserts android:minSdkVersion in to manifest. If the version is 7 or\n"
143 " higher, the default encoding for resources will be in UTF-8.\n"
Dianne Hackborn62da8462009-05-13 15:06:13 -0700144 " --target-sdk-version\n"
145 " inserts android:targetSdkVersion in to manifest.\n"
Ficus Kirkpatrick588f2282010-08-13 14:13:08 -0700146 " --max-res-version\n"
147 " ignores versioned resource directories above the given value.\n"
Dianne Hackborne17086b2009-06-19 15:13:28 -0700148 " --values\n"
149 " when used with \"dump resources\" also includes resource values.\n"
Dianne Hackborn62da8462009-05-13 15:06:13 -0700150 " --version-code\n"
151 " inserts android:versionCode in to manifest.\n"
152 " --version-name\n"
Xavier Ducrohet63459ad2009-11-30 18:05:10 -0800153 " inserts android:versionName in to manifest.\n"
154 " --custom-package\n"
Kenny Root745e17a2009-12-11 08:15:16 -0800155 " generates R.java into a different package.\n"
Josiah Gaskince89f152011-06-08 19:31:40 -0700156 " --extra-packages\n"
Josiah Gaskin9bf34ca2011-06-14 13:57:09 -0700157 " generate R.java for libraries. Separate libraries with ':'.\n"
158 " --generate-dependencies\n"
Josiah Gaskin03589cc2011-06-27 16:26:02 -0700159 " generate dependency files in the same directories for R.java and resource package\n"
Xavier Ducrohet99080c72010-02-04 18:45:31 -0800160 " --auto-add-overlay\n"
161 " Automatically add resources that are only in overlays.\n"
Dianne Hackborne6b68032011-10-13 16:26:02 -0700162 " --preferred-configurations\n"
163 " Like the -c option for filtering out unneeded configurations, but\n"
164 " only expresses a preference. If there is no resource available with\n"
165 " the preferred configuration then it will not be stripped.\n"
Dianne Hackbornef05e072010-03-01 17:43:39 -0800166 " --rename-manifest-package\n"
167 " Rewrite the manifest so that its package name is the package name\n"
168 " given here. Relative class names (for example .Foo) will be\n"
169 " changed to absolute names with the old package so that the code\n"
170 " does not need to change.\n"
171 " --rename-instrumentation-target-package\n"
172 " Rewrite the manifest so that all of its instrumentation\n"
173 " components target the given package. Useful when used in\n"
174 " conjunction with --rename-manifest-package to fix tests against\n"
175 " a package that has been renamed.\n"
Eric Fischer90964042010-09-15 15:59:21 -0700176 " --product\n"
177 " Specifies which variant to choose for strings that have\n"
178 " product variants\n"
Kenny Root745e17a2009-12-11 08:15:16 -0800179 " --utf16\n"
180 " changes default encoding for resources to UTF-16. Only useful when API\n"
Xavier Ducrohetd06c1af2011-02-14 16:58:00 -0800181 " level is set to 7 or higher where the default encoding is UTF-8.\n"
182 " --non-constant-id\n"
183 " Make the resources ID non constant. This is required to make an R java class\n"
184 " that does not contain the final value but is used to make reusable compiled\n"
Raphael Moll90897ed2012-05-07 16:16:46 -0700185 " libraries that need to access resources.\n"
Xavier Ducrohet7714a242012-09-05 17:49:21 -0700186 " --error-on-failed-insert\n"
187 " Forces aapt to return an error if it fails to insert values into the manifest\n"
188 " with --debug-mode, --min-sdk-version, --target-sdk-version --version-code\n"
189 " and --version-name.\n"
190 " Insertion typically fails if the manifest already defines the attribute.\n"
Xavier Ducrohetf5de6502012-09-11 14:45:22 -0700191 " --output-text-symbols\n"
192 " Generates a text file containing the resource symbols of the R class in the\n"
193 " specified folder.\n"
Raphael Moll90897ed2012-05-07 16:16:46 -0700194 " --ignore-assets\n"
195 " Assets to be ignored. Default pattern is:\n"
196 " %s\n",
197 gDefaultIgnoreAssets);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800198}
199
200/*
201 * Dispatch the command.
202 */
203int handleCommand(Bundle* bundle)
204{
205 //printf("--- command %d (verbose=%d force=%d):\n",
206 // bundle->getCommand(), bundle->getVerbose(), bundle->getForce());
207 //for (int i = 0; i < bundle->getFileSpecCount(); i++)
208 // printf(" %d: '%s'\n", i, bundle->getFileSpecEntry(i));
209
210 switch (bundle->getCommand()) {
Xavier Ducrohetb1f6ad82012-12-21 09:54:02 -0800211 case kCommandVersion: return doVersion(bundle);
212 case kCommandList: return doList(bundle);
213 case kCommandDump: return doDump(bundle);
214 case kCommandAdd: return doAdd(bundle);
215 case kCommandRemove: return doRemove(bundle);
216 case kCommandPackage: return doPackage(bundle);
217 case kCommandCrunch: return doCrunch(bundle);
218 case kCommandSingleCrunch: return doSingleCrunch(bundle);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800219 default:
220 fprintf(stderr, "%s: requested command not yet supported\n", gProgName);
221 return 1;
222 }
223}
224
225/*
226 * Parse args.
227 */
228int main(int argc, char* const argv[])
229{
230 char *prog = argv[0];
231 Bundle bundle;
232 bool wantUsage = false;
233 int result = 1; // pessimistically assume an error.
234 int tolerance = 0;
235
236 /* default to compression */
237 bundle.setCompressionMethod(ZipEntry::kCompressDeflated);
238
239 if (argc < 2) {
240 wantUsage = true;
241 goto bail;
242 }
243
244 if (argv[1][0] == 'v')
245 bundle.setCommand(kCommandVersion);
246 else if (argv[1][0] == 'd')
247 bundle.setCommand(kCommandDump);
248 else if (argv[1][0] == 'l')
249 bundle.setCommand(kCommandList);
250 else if (argv[1][0] == 'a')
251 bundle.setCommand(kCommandAdd);
252 else if (argv[1][0] == 'r')
253 bundle.setCommand(kCommandRemove);
254 else if (argv[1][0] == 'p')
255 bundle.setCommand(kCommandPackage);
Josiah Gaskin8a39da82011-06-06 17:00:35 -0700256 else if (argv[1][0] == 'c')
257 bundle.setCommand(kCommandCrunch);
Xavier Ducrohetb1f6ad82012-12-21 09:54:02 -0800258 else if (argv[1][0] == 's')
259 bundle.setCommand(kCommandSingleCrunch);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800260 else {
261 fprintf(stderr, "ERROR: Unknown command '%s'\n", argv[1]);
262 wantUsage = true;
263 goto bail;
264 }
265 argc -= 2;
266 argv += 2;
267
268 /*
269 * Pull out flags. We support "-fv" and "-f -v".
270 */
271 while (argc && argv[0][0] == '-') {
272 /* flag(s) found */
273 const char* cp = argv[0] +1;
274
275 while (*cp != '\0') {
276 switch (*cp) {
277 case 'v':
278 bundle.setVerbose(true);
279 break;
280 case 'a':
281 bundle.setAndroidList(true);
282 break;
283 case 'c':
284 argc--;
285 argv++;
286 if (!argc) {
287 fprintf(stderr, "ERROR: No argument supplied for '-c' option\n");
288 wantUsage = true;
289 goto bail;
290 }
291 bundle.addConfigurations(argv[0]);
292 break;
293 case 'f':
294 bundle.setForce(true);
295 break;
296 case 'g':
297 argc--;
298 argv++;
299 if (!argc) {
300 fprintf(stderr, "ERROR: No argument supplied for '-g' option\n");
301 wantUsage = true;
302 goto bail;
303 }
304 tolerance = atoi(argv[0]);
305 bundle.setGrayscaleTolerance(tolerance);
306 printf("%s: Images with deviation <= %d will be forced to grayscale.\n", prog, tolerance);
307 break;
Doug Zongkerdbe7a682009-10-09 11:24:51 -0700308 case 'k':
309 bundle.setJunkPath(true);
310 break;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800311 case 'm':
312 bundle.setMakePackageDirs(true);
313 break;
314#if 0
315 case 'p':
316 bundle.setPseudolocalize(true);
317 break;
318#endif
319 case 'u':
320 bundle.setUpdate(true);
321 break;
322 case 'x':
323 bundle.setExtending(true);
324 break;
325 case 'z':
326 bundle.setRequireLocalization(true);
327 break;
328 case 'j':
329 argc--;
330 argv++;
331 if (!argc) {
332 fprintf(stderr, "ERROR: No argument supplied for '-j' option\n");
333 wantUsage = true;
334 goto bail;
335 }
336 convertPath(argv[0]);
337 bundle.addJarFile(argv[0]);
338 break;
339 case 'A':
340 argc--;
341 argv++;
342 if (!argc) {
343 fprintf(stderr, "ERROR: No argument supplied for '-A' option\n");
344 wantUsage = true;
345 goto bail;
346 }
347 convertPath(argv[0]);
348 bundle.setAssetSourceDir(argv[0]);
349 break;
Joe Onorato1553c822009-08-30 13:36:22 -0700350 case 'G':
351 argc--;
352 argv++;
353 if (!argc) {
354 fprintf(stderr, "ERROR: No argument supplied for '-G' option\n");
355 wantUsage = true;
356 goto bail;
357 }
358 convertPath(argv[0]);
359 bundle.setProguardFile(argv[0]);
360 break;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800361 case 'I':
362 argc--;
363 argv++;
364 if (!argc) {
365 fprintf(stderr, "ERROR: No argument supplied for '-I' option\n");
366 wantUsage = true;
367 goto bail;
368 }
369 convertPath(argv[0]);
370 bundle.addPackageInclude(argv[0]);
371 break;
372 case 'F':
373 argc--;
374 argv++;
375 if (!argc) {
376 fprintf(stderr, "ERROR: No argument supplied for '-F' option\n");
377 wantUsage = true;
378 goto bail;
379 }
380 convertPath(argv[0]);
381 bundle.setOutputAPKFile(argv[0]);
382 break;
383 case 'J':
384 argc--;
385 argv++;
386 if (!argc) {
387 fprintf(stderr, "ERROR: No argument supplied for '-J' option\n");
388 wantUsage = true;
389 goto bail;
390 }
391 convertPath(argv[0]);
392 bundle.setRClassDir(argv[0]);
393 break;
394 case 'M':
395 argc--;
396 argv++;
397 if (!argc) {
398 fprintf(stderr, "ERROR: No argument supplied for '-M' option\n");
399 wantUsage = true;
400 goto bail;
401 }
402 convertPath(argv[0]);
403 bundle.setAndroidManifestFile(argv[0]);
404 break;
405 case 'P':
406 argc--;
407 argv++;
408 if (!argc) {
409 fprintf(stderr, "ERROR: No argument supplied for '-P' option\n");
410 wantUsage = true;
411 goto bail;
412 }
413 convertPath(argv[0]);
414 bundle.setPublicOutputFile(argv[0]);
415 break;
416 case 'S':
417 argc--;
418 argv++;
419 if (!argc) {
420 fprintf(stderr, "ERROR: No argument supplied for '-S' option\n");
421 wantUsage = true;
422 goto bail;
423 }
424 convertPath(argv[0]);
425 bundle.addResourceSourceDir(argv[0]);
426 break;
Josiah Gaskin8a39da82011-06-06 17:00:35 -0700427 case 'C':
428 argc--;
429 argv++;
430 if (!argc) {
431 fprintf(stderr, "ERROR: No argument supplied for '-C' option\n");
432 wantUsage = true;
433 goto bail;
434 }
435 convertPath(argv[0]);
436 bundle.setCrunchedOutputDir(argv[0]);
437 break;
Xavier Ducrohetb1f6ad82012-12-21 09:54:02 -0800438 case 'i':
439 argc--;
440 argv++;
441 if (!argc) {
442 fprintf(stderr, "ERROR: No argument supplied for '-i' option\n");
443 wantUsage = true;
444 goto bail;
445 }
446 convertPath(argv[0]);
447 bundle.setSingleCrunchInputFile(argv[0]);
448 break;
449 case 'o':
450 argc--;
451 argv++;
452 if (!argc) {
453 fprintf(stderr, "ERROR: No argument supplied for '-o' option\n");
454 wantUsage = true;
455 goto bail;
456 }
457 convertPath(argv[0]);
458 bundle.setSingleCrunchOutputFile(argv[0]);
459 break;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800460 case '0':
461 argc--;
462 argv++;
463 if (!argc) {
464 fprintf(stderr, "ERROR: No argument supplied for '-e' option\n");
465 wantUsage = true;
466 goto bail;
467 }
468 if (argv[0][0] != 0) {
469 bundle.addNoCompressExtension(argv[0]);
470 } else {
471 bundle.setCompressionMethod(ZipEntry::kCompressStored);
472 }
473 break;
Dianne Hackborn62da8462009-05-13 15:06:13 -0700474 case '-':
Xavier Ducrohet6487b092010-08-31 10:45:31 -0700475 if (strcmp(cp, "-debug-mode") == 0) {
476 bundle.setDebugMode(true);
477 } else if (strcmp(cp, "-min-sdk-version") == 0) {
Dianne Hackborn62da8462009-05-13 15:06:13 -0700478 argc--;
479 argv++;
480 if (!argc) {
481 fprintf(stderr, "ERROR: No argument supplied for '--min-sdk-version' option\n");
482 wantUsage = true;
483 goto bail;
484 }
485 bundle.setMinSdkVersion(argv[0]);
486 } else if (strcmp(cp, "-target-sdk-version") == 0) {
487 argc--;
488 argv++;
489 if (!argc) {
490 fprintf(stderr, "ERROR: No argument supplied for '--target-sdk-version' option\n");
491 wantUsage = true;
492 goto bail;
493 }
494 bundle.setTargetSdkVersion(argv[0]);
495 } else if (strcmp(cp, "-max-sdk-version") == 0) {
496 argc--;
497 argv++;
498 if (!argc) {
499 fprintf(stderr, "ERROR: No argument supplied for '--max-sdk-version' option\n");
500 wantUsage = true;
501 goto bail;
502 }
503 bundle.setMaxSdkVersion(argv[0]);
Ficus Kirkpatrick588f2282010-08-13 14:13:08 -0700504 } else if (strcmp(cp, "-max-res-version") == 0) {
505 argc--;
506 argv++;
507 if (!argc) {
508 fprintf(stderr, "ERROR: No argument supplied for '--max-res-version' option\n");
509 wantUsage = true;
510 goto bail;
511 }
512 bundle.setMaxResVersion(argv[0]);
Dianne Hackborn62da8462009-05-13 15:06:13 -0700513 } else if (strcmp(cp, "-version-code") == 0) {
514 argc--;
515 argv++;
516 if (!argc) {
517 fprintf(stderr, "ERROR: No argument supplied for '--version-code' option\n");
518 wantUsage = true;
519 goto bail;
520 }
521 bundle.setVersionCode(argv[0]);
522 } else if (strcmp(cp, "-version-name") == 0) {
523 argc--;
524 argv++;
525 if (!argc) {
526 fprintf(stderr, "ERROR: No argument supplied for '--version-name' option\n");
527 wantUsage = true;
528 goto bail;
529 }
530 bundle.setVersionName(argv[0]);
Dianne Hackborne17086b2009-06-19 15:13:28 -0700531 } else if (strcmp(cp, "-values") == 0) {
532 bundle.setValues(true);
Xavier Ducrohet63459ad2009-11-30 18:05:10 -0800533 } else if (strcmp(cp, "-custom-package") == 0) {
534 argc--;
535 argv++;
536 if (!argc) {
537 fprintf(stderr, "ERROR: No argument supplied for '--custom-package' option\n");
538 wantUsage = true;
539 goto bail;
540 }
541 bundle.setCustomPackage(argv[0]);
Josiah Gaskince89f152011-06-08 19:31:40 -0700542 } else if (strcmp(cp, "-extra-packages") == 0) {
543 argc--;
544 argv++;
545 if (!argc) {
546 fprintf(stderr, "ERROR: No argument supplied for '--extra-packages' option\n");
547 wantUsage = true;
548 goto bail;
549 }
550 bundle.setExtraPackages(argv[0]);
Josiah Gaskin9bf34ca2011-06-14 13:57:09 -0700551 } else if (strcmp(cp, "-generate-dependencies") == 0) {
552 bundle.setGenDependencies(true);
Kenny Root745e17a2009-12-11 08:15:16 -0800553 } else if (strcmp(cp, "-utf16") == 0) {
Kenny Root1741cd42010-03-18 12:12:11 -0700554 bundle.setWantUTF16(true);
Dianne Hackborne6b68032011-10-13 16:26:02 -0700555 } else if (strcmp(cp, "-preferred-configurations") == 0) {
556 argc--;
557 argv++;
558 if (!argc) {
559 fprintf(stderr, "ERROR: No argument supplied for '--preferred-configurations' option\n");
560 wantUsage = true;
561 goto bail;
562 }
563 bundle.addPreferredConfigurations(argv[0]);
Jeff Hamilton2fee0ed2010-01-06 15:46:38 -0600564 } else if (strcmp(cp, "-rename-manifest-package") == 0) {
565 argc--;
566 argv++;
567 if (!argc) {
568 fprintf(stderr, "ERROR: No argument supplied for '--rename-manifest-package' option\n");
569 wantUsage = true;
570 goto bail;
571 }
572 bundle.setManifestPackageNameOverride(argv[0]);
Dianne Hackbornef05e072010-03-01 17:43:39 -0800573 } else if (strcmp(cp, "-rename-instrumentation-target-package") == 0) {
574 argc--;
575 argv++;
576 if (!argc) {
577 fprintf(stderr, "ERROR: No argument supplied for '--rename-instrumentation-target-package' option\n");
578 wantUsage = true;
579 goto bail;
580 }
581 bundle.setInstrumentationPackageNameOverride(argv[0]);
Xavier Ducrohet99080c72010-02-04 18:45:31 -0800582 } else if (strcmp(cp, "-auto-add-overlay") == 0) {
583 bundle.setAutoAddOverlay(true);
Xavier Ducrohet7714a242012-09-05 17:49:21 -0700584 } else if (strcmp(cp, "-error-on-failed-insert") == 0) {
585 bundle.setErrorOnFailedInsert(true);
Xavier Ducrohetf5de6502012-09-11 14:45:22 -0700586 } else if (strcmp(cp, "-output-text-symbols") == 0) {
587 argc--;
588 argv++;
589 if (!argc) {
590 fprintf(stderr, "ERROR: No argument supplied for '-output-text-symbols' option\n");
591 wantUsage = true;
592 goto bail;
593 }
594 bundle.setOutputTextSymbols(argv[0]);
Eric Fischer90964042010-09-15 15:59:21 -0700595 } else if (strcmp(cp, "-product") == 0) {
596 argc--;
597 argv++;
598 if (!argc) {
599 fprintf(stderr, "ERROR: No argument supplied for '--product' option\n");
600 wantUsage = true;
601 goto bail;
602 }
603 bundle.setProduct(argv[0]);
Xavier Ducrohetd06c1af2011-02-14 16:58:00 -0800604 } else if (strcmp(cp, "-non-constant-id") == 0) {
605 bundle.setNonConstantId(true);
Josiah Gaskin8a39da82011-06-06 17:00:35 -0700606 } else if (strcmp(cp, "-no-crunch") == 0) {
607 bundle.setUseCrunchCache(true);
Raphael Moll90897ed2012-05-07 16:16:46 -0700608 } else if (strcmp(cp, "-ignore-assets") == 0) {
609 argc--;
610 argv++;
611 if (!argc) {
612 fprintf(stderr, "ERROR: No argument supplied for '--ignore-assets' option\n");
613 wantUsage = true;
614 goto bail;
615 }
616 gUserIgnoreAssets = argv[0];
617 } else {
Dianne Hackborn62da8462009-05-13 15:06:13 -0700618 fprintf(stderr, "ERROR: Unknown option '-%s'\n", cp);
619 wantUsage = true;
620 goto bail;
621 }
622 cp += strlen(cp) - 1;
623 break;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800624 default:
625 fprintf(stderr, "ERROR: Unknown flag '-%c'\n", *cp);
626 wantUsage = true;
627 goto bail;
628 }
629
630 cp++;
631 }
632 argc--;
633 argv++;
634 }
635
636 /*
637 * We're past the flags. The rest all goes straight in.
638 */
639 bundle.setFileSpec(argv, argc);
640
641 result = handleCommand(&bundle);
642
643bail:
644 if (wantUsage) {
645 usage();
646 result = 2;
647 }
648
649 //printf("--> returning %d\n", result);
650 return result;
651}