首页 > 解决方案 > Glide 4.12.0 找不到 GeneratedAppGlideModule

问题描述

我正在使用 Glide 显示来自 firebase 存储的图像,但出现此错误:

W/Glide:未能找到 GeneratedAppGlideModule。您应该在应用程序中包含对 com.github.bumptech.glide:compiler 的 annotationProcessor 编译依赖项,并且 @GlideModule 注释的 AppGlideModule 实现或 LibraryGlideModules 将被静默忽略

我试图从Glide Failed to find GeneratedAppGlideModuleAndroid Glide "Cannot Resolve Method 'with' in GlideApp"中找到解决方案,但它们都不起作用。

以下是我在回收器视图适配器中的示例代码:

Glide.with(context).load(imageurl).into(viewHolder.getImageview());

我正在使用最新版本的 Glide:

实现 'com.github.bumptech.glide:glide:4.12.0' annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'

清理、重建项目和无效/重新启动对我不起作用。如果有人可以提出解决此问题的解决方案,我将不胜感激。谢谢你。

我在 build.gradle (项目)中的代码:

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

我在 build.gradle (模块)中的代码:

implementation 'com.github.bumptech.glide:glide:4.12.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'

我在 proguard-rules.pro 中的代码:

-keep public class * implements com.bumptech.glide.module.GlideModule
-keep class * extends com.bumptech.glide.module.AppGlideModule {
  <init>(...);
}
-keep public enum com.bumptech.glide.load.ImageHeaderParser$** {
   **[] $VALUES;
   public *;
}
-keep class
 com.bumptech.glide.load.data.ParcelFileDescriptorRewinder$InternalRewinder {
   *** rewind();
 }

标签: androidandroid-recyclerviewfirebase-storageandroid-glideimage-loading

解决方案


根据官方文档,您必须:

  1. 粘贴到您的 Gradle 文件中

    存储库 { google() mavenCentral() }

    依赖项 { 实施 'com.github.bumptech.glide:glide:4.12.0' annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0' }

  2. Proguard - 根据您的 ProGuard (DexGuard) 配置和使用情况,您可能需要在 proguard.cfg 中包含以下行

     -keep public class * implements com.bumptech.glide.module.GlideModule
     -keep class * extends com.bumptech.glide.module.AppGlideModule {
      <init>(...);
     }
     -keep public enum com.bumptech.glide.load.ImageHeaderParser$** {
       **[] $VALUES;
       public *;
     }
     -keep class 
     com.bumptech.glide.load.data.ParcelFileDescriptorRewinder$InternalRewinder {
       *** rewind();
      }
    
     # for DexGuard only
     -keepresourcexmlelements manifest/application/meta-data@value=GlideModule
    

推荐阅读