testCoverageEnabled = false崩溃App

时间:2018-04-09 16:42:31

标签: android android-gradle jacoco

我遇到无法调试局部变量的情况,因为在我的gradle文件中我有testCoverageEnabled true。许多帖子都正确地建议将其设置为false。我遇到的问题是,当我这样做时,我的应用程序崩溃了以下堆栈跟踪:

E/AndroidRuntime: FATAL EXCEPTION: main
                  Process: com.MyApp.pr.redesign.app, PID: 22172
                  java.lang.NoClassDefFoundError: Failed resolution of: Lorg/jacoco/agent/rt/internal_773e439/Offline;
                      at com.MyApp.pr.eventcollector.utils.MyAppLog.$jacocoInit(Unknown Source:14)
                      at com.MyApp.pr.eventcollector.utils.Log.<clinit>(Unknown Source:0)
                      at com.MyApp.pr.eventcollector.utils.MyApp.setLevel(Unknown Source:0)
                      at com.MyApp.pr.MyApp.MyApp.setupLogging(MyApp.java:171)
                      at com.MyApp.pr.MyApp.MyApp.onCreate(MyApp.java:71)
                      at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1125)
                      at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6056)
                      at android.app.ActivityThread.-wrap1(Unknown Source:0)
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1764)
                      at android.os.Handler.dispatchMessage(Handler.java:105)
                      at android.os.Looper.loop(Looper.java:164)
                      at android.app.ActivityThread.main(ActivityThread.java:6938)
                      at java.lang.reflect.Method.invoke(Native Method)
                      at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
                   Caused by: java.lang.ClassNotFoundException: Didn't find class "org.jacoco.agent.rt.internal_773e439.Offline" on path: DexPathList[[zip file "/data/app/com.MyApp.pr.redesign.app-FmWSRcYONdAudVVemfy_Bw==/base.apk"],nativeLibraryDirectories=[/data/app/com.MyApp.pr.redesign.app-FmWSRcYONdAudVVemfy_Bw==/lib/arm64, /data/app/com.MyApp.pr.redesign.app-FmWSRcYONdAudVVemfy_Bw==/base.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64]]
                      at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:93)
                      at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
                      at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
                      at com.MyApp.pr.eventcollector.utils.MyApp.$jacocoInit(Unknown Source:14) 
                      at com.MyApp.pr.eventcollector.utils.MyApp.<clinit>(Unknown Source:0) 
                      at com.MyApp.pr.eventcollector.utils.MyApp.setLevel(Unknown Source:0) 
                      at com.MyApp.pr.MyApp.MyApp.setupLogging(MyApp.java:171) 
                      at com.MyApp.pr.MyApp.MyApp.onCreate(MyApp.java:71) 
                      at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1125) 
                      at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6056) 
                      at android.app.ActivityThread.-wrap1(Unknown Source:0) 
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1764) 
                      at android.os.Handler.dispatchMessage(Handler.java:105) 
                      at android.os.Looper.loop(Looper.java:164) 
                      at android.app.ActivityThread.main(ActivityThread.java:6938) 
                      at java.lang.reflect.Method.invoke(Native Method) 
                      at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327) 
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374) 

我认为这与Jacoco有关,但我不确定。任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:0)

我发现问题是因为我们正在使用jacoco进行使用测试:

 testImplementation 'org.jacoco:org.jacoco.agent:0.7.4.201502262128:runtime'

我能够通过添加我在运行时使用的jacoco库来解决此问题:

 implementation 'org.jacoco:org.jacoco.agent:0.7.4.201502262128:runtime'

关键是要确保使用您在应用中使用的 EXACT 相同的库。