標籤:
目錄(?)[-]
- AAPT 工具介紹
- AAPT 的協助資訊
- 查看AAPT的版本
- 使用AAPT列出資源套件apk檔案清單
- 使用AAPT打包資源檔
- 使用AAPT解壓資源套件apk
來自:http://mmmyddd.freeshell.net/blog.cgi/Computer/Android/aapt-decompress-apk
AAPT 工具介紹
下面是取自"http://www.androidcn.net/wiki/index.php/Reference/aapt"的介紹
aapt stands for Android Asset Packaging Tool and is included in the tools/ directory of the SDK. This tool allows you to view, create, and update Zip-compatible archives (zip, jar, apk). It can also compile resources into binary assets.
aapt即Android Asset Packaging Tool , 在SDK的tools/目錄下. 該工具可以查看, 建立, 更新ZIP格式的文檔附件(zip, jar, apk). 也可將資源檔編譯成二進位檔案.
Though you probably won‘t often use aapt directly, build scripts and IDE plugins can utilize this tool to package the apk file that constitutes an Android application.
儘管你可能沒有直接使用過aapt工具, 但是build scripts和IDE外掛程式會使用這個工具打包apk檔案構成一個Android 應用程式.
For more usage details, open a terminal, go to the tools/ directory, and run the command:
擷取更多的實用資訊, 請開啟終端控制台, 到tools/目錄下, 執行命令:
Linux or Mac OS X:
./aapt
Windows:
aapt.exe
AAPT 的協助資訊
執行上述命令,會在控制台打出相應aapt的資訊:
Android Asset Packaging ToolUsage: aapt l[ist] [-v] [-a] file.{zip,jar,apk} List contents of Zip-compatible archive. aapt d[ump] WHAT file.{apk} [asset [asset ...]] badging Print the label and icon for the app declared in APK. permissions Print the permissions from the APK. resources Print the resource table from the APK. configurations Print the configurations in the APK. xmltree Print the compiled xmls in the given assets. xmlstrings Print the strings of the given compiled xml assets. aapt p[ackage] [-f][-u][-m][-v][-x][-M AndroidManifest.xml] / [-0 extension [-0 extension ...]] / [-I base-package [-I base-package ...]] / [-A asset-source-dir] [-P public-definitions-file] / [-S resource-sources] [-F apk-file] [-J R-file-dir] / [raw-files-dir [raw-files-dir] ...] Package the android resources. It will read assets and resources that are supplied with the -M -A -S or raw-files-dir arguments. The -J -P -F and -R options control which files are output. aapt r[emove] [-v] file.{zip,jar,apk} file1 [file2 ...] Delete specified files from Zip-compatible archive. aapt a[dd] [-v] file.{zip,jar,apk} file1 [file2 ...] Add specified files to Zip-compatible archive. aapt v[ersion] Print program version. Modifiers: -a print Android-specific data (resources, manifest) when listing -c specify which configurations to include. The default is all configurations. The value of the parameter should be a comma separated list of configuration values. Locales should be specified as either a language or language-region pair. Some examples: en port,en port,land,en_US If you put the special locale, zz_ZZ on the list, it will perform pseudolocalization on the default locale, modifying all of the strings so you can look for strings that missed the internationalization process. For example: port,land,zz_ZZ -d one or more device assets to include, separated by commas -f force overwrite of existing files -j specify a jar or zip file containing classes to include -m make package directories under location specified by -J -u update existing packages (add new, replace older, remove deleted files) -v verbose output -x create extending (non-application) resource IDs -z require localization of resource attributes marked with localization="suggested" -A additional directory in which to find raw asset files -F specify the apk file to output -I add an existing package to base include set -J specify where to output R.java resource constant definitions -M specify full path to AndroidManifest.xml to include in zip -P specify where to output public resource definitions -S directory in which to find resources -0 specifies an additional extension for which such files will not be stored compressed in the .apk. An empty string means to not compress any files at all.
根據以上協助資訊,用aapt可以使用以下操作:
查看AAPT的版本
./aapt v
得到當前工具的版本:
Android Asset Packaging Tool, v0.2
使用AAPT列出資源套件(.apk)檔案清單
aapt l[ist] [-v] [-a] file.{zip,jar,apk} List contents of Zip-compatible archive.
可以用命令查看系統資源套件的內容:
./aapt l framework-res.apk
META-INF/MANIFEST.MFMETA-INF/CERT.SFMETA-INF/CERT.RSAAndroidManifest.xmlassets/images/android_320x480.pngassets/images/boot_robot.pngassets/images/boot_robot_glow.png...assets/webkit/youtube.htmlassets/webkit/youtube.pngres/anim/accelerate_decelerate_interpolator.xmlres/anim/accelerate_interpolator.xmlres/anim/app_starting_exit.xml...res/raw-de/loaderror.htmlres/raw-de/nodomain.htmlres/raw/fallbackring.oggres/raw/loaderror.htmlres/raw/nodomain.htmlres/xml-en/autotext.xmlres/xml/apns.xmlres/xml/autotext.xmlres/xml/preferred_time_zones.xmlres/xml/time_zones_by_country.xmlresources.arsc
如果採用-v選項,會將所有檔案的詳細資料列印出來:
Archive: framework-res.apk Length Method Size Ratio Date Time CRC-32 Name-------- ------ ------- ----- ---- ---- ------ ---- 76217 Deflate 25576 66% 04-16-08 07:40 3b7140fa META-INF/MANIFEST.MF 76259 Deflate 25706 66% 04-16-08 07:40 a21d76be META-INF/CERT.SF 1714 Deflate 1156 33% 04-16-08 07:40 ca66d55e META-INF/CERT.RSA 31768 Deflate 5556 83% 01-16-09 12:04 8c137ee8 AndroidManifest.xml 3098 Stored 3098 0% 01-15-09 23:16 ed1132c9 assets/images/android_320x480.png 1001 Stored 1001 0% 01-15-09 23:16 c53ad035 assets/images/boot_robot.png 2083 Stored 2083 0% 01-15-09 23:16 12acc29d assets/images/boot_robot_glow.png... ... 340 Deflate 155 54% 01-16-09 12:04 cc2ad7f2 res/anim/accelerate_decelerate_interpolator.xml 368 Deflate 179 51% 01-16-09 12:04 c94b9323 res/anim/accelerate_interpolator.xml 568 Deflate 260 54% 01-16-09 12:04 e0972304 res/anim/app_starting_exit.xml... ... 605 Deflate 296 51% 01-15-09 23:16 88710568 res/raw-de/loaderror.html 996 Deflate 471 53% 01-15-09 23:16 c42ea004 res/raw-de/nodomain.html 10975 Stored 10975 0% 01-15-09 23:16 21dc2fce res/raw/fallbackring.ogg 579 Deflate 282 51% 01-15-09 23:16 11c56b88 res/raw/loaderror.html 890 Deflate 418 53% 01-15-09 23:16 393cf037 res/raw/nodomain.html 25588 Deflate 5051 80% 01-16-09 12:04 cf7826df res/xml-en/autotext.xml 164 Deflate 97 41% 01-16-09 12:04 ee886635 res/xml/apns.xml 116 Deflate 59 49% 01-16-09 12:04 885f246d res/xml/autotext.xml 864 Deflate 312 64% 01-16-09 12:04 65ad9d7e res/xml/preferred_time_zones.xml 61044 Deflate 11755 81% 01-16-09 12:04 0bc79a58 res/xml/time_zones_by_country.xml 747776 Stored 747776 0% 01-16-09 12:04 98f996b3 resources.arsc-------- ------- --- ------- 2246729 1774656 21% 851 files
如果採用-a選項,會在上述檔案清單之後,列印出android使用的符號表:
Resource table:mError=0x0 (Success)Package Groups (1)Package Group 0 id=1 packageCount=1 name=android Package 0 id=1 name=android typeCount=13 type 0 configCount=1 entryCount=599 spec resource 0x01010000 android:attr/theme: flags=0x40000000 spec resource 0x01010001 android:attr/label: flags=0x40000000 spec resource 0x01010002 android:attr/icon: flags=0x40000000 spec resource 0x01010003 android:attr/name: flags=0x40000000 spec resource 0x01010004 android:attr/manageSpaceActivity: flags=0x40000000 spec resource 0x01010005 android:attr/allowClearUserData: flags=0x40000000 spec resource 0x01010006 android:attr/permission: flags=0x40000000 spec resource 0x01010007 android:attr/readPermission: flags=0x40000000 spec resource 0x01010008 android:attr/writePermission: flags=0x40000000 spec resource 0x01010009 android:attr/protectionLevel: flags=0x40000000 spec resource 0x0101000a android:attr/permissionGroup: flags=0x40000000... ...
這些符號表的格式還需要進一步研究才能搞明白 -_-!
使用AAPT打包資源檔
使用以下命令查看android的build系統是如何打包framework-res模組的:
cd ~/android/srcmake -n --debug framework-res
以下是從輸出提取的關鍵步驟:
1. 第一步,產生資源apk包,由以下命令完成:
out/host/linux-x86/bin/aapt package -z -u -x -M frameworks/base/core/res/AndroidManifest.xml -S frameworks/base/core/res/res -A frameworks/base/core/res/assets -F out/target/product/generic/obj/APPS/framework-res_intermediates/package.apk
2. 第二步,為產生的資源套件做簽名:
java -jar out/host/linux-x86/framework/signapk.jar build/target/product/security/platform.x509.pem build/target/product/security/platform.pk8 out/target/product/generic/obj/APPS/framework-res_intermediates/package.apk.unsigned out/target/product/generic/obj/APPS/framework-res_intermediates/package.apk.signed
3. 第三步,為產生的包做對齊處理:
out/host/linux-x86/bin/zipalign -f 4 out/target/product/generic/obj/APPS/framework-res_intermediates/package.apk.unaligned out/target/product/generic/obj/APPS/framework-res_intermediates/package.apk.aligned
如此產生的framework-res.apk包可以被用來替換system.img中的資源套件。(在CupCake前的穩定版本中測試可行)
具體步驟:
- 首先用產生的framework-res.apk替換在~/android/src/out/target/product/generic/system/framework中的同名檔案。
- 用make snod產生新的system.img,替換sdk目錄下的images/system.img
- 用-wipe-date參數啟動emulator
使用AAPT解壓資源套件(.apk)
./aapt d xmltree framework-res.apk res/anim/fade_in.xml
N: android=http://schemas.android.com/apk/res/android E: alpha (line=21) A: android:interpolator(0x01010141)[email protected] A: android:duration(0x01010198)=(type 0x10)0x12c A: android:fromAlpha(0x010101ca)=(type 0x4)0x0 A: android:toAlpha(0x010101cb)=(type 0x4)0x3f800000
./aapt d xmlstrings framework-res.apk res/anim/fade_in.xml
String #0: interpolatorString #1: fromAlphaString #2: toAlphaString #3: durationString #4: androidString #5: http://schemas.android.com/apk/res/androidString #6:String #7: alpha
而沒有經過編譯的檔案為:
<alpha xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@anim/decelerate_interpolator" android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="300" />
相應的R.java檔案為:
package com.android.internal;public final class R { public static final class anim { public static final int accelerate_decelerate_interpolator=0x010a0004; public static final int accelerate_interpolator=0x010a0005; public static final int app_starting_exit=0x010a0007; public static final int decelerate_interpolator=0x010a0006; public static final int dialog_enter=0x010a0008; public static final int dialog_exit=0x010a0009;... ...
也可以從符號表中得到這些索引值:
resource 0x010a0006 android:anim/decelerate_interpolator: t=0x03 d=0x00001132 (s=0x0008 r=0x00) (PUBLIC)
配合系統預定的framework/base/core/res/res目錄的模版,就可以重建/res檔案.
Android aapt 工具介紹(轉)