java.lang.IllegalArgumentException:无法找到GlideModule实现

时间:2018-10-24 07:42:52

标签: android android-glide

我想在我的App中使用 Glide4 ,我编写了一些代码参考在线教程,但出现了错误:

 E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.zhiyun.mirror, PID: 7481
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.zhiyun.mirror/com.zhiyun.mirror.mxg.activity.HappyMainActivity}: java.lang.IllegalArgumentException: Unable to find GlideModule implementation
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2666)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2727)
        at android.app.ActivityThread.-wrap12(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1478)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6121)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:795)
     Caused by: java.lang.IllegalArgumentException: Unable to find GlideModule implementation
        at com.bumptech.glide.module.ManifestParser.parseModule(ManifestParser.java:68)
        at com.bumptech.glide.module.ManifestParser.parse(ManifestParser.java:46)
        at com.bumptech.glide.Glide.initializeGlide(Glide.java:228)
        at com.bumptech.glide.Glide.initializeGlide(Glide.java:219)
        at com.bumptech.glide.Glide.checkAndInitializeGlide(Glide.java:180)
        at com.bumptech.glide.Glide.get(Glide.java:164)
        at com.bumptech.glide.Glide.getRetriever(Glide.java:670)
        at com.bumptech.glide.Glide.with(Glide.java:697)
        at com.zhiyun.mirror.mxg.util.DreamGoImageLoader.displayImage(DreamGoImageLoader.java:13)
        at com.zhiyun.mirror.mxg.util.DreamGoImageLoader.displayImage(DreamGoImageLoader.java:9)
        at com.youth.banner.Banner.setImageList(Banner.java:354)
        at com.youth.banner.Banner.start(Banner.java:262)
        at com.zhiyun.mirror.mxg.activity.HappyMainActivity.initBanner(HappyMainActivity.java:178)
        at com.zhiyun.mirror.mxg.activity.HappyMainActivity.onCreate(HappyMainActivity.java:128)
        at android.app.Activity.performCreate(Activity.java:6709)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2619)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2727) 
        at android.app.ActivityThread.-wrap12(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1478) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:154) 
        at android.app.ActivityThread.main(ActivityThread.java:6121) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:795) 
     Caused by: java.lang.ClassNotFoundException: com.newear.base.glide.MyGlideModule
        at java.lang.Class.classForName(Native Method)
        at java.lang.Class.forName(Class.java:400)
        at java.lang.Class.forName(Class.java:326)
        at com.bumptech.glide.module.ManifestParser.parseModule(ManifestParser.java:66)
        at com.bumptech.glide.module.ManifestParser.parse(ManifestParser.java:46) 
        at com.bumptech.glide.Glide.initializeGlide(Glide.java:228) 
        at com.bumptech.glide.Glide.initializeGlide(Glide.java:219) 
        at com.bumptech.glide.Glide.checkAndInitializeGlide(Glide.java:180) 
        at com.bumptech.glide.Glide.get(Glide.java:164) 
        at com.bumptech.glide.Glide.getRetriever(Glide.java:670) 
        at com.bumptech.glide.Glide.with(Glide.java:697) 
        at com.zhiyun.mirror.mxg.util.DreamGoImageLoader.displayImage(DreamGoImageLoader.java:13) 
        at com.zhiyun.mirror.mxg.util.DreamGoImageLoader.displayImage(DreamGoImageLoader.java:9) 
        at com.youth.banner.Banner.setImageList(Banner.java:354) 
        at com.youth.banner.Banner.start(Banner.java:262) 
        at com.zhiyun.mirror.mxg.activity.HappyMainActivity.initBanner(HappyMainActivity.java:178) 
        at com.zhiyun.mirror.mxg.activity.HappyMainActivity.onCreate(HappyMainActivity.java:128) 
        at android.app.Activity.performCreate(Activity.java:6709) 
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2619) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2727) 
        at android.app.ActivityThread.-wrap12(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1478) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:154) 
        at android.app.ActivityThread.main(ActivityThread.java:6121) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:795) 
     Caused by: java.lang.ClassNotFoundException: Didn't find class "com.newear.base.glide.MyGlideModule" on path: DexPathList[[zip file "/data/app/com.zhiyun.mirror-2/base.apk"],nativeLibraryDirectories=[/data/app/com.zhiyun.mirror-2/lib/arm, /data/app/com.zhiyun.mirror-2/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at java.lang.Class.classForName(Native Method) 
        at java.lang.Class.forName(Class.java:400) 
        at java.lang.Class.forName(Class.java:326) 
        at com.bumptech.glide.module.ManifestParser.parseModule(ManifestParser.java:66) 
        at com.bumptech.glide.module.ManifestParser.parse(ManifestParser.java:46) 
        at com.bumptech.glide.Glide.initializeGlide(Glide.java:228) 
        at com.bumptech.glide.Glide.initializeGlide(Glide.java:219) 
        at com.bumptech.glide.Glide.checkAndInitializeGlide(Glide.java:180) 
        at com.bumptech.glide.Glide.get(Glide.java:164) 
        at com.bumptech.glide.Glide.getRetriever(Glide.java:670) 
        at com.bumptech.glide.Glide.with(Glide.java:697) 
        at com.zhiyun.mirror.mxg.util.DreamGoImageLoader.displayImage(DreamGoImageLoader.java:13) 
        at com.zhiyun.mirror.mxg.util.DreamGoImageLoader.displayImage(DreamGoImageLoader.java:9) 
        at com.youth.banner.Banner.setImageList(Banner.java:354) 
        at com.youth.banner.Banner.start(Banner.java:262) 
        at com.zhiyun.mirror.mxg.activity.HappyMainActivity.initBanner(HappyMainActivity.java:178) 
        at com.zhiyun.mirror.mxg.activity.HappyMainActivity.onCreate(HappyMainActivity.java:128) 
        at android.app.Activity.performCreate(Activity.java:6709) 
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2619) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2727) 
        at android.app.ActivityThread.-wrap12(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1478) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:154) 
        at android.app.ActivityThread.main(ActivityThread.java:6121) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:795) 

base模块的 build.gradle 中:

dependencies {
    api `com.github.bumptech.glide:glide:4.5.0`
    annotationProcessor `com.github.bumptech.glide:compiler:4.5.0`
}

在我的 build.gradle 中的“应用”模块中:

dependencies {
    annotationProcessor `com.github.bumptech.glide:compiler:4.5.0`
}

我的代码在app模块中:

import com.bumptech.glide.annotation.GlideModule;
import com.bumptech.glide.module.AppGlideModule;

@GlideModule
public class MyGlideModule extends AppGlideModule {

}

用法:

public void displayImage(Context context, Object path, ImageView imageView) {

        GlideApp.with(context).load(path).into(imageView);
}

我不知道为什么会这样,我已经尝试了多种方法,但是似乎都没有。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

当我升级android studio时,我遇到了同样的问题,所以对我来说,我使用gradle 4.4,对于gradle插件我使用3.1.4

 @GlideModule
   class GlideModule : AppGlideModule() {
   }

将此添加到您的build.gradle

  implementation 'com.github.bumptech.glide:glide:4.8.0'
  kapt 'com.github.bumptech.glide:compiler:4.8.0'

kotlin中的kapt类似于Java中的注解处理器,GLIDE模块将自动生成