android studio getResources().getIdentifier 返回 0 如果应用 dexguard

标签 android android-studio android-drawable dexguard

我在应用程序中使用了 dexguard。我正在动态加载图像并在 ImageView 中显示。但 ImageView 显示空白。我正在使用下面的代码。

 getResources().getIdentifier(imagename, "drawable", packageName);

当我在项目中使用 dexguard 1.7.0.02 时,它返回 0(启用收缩并禁用混淆和优化调试构建)。如果我删除 dexguard 并运行该项目,它工作正常并显示正确的图像。

注意:与 eclipse 中的 dexguard 相同的项目,对于上述代码工作正常。我仅在 Android Studio 中遇到过这个问题。

最佳答案

我自己找到了解决方案。如果您在 android studio 中应用收缩,dexguard 7.0 会收缩资源(对于未使用的)。但是当我来到 Dexguard 6.0 时,它不会收缩资源(我在 eclipse 项目中观察到)。所以我管理如下 Dexguard 的资源7.0配置

  -keepresourcefiles res/drawable/**
  -keepresources drawable/**

关于android studio getResources().getIdentifier 返回 0 如果应用 dexguard,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31536038/

相关文章:

Android:启动共享 Intent 会关闭我的 Activity

java - 导出和导入 SQLite 数据库

android - 如何使用 sceneform 从场景中删除选定的对象?

android-studio - 新项目中的 Android Studio "Unknown attribute android:text"警告

android - 设置 BitmapDrawable tileMode 使应用程序重新启动

java - JSONException : Value <? java.lang.String 类型的 xml 无法转换为 JSONObject

AndroidStudio 3.5 - ClassNotFoundException - 从其他模块引用的 View

android - Android Studio 安装过程中无法安装 HAXM

java - 在低于 23 的 API 中绘制复杂的可绘制对象

来自 Fragment 内部的 Android getDrawable()