I recently update my app to use Glide 4, to be precise, Glide 4.2.0. gradle:
compile 'com.github.bumptech.glide:glide:4.2.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.2.0'
compile ('com.github.bumptech.glide:okhttp3-integration:4.2.0'){
exclude group: 'glide-parent'
}
in manifest:
<meta-data
android:name="com.xxx.MyGlideModule"
android:value="GlideModule"/>
GlideModule class:
@GlideModule
public class MyGlideModule extends AppGlideModule {
@Override
public void registerComponents(Context context, Glide glide, Registry registry) {
OkHttpClient client = new OkHttpClient.Builder()
.readTimeout(30, TimeUnit.SECONDS)
.writeTimeout(30, TimeUnit.SECONDS)
.connectTimeout(30, TimeUnit.SECONDS)
.build();
OkHttpUrlLoader.Factory factory = new OkHttpUrlLoader.Factory(client);
glide.getRegistry().replace(GlideUrl.class, InputStream.class, factory);
}
}
how I use glide inside an adapter:
RequestOptions myOptions = new RequestOptions()
.placeholder(R.drawable.ic_placeholder)
.diskCacheStrategy(DiskCacheStrategy.NONE)
.dontAnimate()
.skipMemoryCache(true)
;
Glide.with(mContext)
.load(Imageid[position])
.apply(myOptions)
.into(imageView);
with these code, when I run it I got error:
java.lang.RuntimeException: Expected instanceof GlideModule, but found: [my app package].MyGlideModule@d1c2328
at com.bumptech.glide.module.ManifestParser.parseModule(ManifestParser.java:81)
at com.bumptech.glide.module.ManifestParser.parse(ManifestParser.java:43)
at com.bumptech.glide.Glide.initializeGlide(Glide.java:193)
at com.bumptech.glide.Glide.checkAndInitializeGlide(Glide.java:172)
at com.bumptech.glide.Glide.get(Glide.java:156)
at com.bumptech.glide.Glide.getRetriever(Glide.java:540)
at com.bumptech.glide.Glide.with(Glide.java:566)
at [adapter line where I implement Glide]
how can I use MyGlideModule ?
Glide 4.0 need not have declare "GlideModule" in AndroidManifest.xml. You just need to following steps:
applyOptions
in the YourGlideModule class.GlideApp
class.GlideApp.with(this).load(imgUrl).into(glide_test_iv1)
If GlideApp
can't be generated then -
Make sure you have build.gradle
dependency of annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
Make sure your UnsafeOkHttpGlideModule
extends AppGlideModule
and also in meta-data
the android:value=""
should be android:value="AppGlideModule"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With