【问题标题】:Can't use LeakCanary because of org.junit.Test class dependency in external libraries由于外部库中的 org.junit.Test 类依赖关系,无法使用 LeakCanary
【发布时间】:2020-12-02 23:05:55
【问题描述】:

我正在尝试使用 LeakCanary 来查找我的 Android 应用程序中的内存泄漏。我正在使用 Android Studio。

当我开始调试我的应用程序时,我看到“LeakCanary 当前已禁用:在类路径中找到测试类 org.junit.Test。”消息。

“org.junit.test”类来自外部库。

如何强制启用 LeakCanary?

【问题讨论】:

标签: java android leakcanary


【解决方案1】:

LeakCanary 通过检测org.junit.Test 在类路径中自动禁用自身。不幸的是,一些应用程序在他们的应用程序调试类路径中提供了 Junit(例如,当使用 OkHttp MockWebServer 时)。您可以自定义使用哪个类来检测测试:

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

文档需要更新(在此处跟踪:https://github.com/square/leakcanary/issues/1968

【讨论】:

  • 抱歉,这个自定义会做什么?
【解决方案2】:

有时检查您的模块 build.gradle 文件并为测试依赖项找到“实现”而不是“testImplementation”或“androidTestImplementation”会有所帮助。这可能会导致此问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-09-22
    • 2020-10-14
    • 2010-11-08
    • 1970-01-01
    • 2010-12-14
    • 2017-04-23
    • 2022-01-02
    相关资源
    最近更新 更多