Files
flipper/docs/setup/leak-canary-plugin.mdx
generatedunixname89002005306973 bd320b94e1 Flipper Release: v0.40.0
Summary: Releasing version 0.40.0

Reviewed By: nikoant

Differential Revision: D21302037

fbshipit-source-id: 2f2aeaf0aaf7a0d2fb65b21b6243c9ecd2684cdc
2020-04-29 08:33:04 -07:00

40 lines
1.2 KiB
Plaintext

---
id: leak-canary-plugin
title: LeakCanary Setup
sidebar_label: LeakCanary
---
Ensure that you already have an explicit dependency in your application's
`build.gradle` including the plugin dependency, e.g.
```groovy
dependencies {
debugImplementation 'com.facebook.flipper:flipper-leakcanary-plugin:0.40.0'
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:
```java
import com.facebook.flipper.plugins.leakcanary.LeakCanaryFlipperPlugin;
client.addPlugin(new LeakCanaryFlipperPlugin());
```
Next, build a custom RefWatcher using RecordLeakService: (see [LeakCanary docs](https://github.com/square/leakcanary/wiki/Customizing-LeakCanary#uploading-to-a-server) for more information on RefWatcher)
```java
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.
```xml
<service android:name="com.facebook.flipper.plugins.leakcanary.RecordLeakService" />
```