添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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

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.

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

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 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">
        <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>
@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);
import com.bumptech.glide.annotation.GlideModule;
import com.bumptech.glide.module.AppGlideModule;
@GlideModule
public class GlideApp extends AppGlideModule {

Note: Don't forget to add annotation @GlideModule.

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

Edit: For androidx and Glide versin 4.9.0:

In my app's 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

In my gradle.properties:

android.enableJetifier=true
android.useAndroidX=true

That's all.

Doesn't seem to work with Glide version 4.9.0. This causes error "cannot resolve method 'with' – ezaspi Jun 19, 2019 at 21:15 @ezaspi if you are using Kotlin, you need to replace annotationProcessor by kapt in your build.gradle dependency. Remember to add apply plugin: "kotlin-kapt" too. Moreover, you are referencing your AppGlideModule implementation but you should use GlideApp instead, – Taynã Bonaldo Jul 4, 2019 at 19:50

Kotlin Solution:

Make sure you are adding the following in your gradle file (replace annotationProcessor with kapt source ):

repositories {
  mavenCentral()
  google()
dependencies {
    implementation 'com.github.bumptech.glide:glide:4.8.0'
    kapt 'com.github.bumptech.glide:compiler:4.8.0'
Add **AppGlideModule** implementation in your application [GlideSource][2] (You may override the default methods [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) }
While using glide, use **GlideApp** instead of **Glide**, example:
GlideApp.with(context)
            .load(url)
            .into(imageView)
                @SpyZip Try rebuilding the app( Build > Rebuild Project) or Invalidate cache ( File > Invalidate Caches / Restart)
– Arshak
                Mar 7, 2019 at 8:51
                @RafaelGuimarães Please check whether you have created an additional file which extends AppGlideModule
– Arshak
                Apr 17, 2019 at 6:43
                @RafaelGuimarães No you shouldn’t name the class that extends AppGlideModule to GlideApp, i tried this and i got a compilation error, so instead rename AppNameGlideModule to whatever your apps name is appended by GlideModule(it’s not mandatory, but for understanding purpose), example: CalculatorGlideModule. After that, first build the project so that files can get generated and then run it.
– Arshak
                Apr 18, 2019 at 8:54
                The "Duplicate Class" error will occur if you name the new class "GlideApp". You should name it something else, for example "MyGlideModule". The class GlideApp will be generated for you.
– Per Christian Henden
                Oct 28, 2019 at 10:33

In your build.gradle
//Glide dependency implementation 'com.github.bumptech.glide:glide:4.9.0' annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'

Then add your CustomGlideModule
@GlideModule public class CustomeGlideModule extends AppGlideModule {}

The final step generates the GlideModule
Build >> Make Project and you should see the generated module in your build folder

@SouravKannanthaB override the applyOptions(Context context, GlideBuilder builder) method. – Vishal Naikawadi Jul 20, 2021 at 18:11

All above answer is True and work fine

but i noticed when use #placeholder and #error method the glide work fine with out build GlideModule class as mentioned above

Example : When use glide like this is not work and give must build GlideModule

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

and this is work fine

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

In addition to Ridhi's Answer:

For me to make it work properly I had to include 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;

in build.gradle (app)

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"

in build.gradle (Project)

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

in your respective Class

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)

build.gradle

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

CustomGlideApp

package com.example.android.common.modules;
import com.bumptech.glide.annotation.GlideModule;
import com.bumptech.glide.module.AppGlideModule;
@GlideModule
public class CustomGlideApp extends AppGlideModule { }

Make Project

Build > Make Project

Using

Observe that GlideApp (generated) is called and not the CustomGlideApp class.

import com.example.android.common.modules.GlideApp;
GlideApp.with()

I also had to face this type of issue like 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.

I have fixed my issue after lots of time.

I made mistake in the XML file I had set the wrong height width of UIImageView that's why glide throw an error.

Please check UIImageView Height-Width Properly.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.