]>
git.saurik.com Git - android/aapt.git/blob - Main.cpp
6ff82690105d8876261418d6e740f775515f5f51
2 // Copyright 2006 The Android Open Source Project
4 // Android Asset Packaging Tool main entry point.
10 #include <utils/threads.h>
11 #include <utils/List.h>
12 #include <utils/Errors.h>
13 #include <utils/ZipFile.h>
19 using namespace android
;
21 static const char* gProgName
= "aapt";
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.
28 * This operates in-place on the path string.
30 void convertPath(char *path
) {
31 if (path
!= NULL
&& OS_PATH_SEPARATOR
!= '/') {
32 for (; *path
; path
++) {
34 *path
= OS_PATH_SEPARATOR
;
45 fprintf(stderr
, "Android Asset Packaging Tool\n\n");
46 fprintf(stderr
, "Usage:\n");
48 " %s l[ist] [-v] [-a] file.{zip,jar,apk}\n"
49 " List contents of Zip-compatible archive.\n\n", gProgName
);
51 " %s d[ump] WHAT file.{apk} [asset [asset ...]]\n"
52 " 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
);
59 " %s p[ackage] [-d][-f][-m][-u][-v][-x][-z][-M AndroidManifest.xml] \\\n"
60 " [-0 extension [-0 extension ...]] [-g tolerance] [-j jarfile] \\\n"
61 " [--min-sdk-version VAL] [--target-sdk-version VAL] \\\n"
62 " [--max-sdk-version VAL] [--app-version VAL] \\\n"
63 " [--app-version-name TEXT] \\\n"
64 " [-I base-package [-I base-package ...]] \\\n"
65 " [-A asset-source-dir] [-P public-definitions-file] \\\n"
66 " [-S resource-sources [-S resource-sources ...]] "
67 " [-F apk-file] [-J R-file-dir] \\\n"
68 " [raw-files-dir [raw-files-dir] ...]\n"
70 " Package the android resources. It will read assets and resources that are\n"
71 " supplied with the -M -A -S or raw-files-dir arguments. The -J -P -F and -R\n"
72 " options control which files are output.\n\n"
75 " %s r[emove] [-v] file.{zip,jar,apk} file1 [file2 ...]\n"
76 " Delete specified files from Zip-compatible archive.\n\n",
79 " %s a[dd] [-v] file.{zip,jar,apk} file1 [file2 ...]\n"
80 " Add specified files to Zip-compatible archive.\n\n", gProgName
);
83 " Print program version.\n\n", gProgName
);
86 " -a print Android-specific data (resources, manifest) when listing\n"
87 " -c specify which configurations to include. The default is all\n"
88 " configurations. The value of the parameter should be a comma\n"
89 " separated list of configuration values. Locales should be specified\n"
90 " as either a language or language-region pair. Some examples:\n"
94 " If you put the special locale, zz_ZZ on the list, it will perform\n"
95 " pseudolocalization on the default locale, modifying all of the\n"
96 " strings so you can look for strings that missed the\n"
97 " internationalization process. For example:\n"
99 " -d one or more device assets to include, separated by commas\n"
100 " -f force overwrite of existing files\n"
101 " -g specify a pixel tolerance to force images to grayscale, default 0\n"
102 " -j specify a jar or zip file containing classes to include\n"
103 " -m make package directories under location specified by -J\n"
105 " -p pseudolocalize the default configuration\n"
107 " -u update existing packages (add new, replace older, remove deleted files)\n"
108 " -v verbose output\n"
109 " -x create extending (non-application) resource IDs\n"
110 " -z require localization of resource attributes marked with\n"
111 " localization=\"suggested\"\n"
112 " -A additional directory in which to find raw asset files\n"
113 " -F specify the apk file to output\n"
114 " -I add an existing package to base include set\n"
115 " -J specify where to output R.java resource constant definitions\n"
116 " -M specify full path to AndroidManifest.xml to include in zip\n"
117 " -P specify where to output public resource definitions\n"
118 " -S directory in which to find resources. Multiple directories will be scanned"
119 " and the first match found (left to right) will take precedence."
120 " -0 specifies an additional extension for which such files will not\n"
121 " be stored compressed in the .apk. An empty string means to not\n"
122 " compress any files at all.\n"
123 " --min-sdk-version\n"
124 " inserts android:minSdkVersion in to manifest.\n"
125 " --target-sdk-version\n"
126 " inserts android:targetSdkVersion in to manifest.\n"
127 " --max-sdk-version\n"
128 " inserts android:maxSdkVersion in to manifest.\n"
130 " inserts android:versionCode in to manifest.\n"
132 " inserts android:versionName in to manifest.\n");
136 * Dispatch the command.
138 int handleCommand(Bundle
* bundle
)
140 //printf("--- command %d (verbose=%d force=%d):\n",
141 // bundle->getCommand(), bundle->getVerbose(), bundle->getForce());
142 //for (int i = 0; i < bundle->getFileSpecCount(); i++)
143 // printf(" %d: '%s'\n", i, bundle->getFileSpecEntry(i));
145 switch (bundle
->getCommand()) {
146 case kCommandVersion
: return doVersion(bundle
);
147 case kCommandList
: return doList(bundle
);
148 case kCommandDump
: return doDump(bundle
);
149 case kCommandAdd
: return doAdd(bundle
);
150 case kCommandRemove
: return doRemove(bundle
);
151 case kCommandPackage
: return doPackage(bundle
);
153 fprintf(stderr
, "%s: requested command not yet supported\n", gProgName
);
161 int main(int argc
, char* const argv
[])
163 char *prog
= argv
[0];
165 bool wantUsage
= false;
166 int result
= 1; // pessimistically assume an error.
169 /* default to compression */
170 bundle
.setCompressionMethod(ZipEntry::kCompressDeflated
);
177 if (argv
[1][0] == 'v')
178 bundle
.setCommand(kCommandVersion
);
179 else if (argv
[1][0] == 'd')
180 bundle
.setCommand(kCommandDump
);
181 else if (argv
[1][0] == 'l')
182 bundle
.setCommand(kCommandList
);
183 else if (argv
[1][0] == 'a')
184 bundle
.setCommand(kCommandAdd
);
185 else if (argv
[1][0] == 'r')
186 bundle
.setCommand(kCommandRemove
);
187 else if (argv
[1][0] == 'p')
188 bundle
.setCommand(kCommandPackage
);
190 fprintf(stderr
, "ERROR: Unknown command '%s'\n", argv
[1]);
198 * Pull out flags. We support "-fv" and "-f -v".
200 while (argc
&& argv
[0][0] == '-') {
202 const char* cp
= argv
[0] +1;
204 while (*cp
!= '\0') {
207 bundle
.setVerbose(true);
210 bundle
.setAndroidList(true);
216 fprintf(stderr
, "ERROR: No argument supplied for '-c' option\n");
220 bundle
.addConfigurations(argv
[0]);
223 bundle
.setForce(true);
229 fprintf(stderr
, "ERROR: No argument supplied for '-g' option\n");
233 tolerance
= atoi(argv
[0]);
234 bundle
.setGrayscaleTolerance(tolerance
);
235 printf("%s: Images with deviation <= %d will be forced to grayscale.\n", prog
, tolerance
);
238 bundle
.setMakePackageDirs(true);
242 bundle
.setPseudolocalize(true);
246 bundle
.setUpdate(true);
249 bundle
.setExtending(true);
252 bundle
.setRequireLocalization(true);
258 fprintf(stderr
, "ERROR: No argument supplied for '-j' option\n");
262 convertPath(argv
[0]);
263 bundle
.addJarFile(argv
[0]);
269 fprintf(stderr
, "ERROR: No argument supplied for '-A' option\n");
273 convertPath(argv
[0]);
274 bundle
.setAssetSourceDir(argv
[0]);
280 fprintf(stderr
, "ERROR: No argument supplied for '-I' option\n");
284 convertPath(argv
[0]);
285 bundle
.addPackageInclude(argv
[0]);
291 fprintf(stderr
, "ERROR: No argument supplied for '-F' option\n");
295 convertPath(argv
[0]);
296 bundle
.setOutputAPKFile(argv
[0]);
302 fprintf(stderr
, "ERROR: No argument supplied for '-J' option\n");
306 convertPath(argv
[0]);
307 bundle
.setRClassDir(argv
[0]);
313 fprintf(stderr
, "ERROR: No argument supplied for '-M' option\n");
317 convertPath(argv
[0]);
318 bundle
.setAndroidManifestFile(argv
[0]);
324 fprintf(stderr
, "ERROR: No argument supplied for '-P' option\n");
328 convertPath(argv
[0]);
329 bundle
.setPublicOutputFile(argv
[0]);
335 fprintf(stderr
, "ERROR: No argument supplied for '-S' option\n");
339 convertPath(argv
[0]);
340 bundle
.addResourceSourceDir(argv
[0]);
346 fprintf(stderr
, "ERROR: No argument supplied for '-e' option\n");
350 if (argv
[0][0] != 0) {
351 bundle
.addNoCompressExtension(argv
[0]);
353 bundle
.setCompressionMethod(ZipEntry::kCompressStored
);
357 if (strcmp(cp
, "-min-sdk-version") == 0) {
361 fprintf(stderr
, "ERROR: No argument supplied for '--min-sdk-version' option\n");
365 bundle
.setMinSdkVersion(argv
[0]);
366 } else if (strcmp(cp
, "-target-sdk-version") == 0) {
370 fprintf(stderr
, "ERROR: No argument supplied for '--target-sdk-version' option\n");
374 bundle
.setTargetSdkVersion(argv
[0]);
375 } else if (strcmp(cp
, "-max-sdk-version") == 0) {
379 fprintf(stderr
, "ERROR: No argument supplied for '--max-sdk-version' option\n");
383 bundle
.setMaxSdkVersion(argv
[0]);
384 } else if (strcmp(cp
, "-version-code") == 0) {
388 fprintf(stderr
, "ERROR: No argument supplied for '--version-code' option\n");
392 bundle
.setVersionCode(argv
[0]);
393 } else if (strcmp(cp
, "-version-name") == 0) {
397 fprintf(stderr
, "ERROR: No argument supplied for '--version-name' option\n");
401 bundle
.setVersionName(argv
[0]);
403 fprintf(stderr
, "ERROR: Unknown option '-%s'\n", cp
);
407 cp
+= strlen(cp
) - 1;
410 fprintf(stderr
, "ERROR: Unknown flag '-%c'\n", *cp
);
422 * We're past the flags. The rest all goes straight in.
424 bundle
.setFileSpec(argv
, argc
);
426 result
= handleCommand(&bundle
);
434 //printf("--> returning %d\n", result);