【问题标题】:Glide showing error: Failed to find GeneratedAppGlideModuleGlide 显示错误:未能找到 GeneratedAppGlideModule
【发布时间】:2018-09-28 19:25:16
【问题描述】:

我正在尝试使用 glide 加载图像,但不知何故我无法使用 glide 加载图像。因为它显示以下错误:

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

我也推荐了This solution。但是,我已经有了 glide 的更新版本。

在我的gradle中,我添加了

implementation 'com.github.bumptech.glide:glide:4.7.1'

annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1'

代码

XML

<?xml version="1.0" encoding="utf-8"?>

<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context=".view.SettingActivity">

    <data>
        <variable
            name="settingsViewModel"
            type="com.sevenbits.android.mvvmsample.viewmodel.SettingsViewModel"/>

    </data>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/splash_bg">

        <android.support.constraint.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <LinearLayout
                android:id="@+id/profile"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="20dp"
                android:background="@color/white"
                android:elevation="10dp"
                android:orientation="vertical"
                android:padding="5dp"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toTopOf="parent">

                <de.hdodenhof.circleimageview.CircleImageView
                    android:layout_width="100dp"
                    android:layout_height="100dp"
                    android:layout_gravity="center"
                    android:layout_margin="10dp"
                    app:image_url="@{settingsViewModel.imageUrl}"
                    app:civ_border_width="2dp"
                    app:civ_border_color="@color/colorPrimary"/>

                  ...
            </LinearLayout>

    </android.support.constraint.ConstraintLayout>

</ScrollView>

CustomBindingAdapter

public class CustomBindingAdapter {

@BindingAdapter({"bind:image_url"})
public static void loadImage(ImageView imageView, String url) {

    RequestOptions requestOptions = new RequestOptions();
    requestOptions=requestOptions.placeholder(R.drawable.boy_32);

        Glide.with(imageView.getContext())
                .load(url)
                .apply(requestOptions)
                .into(imageView);
}

【问题讨论】:

  • 请提供应用级别和项目级别的 build.gradle 文件代码。

标签: android data-binding android-glide


【解决方案1】:

我也不得不面对像 Failed to find GeneratedAppGlideModule. You should include an annotationProcessor compile dependency on com.github.bumptech.glide:compiler in your application and a @GlideModule annotated AppGlideModule implementation or LibraryGlideModules will be silently ignored.

这样的问题

经过很长时间,我已经解决了我的问题。

我在 XML 文件中犯了错误,我设置了 UIImageView 的错误 height width 这就是 glide 抛出错误的原因。

请检查UIImageView Height-Width 是否正确。

【讨论】:

    【解决方案2】:

    Kotlin 解决方案:

    确保在 gradle 文件中添加以下内容(将 annotationProcessor 替换为 kapt source ):

    repositories {
      mavenCentral()
      google()
    }
    
    dependencies {
        implementation 'com.github.bumptech.glide:glide:4.8.0'
        kapt 'com.github.bumptech.glide:compiler:4.8.0'
    }
    

    在您的应用程序 [GlideSource][2] 中添加 **AppGlideModule** 实现(您可以覆盖默认方法 [overrideSource][3]):
    import android.content.Context
    import com.bumptech.glide.GlideBuilder
    import com.bumptech.glide.annotation.GlideModule
    import com.bumptech.glide.load.engine.DiskCacheStrategy
    import com.bumptech.glide.module.AppGlideModule
    import com.bumptech.glide.request.RequestOptions
    import com.bumptech.glide.signature.ObjectKey
    
    @GlideModule
    class AppNameGlideModule : AppGlideModule() {
    
        override fun applyOptions(context: Context, builder: GlideBuilder) {
            super.applyOptions(context, builder)
            builder.apply { RequestOptions().diskCacheStrategy(DiskCacheStrategy.ALL) }
        }
    
    }
    

    使用 glide 时,请使用 **GlideApp** 而不是 **Glide**,例如:
    GlideApp.with(context)
                .load(url)
                .into(imageView)
    

    【讨论】:

    • @SpyZip 尝试重建应用程序(Build > Rebuild Project)或使缓存无效(File > Invalidate Caches / Restart)
    • @RafaelGuimarães 请检查您是否创建了扩展 AppGlideModule 的附加文件
    • @Arshak,我尝试使用 android studio 工具在源代码中查找,但没有找到编译代码的解决方案是将类重命名为 GlideApps,对吗?
    • @RafaelGuimarães 不,您不应该命名将 AppGlideModule 扩展为 GlideApp 的类,我尝试了此操作,但出现编译错误,因此请将 AppNameGlideModule 重命名为 GlideModule 附加的任何您的应用程序名称(它不是强制性的,但为了理解目的),例如:CalculatorGlideModule。之后,首先构建项目,以便生成文件,然后运行它。
    • 如果您将新类命名为“GlideApp”,则会出现“重复类”错误。您应该将其命名为其他名称,例如“MyGlideModule”。将为您生成 GlideApp 类。
    【解决方案3】:

    在 build.gradle(应用程序)中

