]>
git.saurik.com Git - android/aapt.git/blob - Main.cpp
2 // Copyright 2006 The Android Open Source Project
4 // Android Asset Packaging Tool main entry point.
10 #include <utils/ZipFile.h>
16 using namespace android
;
18 static const char* gProgName
= "aapt";
21 * When running under Cygwin on Windows, this will convert slash-based
22 * paths into back-slash-based ones. Otherwise the ApptAssets file comparisons
23 * fail later as they use back-slash separators under Windows.
25 * This operates in-place on the path string.
27 void convertPath(char *path
) {
28 if (path
!= NULL
&& OS_PATH_SEPARATOR
!= '/') {
29 for (; *path
; path
++) {
31 *path
= OS_PATH_SEPARATOR
;
42 fprintf(stderr
, "Android Asset Packaging Tool\n\n");
43 fprintf(stderr
, "Usage:\n");
45 " %s l[ist] [-v] [-a] file.{zip,jar,apk}\n"
46 " List contents of Zip-compatible archive.\n\n", gProgName
);
48 " %s d[ump] WHAT file.{apk} [asset [asset ...]]\n"
49 " badging Print the label and icon for the app declared in APK.\n"
50 " permissions Print the permissions from the APK.\n"
51 " resources Print the resource table from the APK.\n"
52 " configurations Print the configurations in the APK.\n"
53 " xmltree Print the compiled xmls in the given assets.\n"
54 " xmlstrings Print the strings of the given compiled xml assets.\n\n", gProgName
);
56 " %s p[ackage] [-f][-u][-m][-v][-x][-M AndroidManifest.xml] \\\n"
57 " [-0 extension [-0 extension ...]] \\\n"
58 " [-I base-package [-I base-package ...]] \\\n"
59 " [-A asset-source-dir] [-P public-definitions-file] \\\n"
60 " [-S resource-sources] [-F apk-file] [-J R-file-dir] \\\n"
61 " [raw-files-dir [raw-files-dir] ...]\n"
63 " Package the android resources. It will read assets and resources that are\n"
64 " supplied with the -M -A -S or raw-files-dir arguments. The -J -P -F and -R\n"
65 " options control which files are output.\n\n"
68 " %s r[emove] [-v] file.{zip,jar,apk} file1 [file2 ...]\n"
69 " Delete specified files from Zip-compatible archive.\n\n",
72 " %s a[dd] [-v] file.{zip,jar,apk} file1 [file2 ...]\n"
73 " Add specified files to Zip-compatible archive.\n\n", gProgName
);
76 " Print program version.\n\n", gProgName
);
79 " -a print Android-specific data (resources, manifest) when listing\n"
80 " -c specify which configurations to include. The default is all\n"
81 " configurations. The value of the parameter should be a comma\n"
82 " separated list of configuration values. Locales should be specified\n"
83 " as either a language or language-region pair. Some examples:\n"
87 " If you put the special locale, zz_ZZ on the list, it will perform\n"
88 " pseudolocalization on the default locale, modifying all of the\n"
89 " strings so you can look for strings that missed the\n"
90 " internationalization process. For example:\n"
92 " -d one or more device assets to include, separated by commas\n"
93 " -f force overwrite of existing files\n"
94 " -j specify a jar or zip file containing classes to include\n"
95 " -m make package directories under location specified by -J\n"
97 " -p pseudolocalize the default configuration\n"
99 " -u update existing packages (add new, replace older, remove deleted files)\n"
100 " -v verbose output\n"
101 " -x create extending (non-application) resource IDs\n"
102 " -z require localization of resource attributes marked with\n"
103 " localization=\"suggested\"\n"
104 " -A additional directory in which to find raw asset files\n"
105 " -F specify the apk file to output\n"
106 " -I add an existing package to base include set\n"
107 " -J specify where to output R.java resource constant definitions\n"
108 " -M specify full path to AndroidManifest.xml to include in zip\n"
109 " -P specify where to output public resource definitions\n"
110 " -S directory in which to find resources\n"
111 " -0 specifies an additional extension for which such files will not\n"
112 " be stored compressed in the .apk. An empty string means to not\n"
113 " compress any files at all.\n");
117 * Dispatch the command.
119 int handleCommand(Bundle
* bundle
)
121 //printf("--- command %d (verbose=%d force=%d):\n",
122 // bundle->getCommand(), bundle->getVerbose(), bundle->getForce());
123 //for (int i = 0; i < bundle->getFileSpecCount(); i++)
124 // printf(" %d: '%s'\n", i, bundle->getFileSpecEntry(i));
126 switch (bundle
->getCommand()) {
127 case kCommandVersion
: return doVersion(bundle
);
128 case kCommandList
: return doList(bundle
);
129 case kCommandDump
: return doDump(bundle
);
130 case kCommandAdd
: return doAdd(bundle
);
131 case kCommandRemove
: return doRemove(bundle
);
132 case kCommandPackage
: return doPackage(bundle
);
134 fprintf(stderr
, "%s: requested command not yet supported\n", gProgName
);
142 int main(int argc
, char* const argv
[])
145 bool wantUsage
= false;
146 int result
= 1; // pessimistically assume an error.
148 /* default to compression */
149 bundle
.setCompressionMethod(ZipEntry::kCompressDeflated
);
156 if (argv
[1][0] == 'v')
157 bundle
.setCommand(kCommandVersion
);
158 else if (argv
[1][0] == 'd')
159 bundle
.setCommand(kCommandDump
);
160 else if (argv
[1][0] == 'l')
161 bundle
.setCommand(kCommandList
);
162 else if (argv
[1][0] == 'a')
163 bundle
.setCommand(kCommandAdd
);
164 else if (argv
[1][0] == 'r')
165 bundle
.setCommand(kCommandRemove
);
166 else if (argv
[1][0] == 'p')
167 bundle
.setCommand(kCommandPackage
);
169 fprintf(stderr
, "ERROR: Unknown command '%s'\n", argv
[1]);
177 * Pull out flags. We support "-fv" and "-f -v".
179 while (argc
&& argv
[0][0] == '-') {
181 const char* cp
= argv
[0] +1;
183 while (*cp
!= '\0') {
186 bundle
.setVerbose(true);
189 bundle
.setAndroidList(true);
195 fprintf(stderr
, "ERROR: No argument supplied for '-c' option\n");
199 bundle
.addConfigurations(argv
[0]);
202 bundle
.setForce(true);
205 bundle
.setMakePackageDirs(true);
209 bundle
.setPseudolocalize(true);
213 bundle
.setUpdate(true);
216 bundle
.setExtending(true);
219 bundle
.setRequireLocalization(true);
225 fprintf(stderr
, "ERROR: No argument supplied for '-j' option\n");
229 convertPath(argv
[0]);
230 bundle
.addJarFile(argv
[0]);
236 fprintf(stderr
, "ERROR: No argument supplied for '-A' option\n");
240 convertPath(argv
[0]);
241 bundle
.setAssetSourceDir(argv
[0]);
247 fprintf(stderr
, "ERROR: No argument supplied for '-I' option\n");
251 convertPath(argv
[0]);
252 bundle
.addPackageInclude(argv
[0]);
258 fprintf(stderr
, "ERROR: No argument supplied for '-F' option\n");
262 convertPath(argv
[0]);
263 bundle
.setOutputAPKFile(argv
[0]);
269 fprintf(stderr
, "ERROR: No argument supplied for '-J' option\n");
273 convertPath(argv
[0]);
274 bundle
.setRClassDir(argv
[0]);
280 fprintf(stderr
, "ERROR: No argument supplied for '-M' option\n");
284 convertPath(argv
[0]);
285 bundle
.setAndroidManifestFile(argv
[0]);
291 fprintf(stderr
, "ERROR: No argument supplied for '-P' option\n");
295 convertPath(argv
[0]);
296 bundle
.setPublicOutputFile(argv
[0]);
302 fprintf(stderr
, "ERROR: No argument supplied for '-S' option\n");
306 convertPath(argv
[0]);
307 bundle
.setResourceSourceDir(argv
[0]);
313 fprintf(stderr
, "ERROR: No argument supplied for '-e' option\n");
317 if (argv
[0][0] != 0) {
318 bundle
.addNoCompressExtension(argv
[0]);
320 bundle
.setCompressionMethod(ZipEntry::kCompressStored
);
324 fprintf(stderr
, "ERROR: Unknown flag '-%c'\n", *cp
);
336 * We're past the flags. The rest all goes straight in.
338 bundle
.setFileSpec(argv
, argc
);
340 result
= handleCommand(&bundle
);
348 //printf("--> returning %d\n", result);