项目中用到Android apk反编译重打包,可在用apktool遇到了一些问题,今天抽时间把问题总结下;
(1)我最初用的apktool版本为1.5.2,在反编译时偶尔报错如下:
2014-12-11 13:46:29 I: Baksmaling...
2014-12-11 13:46:35 I: Loading resource table...
2014-12-11 13:46:36 I: Loaded.
2014-12-11 13:46:36 I: Decoding AndroidManifest.xml with resources...
2014-12-11 13:46:36 I: Loading resource table from file:C:\Users\sunxinxin01\apktool\framework\1.apk
2014-12-11 13:46:38 I: Loaded.
2014-12-11 13:46:38 W: Could not decode attr value, using undecoded valueinstead: ns=android, name=hardwareAccelerated, value=0xffffffff
2014-12-11 13:46:38 I: Regular manifest package...
2014-12-11 13:46:38 I: Decoding file-resources...
2014-12-11 13:46:38 W: Could not decode attr value, using undecoded valueinstead: ns=android, name=textIsSelectable, value=0x00000000
2014-12-11 13:46:38 W: Could not decode attr value, using undecoded valueinstead: ns=android, name=layerType, value=0x00000001
2014-12-11 13:46:39 I: Decoding values */* XMLs...
2014-12-11 13:46:39 Exception in thread "main"brut.androlib.err.UndefinedResObject: resource spec: 0x01010362
2014-12-11 13:46:39 atbrut.androlib.res.data.ResPackage.getResSpec(ResPackage.java:61)
2014-12-11 13:46:39 atbrut.androlib.res.data.ResTable.getResSpec(ResTable.java:58)
2014-12-11 13:46:39 atbrut.androlib.res.data.ResTable.getResSpec(ResTable.java:54)
2014-12-11 13:46:39 atbrut.androlib.res.data.value.ResReferenceValue.getReferent(ResReferenceValue.java:62)
2014-12-11 13:46:39 at brut.androlib.res.data.value.ResStyleValue.serializeToResValuesXml(ResStyleValue.java:51)
2014-12-11 13:46:39 atbrut.androlib.res.AndrolibResources.generateValuesFile(AndrolibResources.java:440)
2014-12-11 13:46:39 atbrut.androlib.res.AndrolibResources.decode(AndrolibResources.java:243)
2014-12-11 13:46:39 atbrut.androlib.Androlib.decodeResourcesFull(Androlib.java:115)
2014-12-11 13:46:39 atbrut.androlib.ApkDecoder.decode(ApkDecoder.java:114)
2014-12-11 13:46:39 at brut.apktool.Main.cmdDecode(Main.java:146)
2014-12-11 13:46:39 at brut.apktool.Main.main(Main.java:77)
解决方案: 将 C:\Users\用户\apktool 文件夹删除即可解决;(2)在用apktool1.5.2版本时,某些apk反编译会报如下错:
2015-01-29 11:50:57 I: Baksmaling...
2015-01-29 11:51:06 I: Loading resource table...
2015-01-29 11:51:06 Exception in thread "main"brut.androlib.AndrolibException: Could not decode arsc file
2015-01-29 11:51:06 atbrut.androlib.res.decoder.ARSCDecoder.decode(ARSCDecoder.java:56)
2015-01-29 11:51:06 atbrut.androlib.res.AndrolibResources.getResPackagesFromApk(AndrolibResources.java:491)
2015-01-29 11:51:06 at brut.androlib.res.AndrolibResources.loadMainPkg(AndrolibResources.java:74)
2015-01-29 11:51:06 atbrut.androlib.res.AndrolibResources.getResTable(AndrolibResources.java:66)
2015-01-29 11:51:06 atbrut.androlib.Androlib.getResTable(Androlib.java:50)
2015-01-29 11:51:06 atbrut.androlib.ApkDecoder.getResTable(ApkDecoder.java:189)
2015-01-29 11:51:06 atbrut.androlib.ApkDecoder.decode(ApkDecoder.java:114)
2015-01-29 11:51:06 at brut.apktool.Main.cmdDecode(Main.java:146)
2015-01-29 11:51:06 at brut.apktool.Main.main(Main.java:77)
2015-01-29 11:51:06 Caused by: java.io.IOException: Expected: 0x001c0001, got:0x00000000
2015-01-29 11:51:06 atbrut.util.ExtDataInput.skipCheckInt(ExtDataInput.java:48)
2015-01-29 11:51:06 at brut.androlib.res.decoder.StringBlock.read(StringBlock.java:44)
2015-01-29 11:51:06 atbrut.androlib.res.decoder.ARSCDecoder.readPackage(ARSCDecoder.java:102)
2015-01-29 11:51:06 atbrut.androlib.res.decoder.ARSCDecoder.readTable(ARSCDecoder.java:83)
2015-01-29 11:51:06 at brut.androlib.res.decoder.ARSCDecoder.decode(ARSCDecoder.java:49)
2015-01-29 11:51:07 ... 8 more
解决方案:将apktool版本升级到2.0.0即可解决,但要注意的是这一版本使用jdk1.7编译的,所以jre低于1.7的会报错;apktool2.0.0下载地址:https://bitbucket.org/iBotPeaches/apktool/downloads;
(3)将apktool升级到2.0.0时,重打包出来的apk在安装时报错:INSTALL_PARSE_FAILED_NO_CERTIFICATES。网上说是没有签名,可已经用jarsigner签名过了,后来发现是由于jdk7的默认签名算法改变了,和jdk6的不同。
解决方案:使用jarsigner签名时要注意加入以下选项,这样打出来的apk就ok了:
-digestalg SHA1 -sigalg MD5withRSA
参考:http://androiddevelopertutorial.com/fixing-install_parse_failed_no_certificates-android-jdk7