简体   繁体   中英

Android Studio 4.2 started to rename resources inside APK in release build

Recently I updated to Android Studio 4.2.1 from 4.1.3 and found everything in APK under res/ folder renamed(can I call it "obfuscated"?) when I build in release mode.

In debug it's the same as it was in older version. I use console build with gradlew assembleRelease .

I found no changelog or official word why this happening. Tried to disable it by adding shrinkResources false in app/build.gradle and using res/raw/keep.xml. Even with minifyEnabled false resources got renamed.

When I install apk to device all my icons and images seem to show as before, but my app distribute Web tool can't show app icon any more.

Anyone got the same and knows how to turn it off in release build?

The behavior was enabled by default starting with Android Gradle Plugin 4.2 and it can be disabled by adding android.enableResourceOptimizations=false to the gradle.properties file.

See https://github.com/godotengine/godot/pull/50665 for reference.

I believe it's by design.

If you updated your Android Gradle Plugin as well as your IDE itself, the newer version creates unique resource namespace per module.

So let's say you use id R.id.some_id in some layout - but within the same layout you import another layout of some library, which uses the same id R.id.some_id , you will no longer have conflict, since the id from the external library will be renamed to a name which will be unique to that library (your layout and the external layout will actually have 2 different ids) . I'll search for references then update this answer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM