Glide showing error: Failed to find GeneratedAppGlideModule

烂漫一生 提交于 2019-11-29 05:45:06
Riddhi

Finally, I found my answer here.

What I have done :

Step-1

I created an empty class named GlideApp

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.settings:

android.enableJetifier=true
android.useAndroidX=true

That's all.

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 (You may override the default methods overrideSource):

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

}


While using glide, use GlideApp instead of Glide, example:

GlideApp.with(context)
            .load(url)
            .into(imageView)

I have faced this issue with Glide:4.9.0 with AndroidX
solved it like this

In your gradle.properties
android.useAndroidX = true
android.enableJetfier=true

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

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

}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!