简体   繁体   English

Android Studio 4.2 开始在发布版本中重命名 APK 内的资源

[英]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.最近我从 4.1.3 更新到 Android Studio 4.2.1 并在发布模式下构建时发现 res/ 文件夹下的 APK 中的所有内容都重命名(我可以称之为“混淆”吗?)。

In debug it's the same as it was in older version.在调试中它与旧版本中的相同。 I use console build with gradlew assembleRelease .我使用带有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.试图通过在 app/build.gradle 中添加shrinkResources false并使用 res/raw/keep.xml 来禁用它。 Even with minifyEnabled false resources got renamed.即使使用minifyEnabled false资源也被重命名。

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.当我将 apk 安装到设备时,我的所有图标和图像似乎都像以前一样显示,但我的应用分发 Web 工具无法再显示应用图标。

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.该行为从 Android Gradle Plugin 4.2 开始默认启用,可以通过将android.enableResourceOptimizations=false添加到gradle.properties文件来禁用它。

See https://github.com/godotengine/godot/pull/50665 for reference.请参阅https://github.com/godotengine/godot/pull/50665以供参考。

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.如果您更新了 Android Gradle 插件以及 IDE 本身,则较新版本会为每个模块创建唯一的资源命名空间。

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) .因此,假设您在某个布局中使用 id R.id.some_id - 但是在同一个布局中您导入某个库的另一个布局,它使用相同的 id R.id.some_id ,您将不再有冲突,因为 id 来自外部库将被重命名为该库唯一的名称(您的布局和外部布局实际上将有 2 个不同的 id) I'll search for references then update this answer.我会搜索参考资料,然后更新这个答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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