Glide无法从发布版本中的资源ID加载图像,代码为封闭

时间:2018-01-03 09:55:16

标签: android android-glide android-proguard dexguard

使用Glide时,当我尝试从Resid加载时,图像永远不会加载到我的版本上,它在调试变体上运行正常。 以下是我的代码。

Glide.with(activity.applicationContext).load(R.drawable.mydrawable).into(imageView)

但是,如果我在发布和发布上同时提供图片网址文件路径,它就有效。调试变体

以下是我的proguard配置

# Glide
-keep class com.bumptech.glide.** { *;}
-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public class * extends com.bumptech.glide.GeneratedAppGlideModule
-keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** {
  **[] $VALUES;
  public *;
}

2 个答案:

答案 0 :(得分:0)

可以先尝试获取资源的drawable,然后使用Glide加载:

Drawable d = getResources().getDrawable(R.drawable.mydrawable, null); Glide.with(activity.applicationContext).load(d).into(imageView)

答案 1 :(得分:-1)

什么是Glide?

Glide supports fetching, decoding, and displaying video stills, images, and animated GIFs. Glide includes a flexible API that allows developers to plug in to almost any network stack.

您正在做的是从drawable加载到imageView。

你不需要Glide,你可以这样做:

imageView.setImageResource(R.drawable.mydrawable);