    def glide_version = "4.11.0"
    implementation ("com.github.bumptech.glide:glide:$glide_version"){
        exclude group: "com.android.support"
    }
    kapt "com.github.bumptech.glide:compiler:$glide_version"
    

    在 build.gradle(项目)中

    repositories {
        google()
        jcenter()
            ....
        maven { url 'https://maven.google.com' }
            ....
    }
    

    在你各自的班级

    import com.bumptech.glide.Glide
    import com.bumptech.glide.request.target.BitmapImageViewTarget
    
    Glide.with(imageView.rootView.context)
    .asBitmap()
    .load("your url")
    .into(object : BitmapImageViewTarget(imageView) {
         override fun setResource(resource: Bitmap?) {
             imageView.setImageBitmap(resource)
             super.setResource(resource)
         }
    })
    

    【讨论】:

      【解决方案4】:

      我在使用 AndroidX
      Glide:4.9.0 中遇到了这个问题 就这样解决了

      在你的 gradle.properties
      android.useAndroidX = true
      android.enableJetifier=true

      在你的 build.gradle
      //Glide dependency implementation 'com.github.bumptech.glide:glide:4.9.0' annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'

      然后添加您的CustomGlideModule
      @GlideModule public class CustomeGlideModule extends AppGlideModule {}

      最后一步生成 GlideModule
      Build >> Make Project,您应该会在构建文件夹中看到生成的模块

      【讨论】:

      • CustomeGlideModule类里面写什么?如果没有,那么这是必需的。
      • @SouravKannanthaB 覆盖 applyOptions(Context context, GlideBuilder builder) 方法。
      【解决方案5】:

      以上所有答案都是正确的并且工作正常

      但我注意到,当使用 #placeholder#error 方法时,如果没有如上所述的构建 GlideModule 类,滑行工作正常

      示例: 当像这样使用滑行不起作用并且必须构建 GlideModule

      Glide.with(this)
                   .load(uri)
                      .into(imageView);
      

      这很好用

      Glide.with(this).load(uri).placeholder(android.R.drawable.progress_indeterminate_horizontal).error(android.R.drawable.stat_notify_error).into(imageView);
      

      【讨论】:

        【解决方案6】:

        终于找到了我的答案here

        我做了什么:

        第一步

        我创建了一个名为GlideApp的空类

        import com.bumptech.glide.annotation.GlideModule;
        import com.bumptech.glide.module.AppGlideModule;
        
        @GlideModule
        public class GlideApp extends AppGlideModule {
        
        }
        

        注意:不要忘记添加注解@GlideModule

        第 2 步 之后,我构建/重建项目,然后将Glide 替换为GlideApp。现在不需要使用RequestOptions

        public class CustomBindingAdapter {
        
            @BindingAdapter({"bind:image_url"})
            public static void loadImage(ImageView imageView, String url) {
        
        //        RequestOptions requestOptions = new RequestOptions();
        //        requestOptions=requestOptions.placeholder(R.drawable.boy_32);
        
                GlideApp.with(imageView.getContext())
                        .load(url)
                        .placeholder(R.drawable.boy_32)
                        .into(imageView);
        
        //            Glide.with(imageView.getContext())
        //                    .load(url)
        //                    .apply(requestOptions)
        //                    .into(imageView);
            }
        }
        

        编辑: 对于 androidx 和 Glide 版本 4.9.0:

        在我应用的 gradle.build 中:

        implementation ("com.github.bumptech.glide:glide:4.9.0") {
            exclude group: "com.android.support"
        }
        annotationProcessor 'androidx.annotation:annotation:1.0.0'
        annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
        implementation ("com.github.bumptech.glide:glide:4.9.0@aar") {
            transitive = true
        }
        

        在我的 gradle.properties 中:

        android.enableJetifier=true
        android.useAndroidX=true
        

        就是这样。

        【讨论】:

        • 似乎不适用于 Glide 4.9.0 版。这会导致错误“无法解析方法'with'
        • @ezaspi 如果您使用 Kotlin,则需要在 build.gradle 依赖项中将 annotationProcessor 替换为 kapt。记得添加apply plugin: "kotlin-kapt"。此外,您正在引用您的 AppGlideModule 实现,但您应该改用 GlideApp
        • 不适用于我找不到方法尝试了所有波纹管解决方案。
        【解决方案7】:

        除了 Ridhi 的回答:

        为了让它正常工作,我必须包含 isManifestParsingEnabled

        import com.bumptech.glide.annotation.GlideModule;
        import com.bumptech.glide.module.AppGlideModule;
        
        @GlideModule
        public class MyGlideApp extends AppGlideModule {
        
            @Override
            public boolean isManifestParsingEnabled() {
                return false;
            }
        
        }
        

        【讨论】:

          猜你喜欢
          • 2021-10-18
          • 2019-11-02
          • 1970-01-01
          • 2018-08-03
          • 2011-09-17
          • 2021-11-27
          • 1970-01-01
          • 2016-04-06
          • 1970-01-01
          相关资源
          最近更新 更多