Files
flipper/docs/setup/leak-canary-plugin.md
Pascal Hartig 60e13335dc Flipper Release: v0.33.1
Summary: Re-release of 0.33.0.

Reviewed By: mweststrate

Differential Revision: D20344545

fbshipit-source-id: 38fd5baa8d36bc7cfa9a66a15144078e7b1f53c3
2020-03-09 15:12:37 -07:00

1.2 KiB

id, title, sidebar_label
id title sidebar_label
leak-canary-plugin LeakCanary Setup LeakCanary

Ensure that you already have an explicit dependency in your application's build.gradle including the plugin dependency, e.g.

dependencies {
  debugImplementation 'com.facebook.flipper:flipper-leakcanary-plugin:0.33.1'
  debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.6.1'
  releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.6.1'
}

First, add the plugin to your Flipper client instance:

import com.facebook.flipper.plugins.leakcanary.LeakCanaryFlipperPlugin;

client.addPlugin(new LeakCanaryFlipperPlugin());

Next, build a custom RefWatcher using RecordLeakService: (see LeakCanary docs for more information on RefWatcher)

import com.facebook.flipper.plugins.leakcanary.RecordLeakService;

RefWatcher refWatcher = LeakCanary.refWatcher(this)
    .listenerServiceClass(RecordLeakService.class)
    .buildAndInstall();

Then, add the RecordLeakService in your debug variant AndroidManifest.xml.

<service android:name="com.facebook.flipper.plugins.leakcanary.RecordLeakService" />