Glide显示错误:无法找到GeneratedAppGlideModule

问题描述 投票:15回答:4

我试图使用滑动加载图像但不知何故我无法使用滑动加载图像。因为它显示以下错误:

无法找到GeneratedAppGlideModule。您应该在com.github.bumptech.glide中包含annotationProcessor编译依赖项:应用程序中的编译器和@GlideModule带注释的AppGlideModule实现或者LibraryGlideModules将被静默忽略。

我也提到了qazxsw poi。但是,我已经有了更新的滑行版本。

在我的gradle中,我补充说

This solution

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

XML

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

CustomBindingAdapter

<?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>
android data-binding android-glide
4个回答
28
投票

最后,我找到了答案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); }

我做了什么 :

步骤1

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

GlideApp

注意:不要忘记添加注释import com.bumptech.glide.annotation.GlideModule; import com.bumptech.glide.module.AppGlideModule; @GlideModule public class GlideApp extends AppGlideModule { }

步骤2之后,我构建/重建项目,然后用@GlideModule替换Glide。现在不需要使用GlideApp

RequestOptions

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

在我的应用程序的gradle.build中:

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

在我的gradle.settings中:

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
}

就这样。


10
投票

Kotlin解决方案:

确保在gradle文件中添加以下内容(用kapt android.enableJetifier=true android.useAndroidX=true 替换annotationProcessor):

source

在您的应用程序repositories { mavenCentral() google() } dependencies { implementation 'com.github.bumptech.glide:glide:4.8.0' kapt 'com.github.bumptech.glide:compiler:4.8.0' } 中添加AppGlideModule实现(您可以覆盖默认方法GlideSource):

overrideSource

使用滑行时,使用GlideApp而不是Glide,例如:

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).signature(ObjectKey(System.currentTimeMillis().toShort())) }
    }

}

4
投票

我用qxxswpoi和AndroidX面对这个问题 这样解决了

在你的gradle.properties中 GlideApp.with(context) .load(url) .into(imageView) Glide:4.9.0

在你的build.gradle中 android.useAndroidX = true

然后添加你的android.enableJetfier=true //Glide dependency implementation 'com.github.bumptech.glide:glide:4.9.0' annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'

最后一步生成GlideModule 构建>>制作项目,您应该在构建文件夹中看到生成的模块


0
投票

除了Ridhi的答案:

为了让它正常工作,我必须包括CustomGlideModule

@GlideModule
public class CustomeGlideModule extends AppGlideModule {}
© www.soinside.com 2019 - 2024. All rights reserved.