在Android检测测试中给出NoClassDefFoundError的Dagger代码,但在普通应用程序中有效

前端之家收集整理的这篇文章主要介绍了在Android检测测试中给出NoClassDefFoundError的Dagger代码,但在普通应用程序中有效前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在 Android应用程序中使用Dagger.
它在应用程序中工作,但是当我运行检测测试时,我得到一个NoClassDefFoundError.

我正在使用Gradle和Espresso.没有progaurd就会发生这种情况.

这很奇怪,因为“Module $$ModuleAdapter”被加载,但“Module $$ModuleAdapter $EndpointProvidesAdapter”却没有.

我将APK从设备中拉回来并使用dexdump验证该类确实在APK中,“Module $$ModuleAdapter $EndpointProvidesAdapter”.

关于可能导致这种情况的任何想法?

java.lang.NoClassDefFoundError: Module$$ModuleAdapter$EndpointProvidesAdapter
            at ...Module$$ModuleAdapter.getBindings(MslModule$$ModuleAdapter.java:33)
            at ...Module$$ModuleAdapter.getBindings(MslModule$$ModuleAdapter.java:13)
            at dagger.ObjectGraph$DaggerObjectGraph.makeGraph(ObjectGraph.java:185)
            at dagger.ObjectGraph$DaggerObjectGraph.access$000(ObjectGraph.java:138)
            at dagger.ObjectGraph.create(ObjectGraph.java:129)
            at ...Application.onCreate(...Application.java:21)
            at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1007)
            at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4344)
            at android.app.ActivityThread.access$1500(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5017)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.ClassNotFoundException: Didn't find class ...Module$$ModuleAdapter$MslEndpointProvidesAdapter" on path: DexPathList[[zip file "/system/framework/android.test.runner.jar",zip file "/data/app/....test-1.apk",zip file "/data/app/...-2.apk"],nativeLibraryDirectories=[/data/app-lib/....test-1,/data/app-lib/...-2,/vendor/lib,/system/lib]]
            at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
at ...Module$$ModuleAdapter.getBindings(MslModule$$ModuleAdapter.java:33)
at ...Module$$ModuleAdapter.getBindings(MslModule$$ModuleAdapter.java:13)
at dagger.ObjectGraph$DaggerObjectGraph.makeGraph(ObjectGraph.java:185)
at dagger.ObjectGraph$DaggerObjectGraph.access$000(ObjectGraph.java:138)
at dagger.ObjectGraph.create(ObjectGraph.java:129)
at ...eApplication.onCreate(...Application.java:21)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1007)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4344)
at android.app.ActivityThread.access$1500(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)

解决方法

Double Espresso现已弃用,转而使用Espresso 2.0.它可能对你有用,因为Jake在枚举传递依赖关系方面做得很好,你可能需要排除这些依赖关系才能让事情发生.

根据我的经验,使用带有Dagger的Espresso 2.0可能需要您从espresso依赖项中排除javax.inject:

androidTestCompile ('com.android.support.test.espresso:espresso-core:2.0') {
    exclude group: 'javax.inject'
}

您可能需要对项目包含的所有espresso依赖项执行此操作.

原文链接:https://www.f2er.com/android/308643.html

猜你在找的Android相关文章