-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] apktool cannot recompile obfuscated apks with shrinkResources = true after updating Gradle #3534
Comments
Do you have a smaller apk sample to work from? |
The sample projects of Android Studio seem to do the trick. Here you have. Both APKs here decompile OK with "java -jar apktool_2.9.3.jar d [file]", but only shrinkResources_false.apk can be recompiled. |
Setting android.enableNewResourceShrinker.preciseShrinking=false in my gradle.properties file and enabling shrinkResources = true seems to make it work again (decompile & recompile) https://developer.android.com/build/releases/gradle-plugin#resource-shrinking |
I made a sample that leveraged that feature when investigating another bug - maybe some overlap with this. Especially if this is the feature that automatically strips namespace context from resources. |
maybe this is the same condition.
related two lines:
after decode , this item(autoSizeTextType) value is 1, the same error rised while re-building. I change its value to uniform manually according to this link, but this error still happen. |
Maybe apktool could detect those values by simply looking for their attribute names in the <!-- styles.xml -->
<item name="someAttribute">1</item>
<!-- attrs.xml -->
<attr name="someAttribute">
<enum name="anotherKey" value="0" />
</attr> can be turned into: <!-- styles.xml -->
<item name="someAttribute">apktool_generatedStubEnumKey_1</item>
<!-- attrs.xml -->
<attr name="someAttribute">
<enum name="anotherKey" value="0" />
<enum name="apktool_generatedStubEnumKey_1" value="1" />
</attr> |
That is one possibility, but Apktool during processing may not have enough information at time of each AXML file disassembly to know at that exact moment if the scalar should be a enum or not. I've been experimenting with relaxing the aapt2 build requirement to see if can survive with the scalar instead of re-making the enum. https://github.com/iBotPeaches/platform_frameworks_base/tree/apktool-2.10.x |
i have successfully recompiled apks which were compiled with shrinkResources = true
Conclusion: If we can include all attrs of such type from google's source or a generic file by default in each decompile and these values get auto detected or changed in res/layout and res/xml folders ? |
If you set android.enableNewResourceShrinker.preciseShrinking=false in your gradle.properties, then you can enable shrinkResources = true again and produce APKs that apktool can process, but gradle shows this message... "The option setting 'android.enableNewResourceShrinker.preciseShrinking=false' is deprecated. We may not be able to do this anymore in the future. Any update on this issue? |
Not at this time. Changes occurred in AOSP and I can no longer build aapt2 and its stretched past my knowledge. So I'm blocked on everything until I learn more on how to resolve that. context: https://groups.google.com/g/android-building/c/TvKKsSLSlPY |
i used "lunch aosp_arm64-trunk_staging-eng" and i can build aapt and aapt2 fine with latest repo sync which removed lunch menu. |
thanks. I'll give that a shot tonight. |
Information
I'm getting errors while decompiling -> recompiling my own apk. The issue started happening after updating Android Studio and the gradle plugin.
It only happens when I compile my app with obfuscation enabled and "shrinkResources true" in my build.gradle file. If I compile an apk with "shrinkResources false", apktool is able to decompile/recompile the apk.
Stacktrace/Logcat
I'm getting a few of those errors:
temp_a711ab5f-4bc1-4ff0-84f4-f5198dc96737\temp\res\values\styles.xml:1552: error: expected enum but got (raw string)
Here is the referenced part of styles.xml file of the apk that breaks apktool:
And here is the styles.xml in the apk that apktool recompiles OK:
The line the stack trace is referencing to (1552) is this one:
<item name="boxBackgroundMode">2</item>
Apparently R8, the obfuscator, replaced an enum with its literal value. My humble guess is that apktool might not need to be that strict while checking this.
Questions to ask before submission
apktool d
,apktool b
without changing anything?: YesThe text was updated successfully, but these errors were encountered: