简体   繁体   English

由于 org.junit.Test class 在外部库中的依赖性,无法使用 LeakCanary

[英]Can't use LeakCanary because of org.junit.Test class dependency in external libraries

I'm trying to use LeakCanary for finding memory leaks in my Android application.我正在尝试使用 LeakCanary 在我的 Android 应用程序中查找 memory 泄漏。 I'm using Android Studio.我正在使用 Android Studio。

When I start debugging my application I see "LeakCanary is currently disabled: test class org.junit.Test was found in classpath."当我开始调试我的应用程序时,我看到“LeakCanary 当前已禁用:测试 class org.junit.Test 已在类路径中找到。” message.信息。

"org.junit.test" class came from external library. “org.junit.test” class 来自外部图书馆。

How can I force enable LeakCanary?如何强制启用 LeakCanary?

LeakCanary automatically disables itself in tests by detecting that the org.junit.Test is in the classpath. LeakCanary 通过检测org.junit.Test在类路径中,自动在测试中禁用自身。 Unfortunately, some apps ship Junit in their app debug classpath (eg when using OkHttp MockWebServer).不幸的是,一些应用程序在其应用程序调试类路径中提供 Junit(例如,当使用 OkHttp MockWebServer 时)。 You can customize which class is used to detect tests:您可以自定义使用哪个 class 来检测测试:

<resources>
  <string name="leak_canary_test_class_name">assertk.Assert</string>
</resources>

The doc needs to be updated (tracked here: https://github.com/square/leakcanary/issues/1968 )该文档需要更新(在此处跟踪: https://github.com/square/leakcanary/issues/1968

Sometimes it helps to check your module build.gradle file and find "implementation" instead of "testImplementation" or "androidTestImplementation" for test dependencies.有时它有助于检查您的模块 build.gradle 文件并找到“实现”而不是“testImplementation”或“androidTestImplementation”来测试依赖项。 It may cause this issue.它可能会导致此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM