gpt4 book ai didi

android - 如何使用 apktool 构建库项目?

转载 作者:太空狗 更新时间:2023-10-29 14:19:09 24 4
gpt4 key购买 nike

我可以使用 apktool 解码 apk,然后为我的普通 android 项目重新构建。

但是当我对依赖于库项目 (appcompat) 的项目尝试同样的事情时,它失败并出现以下错误。

我是否需要使用库项目进行构建?如果需要,我该如何指定?

$ apktool build apkdecode repack.apk
I: Checking whether sources has changed...
I: Smaling...
I: Checking whether resources has changed...
I: Building resources...
/<currentdir>/apkdecode/res/values/styles.xml:59: error: Error retrieving parent for item: No resource found that matches the given name 'Widget.AppCompat.Base'.
/<currentdir>/apkdecode/res/values/styles.xml:99: error: Error retrieving parent for item: No resource found that matches the given name 'Widget.AppCompat.Base'.
/<currentdir>/apkdecode/res/values/styles.xml:146: error: Error retrieving parent for item: No resource found that matches the given name 'Widget.AppCompat.Base'.
/<currentdir>/apkdecode/res/values/styles.xml:176: error: Error retrieving parent for item: No resource found that matches the given name 'Widget.AppCompat.Base'.
/<currentdir>/apkdecode/res/values/styles.xml:192: error: Error retrieving parent for item: No resource found that matches the given name 'Widget.AppCompat.Base.DropDownItem'.
/<currentdir>/apkdecode/res/values/styles.xml:218: error: Error retrieving parent for item: No resource found that matches the given name 'Widget.AppCompat.Base'.
/<currentdir>/apkdecode/res/values/styles.xml:225: error: Error retrieving parent for item: No resource found that matches the given name 'Widget.AppCompat.Light.Base'.
/<currentdir>/apkdecode/res/values/styles.xml:242: error: Error retrieving parent for item: No resource found that matches the given name 'TextAppearance.AppCompat.Base'.
/<currentdir>/apkdecode/res/values/styles.xml:275: error: Error retrieving parent for item: No resource found that matches the given name 'Widget.AppCompat.Base'.
/<currentdir>/apkdecode/res/values-v14/styles.xml:50: error: Error retrieving parent for item: No resource found that matches the given name 'Widget.AppCompat.Base'.
/<currentdir>/apkdecode/res/values/styles.xml:467: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Base'.
Exception in thread "main" brut.androlib.AndrolibException: brut.androlib.AndrolibException: brut.common.BrutException: could not exec command: [aapt, p, --min-sdk-version, 8, --target-sdk-version, 11, -F, /var/folders/6l/q11hqqj57rs0lgxcx1njdlxc0000gn/T/APKTOOL2534308390228031373.tmp, -0, arsc, -I, /<toolpath>/apktool/framework/1.apk, -S, /<currentdir>/apkdecode/res, -M, /<currentdir>/apkdecode/AndroidManifest.xml]
at brut.androlib.Androlib.buildResourcesFull(Androlib.java:358)
at brut.androlib.Androlib.buildResources(Androlib.java:283)
at brut.androlib.Androlib.build(Androlib.java:206)
at brut.androlib.Androlib.build(Androlib.java:176)
at brut.apktool.Main.cmdBuild(Main.java:228)
at brut.apktool.Main.main(Main.java:79)
Caused by: brut.androlib.AndrolibException: brut.common.BrutException: could not exec command: [aapt, p, --min-sdk-version, 8, --target-sdk-version, 11, -F, /var/folders/6l/q11hqqj57rs0lgxcx1njdlxc0000gn/T/APKTOOL2534308390228031373.tmp, -0, arsc, -I, /<toolpath>/apktool/framework/1.apk, -S, /<currentdir>/apkdecode/res, -M, /<currentdir>/apkdecode/AndroidManifest.xml]
at brut.androlib.res.AndrolibResources.aaptPackage(AndrolibResources.java:357)
at brut.androlib.Androlib.buildResourcesFull(Androlib.java:336)
... 5 more
Caused by: brut.common.BrutException: could not exec command: [aapt, p, --min-sdk-version, 8, --target-sdk-version, 11, -F, /var/folders/6l/q11hqqj57rs0lgxcx1njdlxc0000gn/T/APKTOOL2534308390228031373.tmp, -0, arsc, -I, /<toolpath>/apktool/framework/1.apk, -S, /<currentdir>/apkdecode/res, -M, /<currentdir>/apkdecode/AndroidManifest.xml]
at brut.util.OS.exec(OS.java:89)
at brut.androlib.res.AndrolibResources.aaptPackage(AndrolibResources.java:355)
... 6 more

最佳答案

这是 apktool v1 (1.5.3) 的问题。有几种方法可以解决。

<强>1。编辑 styles.xml。将空的“parent”属性添加到错误行上的标签。例如:

之前

59: <style name="Widget.AppCompat.Base.ActionBar">

之后

59: <style name="Widget.AppCompat.Base.ActionBar" parent="">

然后构建项目。这样每次解码apk时都需要编辑xml。

<强>2。编辑 apktool 源并重建它。您必须在文件“android-apktool/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/data/value/ResStyleValue.java”中编辑方法“serializeToResValuesXml”:

之前

if (!mParent.isNull()) {
serializer.attribute(null, "parent", mParent.encodeAsResXmlAttr());
}

之后

if (!mParent.isNull()) {
serializer.attribute(null, "parent", mParent.encodeAsResXmlAttr());
} else if (res.getResSpec().getName().indexOf('.') != -1) {
serializer.attribute(null, "parent", "");
}

<强>3。只需使用 apktool v2 :)

关于android - 如何使用 apktool 构建库项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18478320/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com