Can’t use LeakCanary because of org.junit.Test class dependency in external libraries

Tags: , ,



I’m trying to use LeakCanary for finding memory leaks in my Android application. I’m using Android Studio.

When I start debugging my application I see “LeakCanary is currently disabled: test class org.junit.Test was found in classpath.” message.

“org.junit.test” class came from external library.

How can I force enable LeakCanary?

Answer

LeakCanary automatically disables itself in tests by detecting that the org.junit.Test is in the classpath. Unfortunately, some apps ship Junit in their app debug classpath (e.g. when using OkHttp MockWebServer). You can customize which class is used to detect tests:

<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)



Source: stackoverflow