Apktool rebuild失败:No resource found that matches the given name

Trouble现象

1.使用apktool d命令将已有apk进行反编译→正常;

2.使用apktool b命令将反编译后的文件重新编回apk→异常:

I: Using Apktool 2.2.2
I: Checking whether sources has changed...
I: Checking whether resources has changed...
I: Building resources...
W: /Users/shijie.wei/Downloads/base_858_33000016_0.1.4_15/res/values-v23/styles.xml:3: error: Error retrieving parent for item: No resource found that matches the given name '@android:style/DialogWindowTitle'.
W: 
W: /Users/shijie.wei/Downloads/base_858_33000016_0.1.4_15/res/values-v23/styles.xml:4: error: Error retrieving parent for item: No resource found that matches the given name '@android:style/AlertDialog'.
W: 
Exception in thread "main" brut.androlib.AndrolibException: brut.androlib.AndrolibException: brut.common.BrutException: could not exec (exit code = 1): [/var/folders/kz/sl5jjbvj7mb4qx9r7xlnx728bz6cp6/T/brut_util_Jar_6643593175078773050.tmp, p, --forced-package-id, 127, --min-sdk-version, 15, --target-sdk-version, 24, --version-code, 15, --version-name, 0.1.4, --no-version-vectors, -F, /var/folders/kz/sl5jjbvj7mb4qx9r7xlnx728bz6cp6/T/APKTOOL2395147760136189345.tmp, -0, arsc, -0, acb, -0, txt, -0, assets/bin/Data/PlayerConnectionConfigFile, -0, arsc, -I, /Users/shijie.wei/Library/apktool/framework/1.apk, -S, /Users/shijie.wei/Downloads/base_858_33000016_0.1.4_15/res, -M, /Users/shijie.wei/Downloads/base_858_33000016_0.1.4_15/AndroidManifest.xml]
	at brut.androlib.Androlib.buildResourcesFull(Androlib.java:477)
	at brut.androlib.Androlib.buildResources(Androlib.java:411)
	at brut.androlib.Androlib.build(Androlib.java:310)
	at brut.androlib.Androlib.build(Androlib.java:263)
	at brut.apktool.Main.cmdBuild(Main.java:227)
	at brut.apktool.Main.main(Main.java:84)
Caused by: brut.androlib.AndrolibException: brut.common.BrutException: could not exec (exit code = 1): [/var/folders/kz/sl5jjbvj7mb4qx9r7xlnx728bz6cp6/T/brut_util_Jar_6643593175078773050.tmp, p, --forced-package-id, 127, --min-sdk-version, 15, --target-sdk-version, 24, --version-code, 15, --version-name, 0.1.4, --no-version-vectors, -F, /var/folders/kz/sl5jjbvj7mb4qx9r7xlnx728bz6cp6/T/APKTOOL2395147760136189345.tmp, -0, arsc, -0, acb, -0, txt, -0, assets/bin/Data/PlayerConnectionConfigFile, -0, arsc, -I, /Users/shijie.wei/Library/apktool/framework/1.apk, -S, /Users/shijie.wei/Downloads/base_858_33000016_0.1.4_15/res, -M, /Users/shijie.wei/Downloads/base_858_33000016_0.1.4_15/AndroidManifest.xml]
	at brut.androlib.res.AndrolibResources.aaptPackage(AndrolibResources.java:440)
	at brut.androlib.Androlib.buildResourcesFull(Androlib.java:463)
	... 5 more
Caused by: brut.common.BrutException: could not exec (exit code = 1): [/var/folders/kz/sl5jjbvj7mb4qx9r7xlnx728bz6cp6/T/brut_util_Jar_6643593175078773050.tmp, p, --forced-package-id, 127, --min-sdk-version, 15, --target-sdk-version, 24, --version-code, 15, --version-name, 0.1.4, --no-version-vectors, -F, /var/folders/kz/sl5jjbvj7mb4qx9r7xlnx728bz6cp6/T/APKTOOL2395147760136189345.tmp, -0, arsc, -0, acb, -0, txt, -0, assets/bin/Data/PlayerConnectionConfigFile, -0, arsc, -I, /Users/shijie.wei/Library/apktool/framework/1.apk, -S, /Users/shijie.wei/Downloads/base_858_33000016_0.1.4_15/res, -M, /Users/shijie.wei/Downloads/base_858_33000016_0.1.4_15/AndroidManifest.xml]
	at brut.util.OS.exec(OS.java:95)
	at brut.androlib.res.AndrolibResources.aaptPackage(AndrolibResources.java:434)
	... 6 more

问题来了,【error: Error retrieving parent for item: No resource found that matches the given name '@android:style/DialogWindowTitle'.】

问题分析

我使用的apk并没有做加密处理,所以按理说使用apktool进行反编译和回编译不应该失败。那这个错误就应该有其原因和对应的解决方法。

一般情况下,此时更新最新的apktool.jar就可以解决问题,但有时单纯更新apktool也不行。无论如何,引起错误的原因究竟是什么?其实问题不在apktool,而是framework太旧了!如果你只是更新了apktool.jar,而没有更新framework,这时候很有可能还会遇到最初的问题。

更新apktool的正确方法

在更新了apktool.jar后,需要手动更新framework,方法很简单,删除 ~/Library/apktool/framework/1.apk 即可,这是MacOS下的默认路径,如果你不知道自己的framework路径,就去运行一遍apktool d命令,命令行中会显示使用的framework路径:

apktool d:
I: Using Apktool 2.2.0 on base_858_33000016_0.1.4_15.apk
I: Loading resource table...
I: Decoding AndroidManifest.xml with resources...
I: Loading resource table from file: /Users/jackie/Library/apktool/framework/1.apk
I: Regular manifest package...
I: Decoding file-resources...
I: Decoding values */* XMLs...
I: Baksmaling classes.dex...
I: Copying assets and libs...
I: Copying unknown files...
I: Copying original files...
当你下次运行apktool时,会自动安装对应的framework,这样一来就算完全更新了apktool。

framework

这是使用apktool不可或缺的,一般来说系统会自动安装,然而有些手机厂商(比如htc,三星)会定制自己的framework并在自己的某些系统应用中使用这些文件,当你需要反编译这些文件时就会遇到找不到资源的错误,此时需要手动安装这些设备自带的framework,一般都是以framework-res.apk的之类的名字存在于设备的system/framework文件加下,拷贝到电脑中进行安装即可。

关于更多apktool和framework的信息,可以查看官方文档:Apktool
还有一篇博文也提到了部分知识:Apktool使用心得

你可能感兴趣的:(Android)