]>
git.saurik.com Git - android/aapt.git/blob - Command.cpp
2 // Copyright 2006 The Android Open Source Project
4 // Android Asset Packaging Tool main entry point.
8 #include "ResourceTable.h"
12 #include <utils/ZipFile.h>
17 using namespace android
;
20 * Show version info. All the cool kids do it.
22 int doVersion(Bundle
* bundle
)
24 if (bundle
->getFileSpecCount() != 0)
25 printf("(ignoring extra arguments)\n");
26 printf("Android Asset Packaging Tool, v0.2\n");
33 * Open the file read only. The call fails if the file doesn't exist.
35 * Returns NULL on failure.
37 ZipFile
* openReadOnly(const char* fileName
)
43 result
= zip
->open(fileName
, ZipFile::kOpenReadOnly
);
44 if (result
!= NO_ERROR
) {
45 if (result
== NAME_NOT_FOUND
)
46 fprintf(stderr
, "ERROR: '%s' not found\n", fileName
);
47 else if (result
== PERMISSION_DENIED
)
48 fprintf(stderr
, "ERROR: '%s' access denied\n", fileName
);
50 fprintf(stderr
, "ERROR: failed opening '%s' as Zip file\n",
60 * Open the file read-write. The file will be created if it doesn't
61 * already exist and "okayToCreate" is set.
63 * Returns NULL on failure.
65 ZipFile
* openReadWrite(const char* fileName
, bool okayToCreate
)
71 flags
= ZipFile::kOpenReadWrite
;
73 flags
|= ZipFile::kOpenCreate
;
76 result
= zip
->open(fileName
, flags
);
77 if (result
!= NO_ERROR
) {
89 * Return a short string describing the compression method.
91 const char* compressionName(int method
)
93 if (method
== ZipEntry::kCompressStored
)
95 else if (method
== ZipEntry::kCompressDeflated
)
102 * Return the percent reduction in size (0% == no compression).
104 int calcPercent(long uncompressedLen
, long compressedLen
)
106 if (!uncompressedLen
)
109 return (int) (100.0 - (compressedLen
* 100.0) / uncompressedLen
+ 0.5);
113 * Handle the "list" command, which can be a simple file dump or
116 * The verbose listing closely matches the output of the Info-ZIP "unzip"
119 int doList(Bundle
* bundle
)
123 const ZipEntry
* entry
;
124 long totalUncLen
, totalCompLen
;
125 const char* zipFileName
;
127 if (bundle
->getFileSpecCount() != 1) {
128 fprintf(stderr
, "ERROR: specify zip file name (only)\n");
131 zipFileName
= bundle
->getFileSpecEntry(0);
133 zip
= openReadOnly(zipFileName
);
139 if (bundle
->getVerbose()) {
140 printf("Archive: %s\n", zipFileName
);
142 " Length Method Size Ratio Date Time CRC-32 Name\n");
144 "-------- ------ ------- ----- ---- ---- ------ ----\n");
147 totalUncLen
= totalCompLen
= 0;
149 count
= zip
->getNumEntries();
150 for (i
= 0; i
< count
; i
++) {
151 entry
= zip
->getEntryByIndex(i
);
152 if (bundle
->getVerbose()) {
156 when
= entry
->getModWhen();
157 strftime(dateBuf
, sizeof(dateBuf
), "%m-%d-%y %H:%M",
160 printf("%8ld %-7.7s %7ld %3d%% %s %08lx %s\n",
161 (long) entry
->getUncompressedLen(),
162 compressionName(entry
->getCompressionMethod()),
163 (long) entry
->getCompressedLen(),
164 calcPercent(entry
->getUncompressedLen(),
165 entry
->getCompressedLen()),
168 entry
->getFileName());
170 printf("%s\n", entry
->getFileName());
173 totalUncLen
+= entry
->getUncompressedLen();
174 totalCompLen
+= entry
->getCompressedLen();
177 if (bundle
->getVerbose()) {
179 "-------- ------- --- -------\n");
180 printf("%8ld %7ld %2d%% %d files\n",
183 calcPercent(totalUncLen
, totalCompLen
),
184 zip
->getNumEntries());
187 if (bundle
->getAndroidList()) {
189 if (!assets
.addAssetPath(String8(zipFileName
), NULL
)) {
190 fprintf(stderr
, "ERROR: list -a failed because assets could not be loaded\n");
194 const ResTable
& res
= assets
.getResources(false);
196 printf("\nNo resource table found.\n");
198 printf("\nResource table:\n");
202 Asset
* manifestAsset
= assets
.openNonAsset("AndroidManifest.xml",
203 Asset::ACCESS_BUFFER
);
204 if (manifestAsset
== NULL
) {
205 printf("\nNo AndroidManifest.xml found.\n");
207 printf("\nAndroid manifest:\n");
209 tree
.setTo(manifestAsset
->getBuffer(true),
210 manifestAsset
->getLength());
211 printXMLBlock(&tree
);
213 delete manifestAsset
;
223 static ssize_t
indexOfAttribute(const ResXMLTree
& tree
, uint32_t attrRes
)
225 size_t N
= tree
.getAttributeCount();
226 for (size_t i
=0; i
<N
; i
++) {
227 if (tree
.getAttributeNameResID(i
) == attrRes
) {
234 static String8
getAttribute(const ResXMLTree
& tree
, const char* ns
,
235 const char* attr
, String8
* outError
)
237 ssize_t idx
= tree
.indexOfAttribute(ns
, attr
);
242 if (tree
.getAttributeValue(idx
, &value
) != NO_ERROR
) {
243 if (value
.dataType
!= Res_value::TYPE_STRING
) {
244 if (outError
!= NULL
) *outError
= "attribute is not a string value";
249 const uint16_t* str
= tree
.getAttributeStringValue(idx
, &len
);
250 return str
? String8(str
, len
) : String8();
253 static String8
getAttribute(const ResXMLTree
& tree
, uint32_t attrRes
, String8
* outError
)
255 ssize_t idx
= indexOfAttribute(tree
, attrRes
);
260 if (tree
.getAttributeValue(idx
, &value
) != NO_ERROR
) {
261 if (value
.dataType
!= Res_value::TYPE_STRING
) {
262 if (outError
!= NULL
) *outError
= "attribute is not a string value";
267 const uint16_t* str
= tree
.getAttributeStringValue(idx
, &len
);
268 return str
? String8(str
, len
) : String8();
271 static int32_t getIntegerAttribute(const ResXMLTree
& tree
, uint32_t attrRes
,
272 String8
* outError
, int32_t defValue
= -1)
274 ssize_t idx
= indexOfAttribute(tree
, attrRes
);
279 if (tree
.getAttributeValue(idx
, &value
) != NO_ERROR
) {
280 if (value
.dataType
< Res_value::TYPE_FIRST_INT
281 || value
.dataType
> Res_value::TYPE_LAST_INT
) {
282 if (outError
!= NULL
) *outError
= "attribute is not an integer value";
289 static String8
getResolvedAttribute(const ResTable
* resTable
, const ResXMLTree
& tree
,
290 uint32_t attrRes
, String8
* outError
)
292 ssize_t idx
= indexOfAttribute(tree
, attrRes
);
297 if (tree
.getAttributeValue(idx
, &value
) != NO_ERROR
) {
298 if (value
.dataType
== Res_value::TYPE_STRING
) {
300 const uint16_t* str
= tree
.getAttributeStringValue(idx
, &len
);
301 return str
? String8(str
, len
) : String8();
303 resTable
->resolveReference(&value
, 0);
304 if (value
.dataType
!= Res_value::TYPE_STRING
) {
305 if (outError
!= NULL
) *outError
= "attribute is not a string value";
310 const Res_value
* value2
= &value
;
311 const char16_t* str
= const_cast<ResTable
*>(resTable
)->valueToString(value2
, 0, NULL
, &len
);
312 return str
? String8(str
, len
) : String8();
315 // These are attribute resource constants for the platform, as found
318 NAME_ATTR
= 0x01010003,
319 VERSION_CODE_ATTR
= 0x0101021b,
320 VERSION_NAME_ATTR
= 0x0101021c,
321 LABEL_ATTR
= 0x01010001,
322 ICON_ATTR
= 0x01010002,
323 MIN_SDK_VERSION_ATTR
= 0x0101020c,
324 REQ_TOUCH_SCREEN_ATTR
= 0x01010227,
325 REQ_KEYBOARD_TYPE_ATTR
= 0x01010228,
326 REQ_HARD_KEYBOARD_ATTR
= 0x01010229,
327 REQ_NAVIGATION_ATTR
= 0x0101022a,
328 REQ_FIVE_WAY_NAV_ATTR
= 0x01010232,
329 TARGET_SDK_VERSION_ATTR
= 0x01010270,
330 TEST_ONLY_ATTR
= 0x01010272,
331 DENSITY_ATTR
= 0x0101026c,
334 const char *getComponentName(String8
&pkgName
, String8
&componentName
) {
335 ssize_t idx
= componentName
.find(".");
336 String8
retStr(pkgName
);
338 retStr
+= componentName
;
339 } else if (idx
< 0) {
341 retStr
+= componentName
;
343 return componentName
.string();
345 return retStr
.string();
349 * Handle the "dump" command, to extract select data from an archive.
351 int doDump(Bundle
* bundle
)
353 status_t result
= UNKNOWN_ERROR
;
356 if (bundle
->getFileSpecCount() < 1) {
357 fprintf(stderr
, "ERROR: no dump option specified\n");
361 if (bundle
->getFileSpecCount() < 2) {
362 fprintf(stderr
, "ERROR: no dump file specified\n");
366 const char* option
= bundle
->getFileSpecEntry(0);
367 const char* filename
= bundle
->getFileSpecEntry(1);
371 if (!assets
.addAssetPath(String8(filename
), &assetsCookie
)) {
372 fprintf(stderr
, "ERROR: dump failed because assets could not be loaded\n");
376 const ResTable
& res
= assets
.getResources(false);
378 fprintf(stderr
, "ERROR: dump failed because no resource table was found\n");
382 if (strcmp("resources", option
) == 0) {
385 } else if (strcmp("xmltree", option
) == 0) {
386 if (bundle
->getFileSpecCount() < 3) {
387 fprintf(stderr
, "ERROR: no dump xmltree resource file specified\n");
391 for (int i
=2; i
<bundle
->getFileSpecCount(); i
++) {
392 const char* resname
= bundle
->getFileSpecEntry(i
);
394 asset
= assets
.openNonAsset(resname
, Asset::ACCESS_BUFFER
);
396 fprintf(stderr
, "ERROR: dump failed because resource %p found\n", resname
);
400 if (tree
.setTo(asset
->getBuffer(true),
401 asset
->getLength()) != NO_ERROR
) {
402 fprintf(stderr
, "ERROR: Resource %s is corrupt\n", resname
);
406 printXMLBlock(&tree
);
411 } else if (strcmp("xmlstrings", option
) == 0) {
412 if (bundle
->getFileSpecCount() < 3) {
413 fprintf(stderr
, "ERROR: no dump xmltree resource file specified\n");
417 for (int i
=2; i
<bundle
->getFileSpecCount(); i
++) {
418 const char* resname
= bundle
->getFileSpecEntry(i
);
420 asset
= assets
.openNonAsset(resname
, Asset::ACCESS_BUFFER
);
422 fprintf(stderr
, "ERROR: dump failed because resource %p found\n", resname
);
426 if (tree
.setTo(asset
->getBuffer(true),
427 asset
->getLength()) != NO_ERROR
) {
428 fprintf(stderr
, "ERROR: Resource %s is corrupt\n", resname
);
431 printStringPool(&tree
.getStrings());
438 asset
= assets
.openNonAsset("AndroidManifest.xml",
439 Asset::ACCESS_BUFFER
);
441 fprintf(stderr
, "ERROR: dump failed because no AndroidManifest.xml found\n");
445 if (tree
.setTo(asset
->getBuffer(true),
446 asset
->getLength()) != NO_ERROR
) {
447 fprintf(stderr
, "ERROR: AndroidManifest.xml is corrupt\n");
452 if (strcmp("permissions", option
) == 0) {
454 ResXMLTree::event_code_t code
;
456 while ((code
=tree
.next()) != ResXMLTree::END_DOCUMENT
&& code
!= ResXMLTree::BAD_DOCUMENT
) {
457 if (code
== ResXMLTree::END_TAG
) {
461 if (code
!= ResXMLTree::START_TAG
) {
465 String8
tag(tree
.getElementName(&len
));
466 //printf("Depth %d tag %s\n", depth, tag.string());
468 if (tag
!= "manifest") {
469 fprintf(stderr
, "ERROR: manifest does not start with <manifest> tag\n");
472 String8 pkg
= getAttribute(tree
, NULL
, "package", NULL
);
473 printf("package: %s\n", pkg
.string());
474 } else if (depth
== 2 && tag
== "permission") {
476 String8 name
= getAttribute(tree
, NAME_ATTR
, &error
);
478 fprintf(stderr
, "ERROR: %s\n", error
.string());
481 printf("permission: %s\n", name
.string());
482 } else if (depth
== 2 && tag
== "uses-permission") {
484 String8 name
= getAttribute(tree
, NAME_ATTR
, &error
);
486 fprintf(stderr
, "ERROR: %s\n", error
.string());
489 printf("uses-permission: %s\n", name
.string());
492 } else if (strcmp("badging", option
) == 0) {
494 ResXMLTree::event_code_t code
;
497 bool withinActivity
= false;
498 bool isMainActivity
= false;
499 bool isLauncherActivity
= false;
500 bool withinApplication
= false;
501 bool withinReceiver
= false;
503 String8 activityName
;
504 String8 activityLabel
;
505 String8 activityIcon
;
506 String8 receiverName
;
507 while ((code
=tree
.next()) != ResXMLTree::END_DOCUMENT
&& code
!= ResXMLTree::BAD_DOCUMENT
) {
508 if (code
== ResXMLTree::END_TAG
) {
512 if (code
!= ResXMLTree::START_TAG
) {
516 String8
tag(tree
.getElementName(&len
));
517 //printf("Depth %d tag %s\n", depth, tag.string());
519 if (tag
!= "manifest") {
520 fprintf(stderr
, "ERROR: manifest does not start with <manifest> tag\n");
523 pkg
= getAttribute(tree
, NULL
, "package", NULL
);
524 printf("package: name='%s' ", pkg
.string());
525 int32_t versionCode
= getIntegerAttribute(tree
, VERSION_CODE_ATTR
, &error
);
527 fprintf(stderr
, "ERROR getting 'android:versionCode' attribute: %s\n", error
.string());
530 if (versionCode
> 0) {
531 printf("versionCode='%d' ", versionCode
);
533 printf("versionCode='' ");
535 String8 versionName
= getAttribute(tree
, VERSION_NAME_ATTR
, &error
);
537 fprintf(stderr
, "ERROR getting 'android:versionName' attribute: %s\n", error
.string());
540 printf("versionName='%s'\n", versionName
.string());
541 } else if (depth
== 2) {
542 withinApplication
= false;
543 if (tag
== "application") {
544 withinApplication
= true;
545 String8 label
= getResolvedAttribute(&res
, tree
, LABEL_ATTR
, &error
);
547 fprintf(stderr
, "ERROR getting 'android:label' attribute: %s\n", error
.string());
550 printf("application: label='%s' ", label
.string());
551 String8 icon
= getResolvedAttribute(&res
, tree
, ICON_ATTR
, &error
);
553 fprintf(stderr
, "ERROR getting 'android:icon' attribute: %s\n", error
.string());
556 printf("icon='%s'\n", icon
.string());
557 int32_t testOnly
= getIntegerAttribute(tree
, TEST_ONLY_ATTR
, &error
, 0);
559 fprintf(stderr
, "ERROR getting 'android:testOnly' attribute: %s\n", error
.string());
563 printf("testOnly='%d'\n", testOnly
);
565 } else if (tag
== "uses-sdk") {
566 int32_t code
= getIntegerAttribute(tree
, MIN_SDK_VERSION_ATTR
, &error
);
569 String8 name
= getResolvedAttribute(&res
, tree
, MIN_SDK_VERSION_ATTR
, &error
);
571 fprintf(stderr
, "ERROR getting 'android:minSdkVersion' attribute: %s\n",
575 printf("sdkVersion:'%s'\n", name
.string());
576 } else if (code
!= -1) {
577 printf("sdkVersion:'%d'\n", code
);
579 code
= getIntegerAttribute(tree
, TARGET_SDK_VERSION_ATTR
, &error
);
582 String8 name
= getResolvedAttribute(&res
, tree
, TARGET_SDK_VERSION_ATTR
, &error
);
584 fprintf(stderr
, "ERROR getting 'android:targetSdkVersion' attribute: %s\n",
588 printf("targetSdkVersion:'%s'\n", name
.string());
589 } else if (code
!= -1) {
590 printf("targetSdkVersion:'%d'\n", code
);
592 } else if (tag
== "uses-configuration") {
593 int32_t reqTouchScreen
= getIntegerAttribute(tree
,
594 REQ_TOUCH_SCREEN_ATTR
, NULL
, 0);
595 int32_t reqKeyboardType
= getIntegerAttribute(tree
,
596 REQ_KEYBOARD_TYPE_ATTR
, NULL
, 0);
597 int32_t reqHardKeyboard
= getIntegerAttribute(tree
,
598 REQ_HARD_KEYBOARD_ATTR
, NULL
, 0);
599 int32_t reqNavigation
= getIntegerAttribute(tree
,
600 REQ_NAVIGATION_ATTR
, NULL
, 0);
601 int32_t reqFiveWayNav
= getIntegerAttribute(tree
,
602 REQ_FIVE_WAY_NAV_ATTR
, NULL
, 0);
603 printf("uses-configuation:");
604 if (reqTouchScreen
!= 0) {
605 printf(" reqTouchScreen='%d'", reqTouchScreen
);
607 if (reqKeyboardType
!= 0) {
608 printf(" reqKeyboardType='%d'", reqKeyboardType
);
610 if (reqHardKeyboard
!= 0) {
611 printf(" reqHardKeyboard='%d'", reqHardKeyboard
);
613 if (reqNavigation
!= 0) {
614 printf(" reqNavigation='%d'", reqNavigation
);
616 if (reqFiveWayNav
!= 0) {
617 printf(" reqFiveWayNav='%d'", reqFiveWayNav
);
620 } else if (tag
== "supports-density") {
621 int32_t dens
= getIntegerAttribute(tree
, DENSITY_ATTR
, &error
);
623 fprintf(stderr
, "ERROR getting 'android:density' attribute: %s\n",
627 printf("supports-density:'%d'\n", dens
);
629 } else if (depth
== 3 && withinApplication
) {
630 withinActivity
= false;
631 withinReceiver
= false;
632 if(tag
== "activity") {
633 withinActivity
= true;
634 activityName
= getAttribute(tree
, NAME_ATTR
, &error
);
636 fprintf(stderr
, "ERROR getting 'android:name' attribute: %s\n", error
.string());
640 activityLabel
= getResolvedAttribute(&res
, tree
, LABEL_ATTR
, &error
);
642 fprintf(stderr
, "ERROR getting 'android:label' attribute: %s\n", error
.string());
646 activityIcon
= getResolvedAttribute(&res
, tree
, ICON_ATTR
, &error
);
648 fprintf(stderr
, "ERROR getting 'android:icon' attribute: %s\n", error
.string());
651 } else if (tag
== "uses-library") {
652 String8 libraryName
= getAttribute(tree
, NAME_ATTR
, &error
);
654 fprintf(stderr
, "ERROR getting 'android:name' attribute for uses-library: %s\n", error
.string());
657 printf("uses-library:'%s'\n", libraryName
.string());
658 } else if (tag
== "receiver") {
659 withinReceiver
= true;
660 receiverName
= getAttribute(tree
, NAME_ATTR
, &error
);
663 fprintf(stderr
, "ERROR getting 'android:name' attribute for receiver: %s\n", error
.string());
667 } else if (depth
== 5) {
668 if (withinActivity
) {
669 if (tag
== "action") {
670 //printf("LOG: action tag\n");
671 String8 action
= getAttribute(tree
, NAME_ATTR
, &error
);
673 fprintf(stderr
, "ERROR getting 'android:name' attribute: %s\n", error
.string());
676 if (action
== "android.intent.action.MAIN") {
677 isMainActivity
= true;
678 //printf("LOG: isMainActivity==true\n");
680 } else if (tag
== "category") {
681 String8 category
= getAttribute(tree
, NAME_ATTR
, &error
);
683 fprintf(stderr
, "ERROR getting 'name' attribute: %s\n", error
.string());
686 if (category
== "android.intent.category.LAUNCHER") {
687 isLauncherActivity
= true;
688 //printf("LOG: isLauncherActivity==true\n");
691 } else if (withinReceiver
) {
692 if (tag
== "action") {
693 String8 action
= getAttribute(tree
, NAME_ATTR
, &error
);
695 fprintf(stderr
, "ERROR getting 'android:name' attribute for receiver: %s\n", error
.string());
698 if (action
== "android.appwidget.action.APPWIDGET_UPDATE") {
699 const char *rName
= getComponentName(pkg
, receiverName
);
701 printf("gadget-receiver:'%s/%s'\n", pkg
.string(), rName
);
709 withinApplication
= false;
712 //if (withinActivity) printf("LOG: withinActivity==false\n");
713 withinActivity
= false;
714 withinReceiver
= false;
718 //if (isMainActivity) printf("LOG: isMainActivity==false\n");
719 //if (isLauncherActivity) printf("LOG: isLauncherActivity==false\n");
720 isMainActivity
= false;
721 isLauncherActivity
= false;
724 if (withinActivity
&& isMainActivity
&& isLauncherActivity
) {
725 printf("launchable activity:");
726 const char *aName
= getComponentName(pkg
, activityName
);
728 printf(" name='%s'", aName
);
730 printf("label='%s' icon='%s'\n",
731 activityLabel
.string(),
732 activityIcon
.string());
736 Vector
<String8
> locales
;
737 res
.getLocales(&locales
);
738 const size_t N
= locales
.size();
739 for (size_t i
=0; i
<N
; i
++) {
740 const char* localeStr
= locales
[i
].string();
741 if (localeStr
== NULL
|| strlen(localeStr
) == 0) {
744 printf(" '%s'", localeStr
);
747 AssetDir
* dir
= assets
.openNonAssetDir(assetsCookie
, "lib");
749 if (dir
->getFileCount() > 0) {
750 printf("native-code:");
751 for (size_t i
=0; i
<dir
->getFileCount(); i
++) {
752 printf(" '%s'", dir
->getFileName(i
).string());
758 } else if (strcmp("configurations", option
) == 0) {
759 Vector
<ResTable_config
> configs
;
760 res
.getConfigurations(&configs
);
761 const size_t N
= configs
.size();
762 for (size_t i
=0; i
<N
; i
++) {
763 printf("%s\n", configs
[i
].toString().string());
766 fprintf(stderr
, "ERROR: unknown dump option '%s'\n", option
);
777 return (result
!= NO_ERROR
);
782 * Handle the "add" command, which wants to add files to a new or
783 * pre-existing archive.
785 int doAdd(Bundle
* bundle
)
788 status_t result
= UNKNOWN_ERROR
;
789 const char* zipFileName
;
791 if (bundle
->getUpdate()) {
792 /* avoid confusion */
793 fprintf(stderr
, "ERROR: can't use '-u' with add\n");
797 if (bundle
->getFileSpecCount() < 1) {
798 fprintf(stderr
, "ERROR: must specify zip file name\n");
801 zipFileName
= bundle
->getFileSpecEntry(0);
803 if (bundle
->getFileSpecCount() < 2) {
804 fprintf(stderr
, "NOTE: nothing to do\n");
808 zip
= openReadWrite(zipFileName
, true);
810 fprintf(stderr
, "ERROR: failed opening/creating '%s' as Zip file\n", zipFileName
);
814 for (int i
= 1; i
< bundle
->getFileSpecCount(); i
++) {
815 const char* fileName
= bundle
->getFileSpecEntry(i
);
817 if (strcasecmp(String8(fileName
).getPathExtension().string(), ".gz") == 0) {
818 printf(" '%s'... (from gzip)\n", fileName
);
819 result
= zip
->addGzip(fileName
, String8(fileName
).getBasePath().string(), NULL
);
821 printf(" '%s'...\n", fileName
);
822 result
= zip
->add(fileName
, bundle
->getCompressionMethod(), NULL
);
824 if (result
!= NO_ERROR
) {
825 fprintf(stderr
, "Unable to add '%s' to '%s'", bundle
->getFileSpecEntry(i
), zipFileName
);
826 if (result
== NAME_NOT_FOUND
)
827 fprintf(stderr
, ": file not found\n");
828 else if (result
== ALREADY_EXISTS
)
829 fprintf(stderr
, ": already exists in archive\n");
831 fprintf(stderr
, "\n");
840 return (result
!= NO_ERROR
);
845 * Delete files from an existing archive.
847 int doRemove(Bundle
* bundle
)
850 status_t result
= UNKNOWN_ERROR
;
851 const char* zipFileName
;
853 if (bundle
->getFileSpecCount() < 1) {
854 fprintf(stderr
, "ERROR: must specify zip file name\n");
857 zipFileName
= bundle
->getFileSpecEntry(0);
859 if (bundle
->getFileSpecCount() < 2) {
860 fprintf(stderr
, "NOTE: nothing to do\n");
864 zip
= openReadWrite(zipFileName
, false);
866 fprintf(stderr
, "ERROR: failed opening Zip archive '%s'\n",
871 for (int i
= 1; i
< bundle
->getFileSpecCount(); i
++) {
872 const char* fileName
= bundle
->getFileSpecEntry(i
);
875 entry
= zip
->getEntryByName(fileName
);
877 printf(" '%s' NOT FOUND\n", fileName
);
881 result
= zip
->remove(entry
);
883 if (result
!= NO_ERROR
) {
884 fprintf(stderr
, "Unable to delete '%s' from '%s'\n",
885 bundle
->getFileSpecEntry(i
), zipFileName
);
890 /* update the archive */
895 return (result
!= NO_ERROR
);
900 * Package up an asset directory and associated application files.
902 int doPackage(Bundle
* bundle
)
904 const char* outputAPKFile
;
907 sp
<AaptAssets
> assets
;
910 // -c zz_ZZ means do pseudolocalization
911 ResourceFilter filter
;
912 err
= filter
.parse(bundle
->getConfigurations());
913 if (err
!= NO_ERROR
) {
916 if (filter
.containsPseudo()) {
917 bundle
->setPseudolocalize(true);
920 N
= bundle
->getFileSpecCount();
921 if (N
< 1 && bundle
->getResourceSourceDirs().size() == 0 && bundle
->getJarFiles().size() == 0
922 && bundle
->getAndroidManifestFile() == NULL
&& bundle
->getAssetSourceDir() == NULL
) {
923 fprintf(stderr
, "ERROR: no input files\n");
927 outputAPKFile
= bundle
->getOutputAPKFile();
929 // Make sure the filenames provided exist and are of the appropriate type.
932 type
= getFileType(outputAPKFile
);
933 if (type
!= kFileTypeNonexistent
&& type
!= kFileTypeRegular
) {
935 "ERROR: output file '%s' exists but is not regular file\n",
942 assets
= new AaptAssets();
943 err
= assets
->slurpFromArgs(bundle
);
948 if (bundle
->getVerbose()) {
952 // If they asked for any files that need to be compiled, do so.
953 if (bundle
->getResourceSourceDirs().size() || bundle
->getAndroidManifestFile()) {
954 err
= buildResources(bundle
, assets
);
960 // At this point we've read everything and processed everything. From here
961 // on out it's just writing output files.
962 if (SourcePos::hasErrors()) {
966 // Write out R.java constants
967 if (assets
->getPackage() == assets
->getSymbolsPrivatePackage()) {
968 err
= writeResourceSymbols(bundle
, assets
, assets
->getPackage(), true);
973 err
= writeResourceSymbols(bundle
, assets
, assets
->getPackage(), false);
977 err
= writeResourceSymbols(bundle
, assets
, assets
->getSymbolsPrivatePackage(), true);
985 err
= writeAPK(bundle
, assets
, String8(outputAPKFile
));
986 if (err
!= NO_ERROR
) {
987 fprintf(stderr
, "ERROR: packaging of '%s' failed\n", outputAPKFile
);
994 if (SourcePos::hasErrors()) {
995 SourcePos::printErrors(stderr
);