http://blog.csdn.net/wirelessqa/article/details/8997168
Android apktool是一個用來處理APK文件的工具,可以對APK進行反編譯生成程序的源代碼和圖片、XML配置、語言資源等文件,也可以添加新的功能到APK文件中。用該工具來漢化Android軟件然后重新打包發布是相當簡單的。
下載地址:http://code.google.com/p/android-apktool/downloads/list
一.安裝操作:
1.下載apktool.jar — 解壓
2.下載Mac上的輔助工具apktool-install-macosx.. – 解壓
3. 將apktool.jar放到apktool-install-macosx..目錄下,也就是跟apktool命令放到一起
4.運行sh apktool

運行結果:
01 |
bixiaopeng @bixiaopengtekiMacBook -Pro ~$ /Users/bixiaopeng/Downloads/apktool-install-macosx-r05-ibot/apktool ; exit; |
02 |
Apktool v1. 5.2 - a tool for reengineering Android apk files |
03 |
Copyright 2010 Ryszard Wi?niewski <brut.alll @gmail .com> |
04 |
with smali v1. 4.1 , and baksmali v1. 4.1 |
05 |
Updated by @iBotPeaches <connor.tumbleson @gmail .com> |
06 |
Apache License 2.0 (http: |
09 |
Usage: apktool [-q|--quiet OR -v|--verbose] COMMAND […] |
15 |
d[ecode] [OPTS] <file.apk> [<dir>] |
16 |
Decode <file.apk> to <dir>. |
23 |
Do not decode sources. |
25 |
Do not decode resources. |
27 |
Decode in debug mode. Check project page for more info. |
29 |
Baksmali -- don't write out debug info (.local, .param, .line, etc.) |
31 |
Force delete destination directory. |
32 |
-t <tag>, --frame-tag <tag> |
33 |
Try to use framework files tagged by <tag>. |
35 |
Use the specified directory for framework files |
37 |
Use if there was an error and some resources were dropped, e.g.: |
38 |
"Invalid config flags detected. Dropping resources" , but you |
39 |
want to decode them anyway, even with errors. You will have to |
40 |
fix them manually before building. |
43 |
b[uild] [OPTS] [<app_path>] [<out_file>] ----從你給出的本地路徑構建一個apk |
44 |
Build an apk from already decoded application located in <app_path>. |
47 |
It will automatically detect, whether files was changed and perform |
51 |
If you omit <app_path> then current directory will be used. |
52 |
If you omit <out_file> then <app_path>/dist/<name_of_original.apk> |
60 |
Skip changes detection and build all files. |
62 |
Build in debug mode. Check project page for more info. |
64 |
Loads aapt from specified location. |
67 |
if |install-framework <framework.apk> [<tag>] --frame-path [<location>] |
68 |
Install framework file to your system. |
71 |
For additional info, see: http: |
72 |
For smali/baksmali info, see: http: |
二.配置環境變量
(1)先查看$PATH的配置

(2)將上述三個文件復制到/usr/local/bin 下面

(3) 接下來你就可以直接使用apktool了
1.反編譯APK命令
decode:該命令用於進行反編譯apk文件,一般用法為 :
apktool d <file.apk> <dir>
<file.apk>代表了要反編譯的apk文件的路徑,最好寫絕對路徑,比如C:\MusicPlayer.apk
<dir>代表了反編譯后的文件的存儲位置,比如C:\MusicPlayer
如果你給定的<dir>已經存在,那么輸入完該命令后會提示你,並且無法執行,需要你重新修改命令加入-f指令
apktool d –f <file.apk> <dir>
這樣就會強行覆蓋已經存在的文件
2.編譯修改好的文件
build:該命令用於編譯修改好的文件,一般用法為:
apktool b <dir>
這里的<dir>就是剛才你反編譯時輸入的<dir>(如C:\MusicPlayer),輸入這行命令后,如果一切正常,你會發現C:\MusicPlayer內多了2個文件夾build和dist,其中分別存儲着編譯過程中逐個編譯的文件以及最終打包的apk文件。
3.install-framework
該命令用於為APKTool安裝特定的framework-res.apk文件,以方便進行反編譯一些與ROM相互依賴的APK文件。具體情況請看常見問題

4.1 反編譯新浪微博的APK
01 |
bixiaopeng @bixiaopengtekiMacBook -Pro ~$ apktool d /Users/bixiaopeng/Downloads/com.sina.weibo.apk /Users/bixiaopeng/work-folder/OWL-APKTOOL |
03 |
I: Loading resource table… |
05 |
I: Decoding AndroidManifest.xml with resources… |
06 |
I: Loading resource table from file: /Users/bixiaopeng/Library/apktool/framework/ 1 .apk |
08 |
I: Regular manifest package … |
09 |
I: Decoding file-resources… |
10 |
I: Decoding values */* XMLs… |
12 |
I: Copying assets and libs… |
作者:畢小朋 出處: http://www.wirelessqa.com 歡迎轉載或分享,但請務必聲明文章出處。如果文章對您有幫助,希望您能推薦或關注。
反編譯后的結果:

4.2 重新打包修改后的資源文件
1 |
bixiaopeng @bixiaopengtekiMacBook -Pro ~$ apktool b /Users/bixiaopeng/work-folder/OWL-APKTOOL |
2 |
I: Checking whether sources has changed… |
3 |
I: Checking whether resources has changed… |
重新打包成功后,在原文件夾下面會多出一個dist文件夾,重新打包的APK就存在下面

4.3 自動簽名
將你准備簽名的keystore放到當前目錄下,運行命令:
1 |
bixiaopeng@bixiaopengtekiMacBook-Pro dist$ jarsigner -verbose -keystore bxp.keystore -signedjar new .apk com.sina.weibo.apk bxp.keystore |
小解其意:
【keystore】:bxp.keystore
【簽名后的apk名字】:new.apk
【簽名前的apk名字】:com.sina.weibo.apk

【如果您沒有keystore或者是不知道keystore密鑰庫的口令,那么您需要自己做一個,怎么做?跟我來吧!!】
4.4 用命令行創建keystore
1 |
keytool -genkey -keystore bxp.keystore -keyalg RSA -validity 10000 -alias bxp.keystore |

命令參數說明:
-genkey 產生證書文件
-keystore 指定密鑰庫的.keystore文件中
-keyalg 指定密鑰的算法
-validity 為證書有效天數,這里我們寫的是10000天。
-alias 產生別名
在輸入密碼時沒有回顯,只管輸入就可以了,一般位數建議使用20位,切忌需要記下來后面還要用,
注意:
1. CN(Common Name – 名字與姓氏):其實這個“名字與姓氏”應該是域名,比如說localhost或是blog.devep.net之類的。輸成了姓名,和真正運行的時候域名不符,會出問題。瀏覽器訪問時,彈出一個對話框,提示“安全證書上的名稱無效,或者與站點名稱不匹配”,用戶選擇繼續還是可以瀏覽網頁。但是用http client寫程序訪問的時候,會拋出類似於“javax.servlet.ServletException: HTTPS hostname wrong: should be ”的異常。
2. 在用keytool生成數字證書時必須保證:-keystore androidapp.keystore -alias androidapp.keystore 兩者名稱必須相同。否則下一步簽名時會出現錯誤:jarsigner: 找不到 androidapp.keystore 的證書鏈。androidapp.keystore 必須引用包含專用密鑰和相應的公共密鑰證書鏈的有效密鑰庫密鑰條目。