遇到问题:
由于apktool工具版本的升级和打包环境的升级,在使用apktool d -f hello.apk时,会出现如下错误提示,让我头疼了好久:
C:\Users\beijing_zbs\Desktop\apktool>apktool.bat d -f TencentNews_63.apk unzipI: 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. 解决办法:
升级apktool
Quick Check
Apktool 2.x (Versions after 1.5.2)
Is Java 1.7 installed?
Does executing java -version on command line / command prompt return 1.7?
If not, please install Java 7 and make it the default.
Installation for Apktool 2.x
Windows:
Download Windows (Right click, Save Link As apktool.bat)
Download apktool-2 ()
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 osdef 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_stringdef 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_channelif __name__ == '__main__': apktooltest()