LeakCanary使用官网
2020-08-03 20:17:38.046 2561-2561/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.yixuepai, PID: 2561
java.lang.Error: LeakCanary in non-debuggable build
LeakCanary should only be used in debug builds, but this APK is not debuggable.
Please follow the instructions on the "Getting started" page to only include LeakCanary in
debug builds: https://square.github.io/leakcanary/getting_started/
If you're sure you want to include LeakCanary in a non-debuggable build, follow the
instructions here: https://square.github.io/leakcanary/recipes/#leakcanary-in-release-builds
at leakcanary.internal.InternalLeakCanary.checkRunningInDebuggableBuild(Unknown Source:28)
at leakcanary.internal.InternalLeakCanary.invoke(Unknown Source:6)
at leakcanary.internal.InternalLeakCanary.invoke(Unknown Source:2)
at leakcanary.internal.AppWatcherInstaller.onCreate(:11)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1949)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1923)
at android.app.ActivityThread.installProvider(ActivityThread.java:7273)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:6813)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6699)
at android.app.ActivityThread.access$2000(ActivityThread.java:273)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2020)
at android.os.Handler.dispatchMessage(Handler.java:112)
at android.os.Looper.loop(Looper.java:216)
at android.app.ActivityThread.main(ActivityThread.java:7625)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987)
出现的原因是: 你的buildType除了debug和release外还有其他的构建类型(比如stage test dev等等)
解决的办法就是任意的资源文件增加一行代码:
<bool name="leak_canary_allow_in_non_debuggable_build">truebool>