我正在尝试运行泄漏金丝雀和我的Android仪器测试。我遵循了LeakCanary的文档https://square.github.io/leakcanary/upgrading-to-leakcanary-2.0/#running-仪器测试中的泄漏
但是,仪器测试应用程序无法启动,出现以下错误:
java.lang.RuntimeException: Exception thrown in onCreate() of ComponentInfo{<app component>/androidx.test.runner.AndroidJUnitRunner}: java.lang.IllegalArgumentException: Could not find extra class com.squareup.leakcanary.FailTestOnLeakRunListener
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6709)
at android.app.ActivityThread.access$1300(ActivityThread.java:237)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1913)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
我的建筑中有以下内容。gradle:
dependencies {
compileOnly 'org.projectlombok:lombok:1.18.12'
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.annotation:annotation:1.0.0'
implementation 'androidx.core:core:1.0.0'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.github.bumptech.glide:glide:4.6.1'
testImplementation 'junit:junit:4.12'
testImplementation 'org.robolectric:robolectric:4.2'
testImplementation 'org.robolectric:shadows-httpclient:4.2'
testImplementation 'androidx.test:core:1.1.0'
testImplementation 'org.mockito:mockito-core:2.25.0'
androidTestImplementation 'org.mockito:mockito-core:2.25.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.annotation:annotation:1.0.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test:rules:1.1.1'
androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
androidTestImplementation 'com.linkedin.dexmaker:dexmaker:2.25.0'
androidTestImplementation 'com.linkedin.dexmaker:dexmaker-mockito:2.25.0'
testImplementation 'com.squareup.leakcanary:leakcanary-android:2.9.1'
androidTestImplementation 'com.squareup.leakcanary:leakcanary-android-instrumentation:2.9.1'
androidTestUtil 'androidx.test:orchestrator:1.1.1'
api "com.google.auto.value:auto-value-annotations:1.7"
api 'com.google.guava:guava:27.0.1-jre'
annotationProcessor "com.google.auto.value:auto-value:1.7"
annotationProcessor 'org.projectlombok:lombok:1.18.12'
}
android {
compileSdkVersion 31
ndkVersion "23.0.7599858"
buildToolsVersion "30.0.2"
defaultConfig {
minSdkVersion 22
targetSdkVersion 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunnerArguments clearPackageData: 'true'
testInstrumentationRunnerArgument "listener", "com.squareup.leakcanary.FailTestOnLeakRunListener"
renderscriptTargetApi 22
}
}
如有任何帮助或建议,我们将不胜感激。
这是一个已修复的文档问题。
https://github.com/square/leakcanary/issues/2409