Glide 显示错误:无法找到 GeneratedAppGlideModule [英] Glide showing error: Failed to find GeneratedAppGlideModule

查看:41
本文介绍了Glide 显示错误:无法找到 GeneratedAppGlideModule的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to load an image using glide but somehow I can not load the image using glide. As it shows following error:

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

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.

我也推荐了这个解决方案.但是,我已经有了 glide 的更新版本.

I have reffered This solution too. But, I already have the updated verion of glide.

在我的gradle中,我添加了

In my gradle, I have added

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>

自定义绑定适配器

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);
}

推荐答案

我终于找到了答案 这里.

我做了什么:

第一步

我创建了一个名为 GlideApp

import com.bumptech.glide.annotation.GlideModule;
import com.bumptech.glide.module.AppGlideModule;

@GlideModule
public class GlideApp extends AppGlideModule {

}

注意:不要忘记添加注释@GlideModule.

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

Step-2 After that, I build/rebuild the project and then, replaced Glide with GlideApp.and now no need to use 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:

For androidx and Glide versin 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 显示错误:无法找到 GeneratedAppGlideModule的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