[轉]android 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


 

 

 

 

本文小結了一下該工具的用法。
1.  aapt l[ist] [-v] [-a] file.{zip,jar,apk}
   List contents of Zip-compatible archive.
1.1 列出壓縮文件目錄
aapt l <file_path.apk>
參數:
-v:會以table的形式輸出目錄,table的表目有:Length、Method、Size、Ratio、Date、Time、CRC-32、Name。
其中Method表示壓縮形式,有:Deflate及Stored兩種,即該Zip目錄采用的算法是壓縮模式還是存儲模式;可以看出resources.arsc、*.png采用壓縮模式,而其它采用壓縮模式。
Ratio表示壓縮率。CRC-32未明其意,Sodino盼指教。

-a:會詳細輸出所有目錄的內容。
效果圖:aapt_list.JPG
 list


2. aapt d[ump] [--values] 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.

2.1 查看apk包的packageName、versionCode、applicationLabel、launcherActivity、permission等各種詳細信息
aapt dump badging <file_path.apk>
效果圖:aapt_dump_badging.JPG
 badging

2.2 查看權限
aapt dump permissions <file_path.apk>
效果圖:aapt_dump_permissions.JPG

 permission

2.3 查看資源列表
aapt dump resources <file_path.apk>
一般都會輸出很多的信息,如要全部查看,請用下面這兩句:
aapt dump resources <file_path.apk>   > sodino.txt
sodino.txt
這樣會把所有的信息通過重定向符">"輸出到sodino.txt文件中,然后再打開該文件即可查看。


2.4 查看apk配置信息
aapt dump configurations <file_path.apk>


2.5 查看指定apk的指定xml文件。
aapt dump xmltree <file_path.apk> res/***.xml
以樹形結構輸出的xml信息。
aapt dump xmlstrings <file_path.apk> res/***.xml
輸出xml文件中所有的字符串信息。
效果圖:aapt_dump_xmltree.JPG

 xmltree

3
由於此處代碼量比較大,本人寫成批處理形式了。

使用aapt生成R.java
rem 測試的工程目錄下必須得有gen文件夾,否則會提示:Unable to open class file R.java:No such file or directory
%aapt% package -f -m -J %GEN% -S %RES% -I %ANDROID_JAR% -M %ANDROID_MANIFEST_XML%

使用aapt生成資源包文件
%aapt% package -f -M %ANDROID_MANIFEST_XML% -S %RES% -A %ASSETS% -I %ANDROID_JAR% -F %RESOURCE%

%GEN%:存放的R.java文件夾路徑。
%RES%:res文件夾路徑。
%ANDROID_JAR%:引用的android.jar路徑。
%ANDROID_MANIFEST_XML%:工程AndroidManifest.xml絕對路徑。
%ASSETS%:asset文件夾路徑。
%RESOURCE%:生成的resouces.arsc存放路徑。

參考:
Android系列之Android 命令行手動編譯打包詳解
http://blog168.chinaunix.net/space.php?uid=22957718&do=blog&cuid=2322671

 

其余的不解釋,直接見效果圖:
 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.
效果圖:aapt_r_a_v.JPG  

r_a_v

 

http://blog.csdn.net/brave_heart_lxl/article/details/6187260


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM