添加依赖:
佳姝1:在项目的build.gradle中添加以下依赖
debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.6.1'
releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.6.1'
// Optional, if you use support library fragments:
debugImplementation 'com.squareup.leakcanary:leakcanary-support-fragment:1.6.1'
佳姝2:自定义MyApp类继承Application,注意记得在manifests清单文件中的application{
android:name=".App"
}
声明此类
public RefWatcher refWatcher; @Override public void onCreate() { super.onCreate(); refWatcher = setupLeakCanary(); } private RefWatcher setupLeakCanary() { if (LeakCanary.isInAnalyzerProcess(this)) { return RefWatcher.DISABLED; } return LeakCa