遇到問題:java
因爲apktool工具版本的升級和打包環境的升級,在使用apktool d -f hello.apk時,會出現以下錯誤提示,讓我頭疼了很久:python
C:\Users\beijing_zbs\Desktop\apktool>apktool.bat d -f TencentNews_63.apk unzip I: Baksmaling... I: Loading resource table... Exception in thread "main" brut.androlib.AndrolibException: Could not decode arsc file at brut.androlib.res.decoder.ARSCDecoder.decode(ARSCDecoder.java:54) at brut.androlib.res.AndrolibResources.getResPackagesFromApk(AndrolibResources.java:540) at brut.androlib.res.AndrolibResources.loadMainPkg(AndrolibResources.java:76) at brut.androlib.res.AndrolibResources.getResTable(AndrolibResources.java:68) at brut.androlib.Androlib.getResTable(Androlib.java:51) at brut.androlib.ApkDecoder.getResTable(ApkDecoder.java:191) at brut.androlib.ApkDecoder.decode(ApkDecoder.java:116) at brut.apktool.Main.cmdDecode(Main.java:148) at brut.apktool.Main.main(Main.java:77) Caused by: java.io.IOException: Expected: 0x001c0001, got: 0x00000000 at brut.util.ExtDataInput.skipCheckInt(ExtDataInput.java:48) at brut.androlib.res.decoder.StringBlock.read(StringBlock.java:43) at brut.androlib.res.decoder.ARSCDecoder.readPackage(ARSCDecoder.java:100) at brut.androlib.res.decoder.ARSCDecoder.readTable(ARSCDecoder.java:81) at brut.androlib.res.decoder.ARSCDecoder.decode(ARSCDecoder.java:49) ... 8 more
2. 解決辦法:android
升級apktoolgit
https://code.google.com/p/android-apktool/wiki/Install github
Apktool 2.x (Versions after 1.5.2)shell
Is Java 1.7 installed?編程
Does executing java -version on command line / command prompt return 1.7?windows
If not, please install Java 7 and make it the default.app
Windows:工具
Download Windows wrapper script (Right click, Save Link As apktool.bat)
Download apktool-2 (find newest here)
Rename downloaded jar to apktool.jar
Move both files (apktool.jar & apktool.bat) to your Windows directory (Usually C://Windows)
If you do not have access to C://Windows, you may place the two files anywhere then add that directory to your Environment Variables System PATH variable.
Try running apktool via command prompt
3. 升級之後,使用apktool d -s -m -f hello.apk這個工具就能夠了
4.編程實現:
# # -*- coding: utf-8 -*- ''' Created on 2015-2-2 @author: baosenzhang ''' import os def findversionline(path): f = open(path,'r') #lines=f.readlines() for l in f.readline(): line = f.readline() #print l,line if line.find('versionName')>-1: #print "OK" return line.strip('\n') else: return f.close() def readversioninfo(versioninfolinestr): versioninfo=versioninfolinestr.split(' ') return [versioninfo[1].split('"')[1],versioninfo[2].split('"')[1]] def readcontent(path): file = open(path,'r') send_string = '' try: send_string=file.read() finally: file.close() #print send_string.decode('gb2312').encode('utf-8') return send_string def apktooltest(): os.system('apktool d -s -m -f ..\AppFolder\TencentNews_14.apk -o ..\unzipfolder\\') versioninfo=findversionline("\\unzipfolder\\AndroidManifest.xml") print versioninfo getpackageversion=readversioninfo(versioninfo) print getpackageversion read_channel = readcontent('\\unzipfolder\\assets\\channel') print read_channel if __name__ == '__main__': apktooltest()