1、aapt工具介紹
aapt即Android Asset Packaging Tool,在SDK的build-tools目錄下。該工具可以查看,創建, 更新ZIP格式的文檔附件(zip, jar, apk)。也可將資源文件編譯成二進制文件,盡管你可能沒有直接使用過aapt工具,但是build scripts和IDE插件會使用這個工具打包apk文件構成一個Android 應用程序。在使用aapt之前需要在環境變量里面配置SDK-tools路徑,或者是路徑+aapt的方式進入aapt。
2、Mac上環境變量配置
1)touch ~/.bash_profile
2)open -t ~/.bash_profile
修改環境變量
Example:
export PATH=${PATH}:/Users/sunshanshan/Library/Android/sdk/build-tools/23.0.0
注意:不同的電腦最后路徑可能不一樣,需要自己確定最后一個文件是否是23.0.0,從該路徑下找到aapt(然后執行pwd指令獲取當前路徑即可)
環境變量添加完成
3)source ~/.bash_profile
修改文件后執行生效操作
4)echo $PATH
查看環境變量是否生效
5)直接在終端中輸入aapt,顯示如下表示已經成功添加環境變量
3、aapt的常用解析apk指令
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.
Example:aapt -dump <apk文件路徑> 這條指令就是查看QQ.apk這個Android安裝包的資源列表,里面包括了版本號等基本信息
3.2 aapt l -v <apk文件路徑>
-
Length:原始文件的長度
-
Date:日期
-
Time:時間
-
Name:名稱
-
Method:壓縮方法,Deflate及Stored兩種,即該Zip目錄采用的算法是壓縮模式還是存儲模式;可以看出resources.arsc、*.png采用壓縮模式,而其它采用壓縮模式。
-
Ratio:壓縮率
-
Size:這個是壓縮省掉的大小,即如果壓縮率是xx%。那Size是原始長度*(1-xx%)。
-
CRC-32:循環冗余校驗。這個計算是有特定的算法的。
-
offset:zipfile中的偏移量