如果错误地实现了GeneratedAppGlideModuleImpl错误,则在AndroidX中实现Glide 4.10.0

时间:2019-10-19 00:37:27

标签: java android android-glide androidx

我在AndroidX中实现Glide 4.10.0时遇到问题,我遵循了文档,但仍然遇到错误。请帮我在Glide中学习新内容!

我的proguard-rules.pro代码

-keep public class * implements com.bumptech.glide.module.GlideModule

-keep public class * extends com.bumptech.glide.module.AppGlideModule

-keep public enum com.bumptech.glide.load.ImageHeaderParser$** {
  **[] $VALUES;
  public *;
}

-keepresourcexmlelements manifest/application/meta-data@value=GlideModule

我的build.gradle代码

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

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

我的代码

Glide.with(ctx).load("https://lh6.ggpht.com/9SZhHdv4URtBzRmXpnWxZcYhkgTQurFuuQ8OR7WZ3R7fyTmha77dYkVvcuqMu3DLvMQ=w300").into(img);

错误消息

W/System.err: java.lang.IllegalStateException: GeneratedAppGlideModuleImpl is implemented incorrectly. If you've manually implemented this class, remove your implementation. The Annotation processor will generate a correct implementation.
        at com.bumptech.glide.Glide.throwIncorrectGlideModule(Glide.java:341)
        at com.bumptech.glide.Glide.getAnnotationGeneratedGlideModules(Glide.java:333)
        at com.bumptech.glide.Glide.get(Glide.java:176)
        at com.bumptech.glide.Glide.getRetriever(Glide.java:714)
        at com.bumptech.glide.Glide.with(Glide.java:741)
        at com.ind.projecttest.util.Tools.displayCircularImageViewOriginal(Tools.java:62)
        at com.ind.projecttest.activity.MainActivity.setupLayoutValue(MainActivity.java:101)
        at com.ind.projecttest.activity.MainActivity.access$500(MainActivity.java:54)
        at com.ind.projecttest.activity.MainActivity$4.onResponse(MainActivity.java:305)
        at com.ind.projecttest.activity.MainActivity$4.onResponse(MainActivity.java:296)
        at com.android.volley.toolbox.JsonRequest.deliverResponse(JsonRequest.java:90)
        at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:102)
W/System.err:     at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:201)
        at android.app.ActivityThread.main(ActivityThread.java:6810)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
    Caused by: java.lang.NoSuchMethodException: <init> [class android.content.Context]
        at java.lang.Class.getConstructor0(Class.java:2327)
        at java.lang.Class.getDeclaredConstructor(Class.java:2166)
        at com.bumptech.glide.Glide.getAnnotationGeneratedGlideModules(Glide.java:317)
        ... 17 more
I/f.indsmartmobil: ProcessProfilingInfo new_methods=1978 is saved saved_to_disk=1 resolve_classes_delay=8000
W/DpmTcmClient: read failed bytes countRead: -1

1 个答案:

答案 0 :(得分:0)

在我的自定义AppGlideModule类中添加 @Keep 注释对我来说很有效。

@Keep
@GlideModule
class AppGlideModule : AppGlideModule() {

}