]>
git.saurik.com Git - android/aapt.git/blob - Main.cpp
d86ad47ea47b0f60dfae4dd9c310a5b2cfbe01c7
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 " permissions Print the permissions from the APK.\n"
50 " resources Print the resource table from the APK.\n"
51 " configurations Print the configurations in the APK.\n"
52 " xmltree Print the compiled xmls in the given assets.\n"
53 " xmlstrings Print the strings of the given compiled xml assets.\n\n", gProgName
);
55 " %s p[ackage] [-f][-u][-m][-v][-x][-M AndroidManifest.xml] \\\n"
56 " [-I base-package [-I base-package ...]] \\\n"
57 " [-A asset-source-dir] [-P public-definitions-file] \\\n"
58 " [-S resource-sources] [-F apk-file] [-J R-file-dir] \\\n"
59 " [raw-files-dir [raw-files-dir] ...]\n"
61 " Package the android resources. It will read assets and resources that are\n"
62 " supplied with the -M -A -S or raw-files-dir arguments. The -J -P -F and -R\n"
63 " options control which files are output.\n\n"
66 " %s r[emove] [-v] file.{zip,jar,apk} file1 [file2 ...]\n"
67 " Delete specified files from Zip-compatible archive.\n\n",
70 " %s a[dd] [-v] file.{zip,jar,apk} file1 [file2 ...]\n"
71 " Add specified files to Zip-compatible archive.\n\n", gProgName
);
74 " Print program version.\n\n", gProgName
);
77 " -a print Android-specific data (resources, manifest) when listing\n"
78 " -c specify which configurations to include. The default is all\n"
79 " configurations. The value of the parameter should be a comma\n"
80 " separated list of configuration values. Locales should be specified\n"
81 " as either a language or language-region pair. Some examples:\n"
85 " If you put the special locale, zz_ZZ on the list, it will perform\n"
86 " pseudolocalization on the default locale, modifying all of the\n"
87 " strings so you can look for strings that missed the\n"
88 " internationalization process. For example:\n"
90 " -d one or more device assets to include, separated by commas\n"
91 " -f force overwrite of existing files\n"
92 " -j specify a jar or zip file containing classes to include\n"
93 " -m make package directories under location specified by -J\n"
95 " -p pseudolocalize the default configuration\n"
97 " -u update existing packages (add new, replace older, remove deleted files)\n"
98 " -v verbose output\n"
99 " -x create extending (non-application) resource IDs\n"
100 " -z require localization of resource attributes marked with\n"
101 " localization=\"suggested\"\n"
102 " -A additional directory in which to find raw asset files\n"
103 " -F specify the apk file to output\n"
104 " -I add an existing package to base include set\n"
105 " -J specify where to output R.java resource constant definitions\n"
106 " -M specify full path to AndroidManifest.xml to include in zip\n"
107 " -P specify where to output public resource definitions\n"
108 " -S directory in which to find resources\n"
109 " -0 don't compress files we're adding\n");
113 * Dispatch the command.
115 int handleCommand(Bundle
* bundle
)
117 //printf("--- command %d (verbose=%d force=%d):\n",
118 // bundle->getCommand(), bundle->getVerbose(), bundle->getForce());
119 //for (int i = 0; i < bundle->getFileSpecCount(); i++)
120 // printf(" %d: '%s'\n", i, bundle->getFileSpecEntry(i));
122 switch (bundle
->getCommand()) {
123 case kCommandVersion
: return doVersion(bundle
);
124 case kCommandList
: return doList(bundle
);
125 case kCommandDump
: return doDump(bundle
);
126 case kCommandAdd
: return doAdd(bundle
);
127 case kCommandRemove
: return doRemove(bundle
);
128 case kCommandPackage
: return doPackage(bundle
);
130 fprintf(stderr
, "%s: requested command not yet supported\n", gProgName
);
138 int main(int argc
, char* const argv
[])
141 bool wantUsage
= false;
142 int result
= 1; // pessimistically assume an error.
144 /* default to compression */
145 bundle
.setCompressionMethod(ZipEntry::kCompressDeflated
);
152 if (argv
[1][0] == 'v')
153 bundle
.setCommand(kCommandVersion
);
154 else if (argv
[1][0] == 'd')
155 bundle
.setCommand(kCommandDump
);
156 else if (argv
[1][0] == 'l')
157 bundle
.setCommand(kCommandList
);
158 else if (argv
[1][0] == 'a')
159 bundle
.setCommand(kCommandAdd
);
160 else if (argv
[1][0] == 'r')
161 bundle
.setCommand(kCommandRemove
);
162 else if (argv
[1][0] == 'p')
163 bundle
.setCommand(kCommandPackage
);
165 fprintf(stderr
, "ERROR: Unknown command '%s'\n", argv
[1]);
173 * Pull out flags. We support "-fv" and "-f -v".
175 while (argc
&& argv
[0][0] == '-') {
177 const char* cp
= argv
[0] +1;
179 while (*cp
!= '\0') {
182 bundle
.setVerbose(true);
185 bundle
.setAndroidList(true);
191 fprintf(stderr
, "ERROR: No argument supplied for '-c' option\n");
195 bundle
.addConfigurations(argv
[0]);
198 bundle
.setForce(true);
201 bundle
.setMakePackageDirs(true);
205 bundle
.setPseudolocalize(true);
209 bundle
.setUpdate(true);
212 bundle
.setExtending(true);
215 bundle
.setRequireLocalization(true);
221 fprintf(stderr
, "ERROR: No argument supplied for '-j' option\n");
225 convertPath(argv
[0]);
226 bundle
.addJarFile(argv
[0]);
232 fprintf(stderr
, "ERROR: No argument supplied for '-A' option\n");
236 convertPath(argv
[0]);
237 bundle
.setAssetSourceDir(argv
[0]);
243 fprintf(stderr
, "ERROR: No argument supplied for '-I' option\n");
247 convertPath(argv
[0]);
248 bundle
.addPackageInclude(argv
[0]);
254 fprintf(stderr
, "ERROR: No argument supplied for '-F' option\n");
258 convertPath(argv
[0]);
259 bundle
.setOutputAPKFile(argv
[0]);
265 fprintf(stderr
, "ERROR: No argument supplied for '-J' option\n");
269 convertPath(argv
[0]);
270 bundle
.setRClassDir(argv
[0]);
276 fprintf(stderr
, "ERROR: No argument supplied for '-M' option\n");
280 convertPath(argv
[0]);
281 bundle
.setAndroidManifestFile(argv
[0]);
287 fprintf(stderr
, "ERROR: No argument supplied for '-P' option\n");
291 convertPath(argv
[0]);
292 bundle
.setPublicOutputFile(argv
[0]);
298 fprintf(stderr
, "ERROR: No argument supplied for '-S' option\n");
302 convertPath(argv
[0]);
303 bundle
.setResourceSourceDir(argv
[0]);
306 bundle
.setCompressionMethod(ZipEntry::kCompressStored
);
309 fprintf(stderr
, "ERROR: Unknown flag '-%c'\n", *cp
);
321 * We're past the flags. The rest all goes straight in.
323 bundle
.setFileSpec(argv
, argc
);
325 result
= handleCommand(&bundle
);
333 //printf("--> returning %d\n", result);