Add plugin for LeakCanary 2 (#1959)
Summary: Add plugin for LeakCanary 2 as requested various times: https://github.com/facebook/flipper/issues/1379 https://github.com/facebook/flipper/issues/832 https://github.com/square/leakcanary/issues/1777 ## Changelog * Adds a leakcanary2 plugin for Android * Adds support for leakcanary2 to existing desktop plugin Pull Request resolved: https://github.com/facebook/flipper/pull/1959 Test Plan: * Docs updated to show new implementation * Should old leakcanary plugin in sample be replaced? Reviewed By: mweststrate Differential Revision: D26691637 Pulled By: passy fbshipit-source-id: 5e236fa6cc124f0720a6b21b5ee7c117ccf96fbf
This commit is contained in:
committed by
Facebook GitHub Bot
parent
61eabf372a
commit
4d8be35d1a
49
docs/setup/leak-canary-2-plugin.mdx
Normal file
49
docs/setup/leak-canary-2-plugin.mdx
Normal file
@@ -0,0 +1,49 @@
|
||||
---
|
||||
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-leakcanary2-plugin:0.76.0'
|
||||
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.6'
|
||||
}
|
||||
```
|
||||
|
||||
Update your the `onCreate` method in you `Application` to add the LeakCanary2 plugin to Flipper and the Flipper listener to LeakCanary
|
||||
|
||||
```kt
|
||||
import com.facebook.flipper.plugins.leakcanary2.FlipperLeakListener
|
||||
import com.facebook.flipper.plugins.leakcanary2.LeakCanary2FlipperPlugin
|
||||
|
||||
...
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
setupFlipper()
|
||||
|
||||
/*
|
||||
set the flipper listener in leak canary config
|
||||
*/
|
||||
LeakCanary.config = LeakCanary.config.copy(
|
||||
onHeapAnalyzedListener = FlipperLeakListener()
|
||||
)
|
||||
|
||||
SoLoader.init(this, false)
|
||||
|
||||
if (BuildConfig.DEBUG && FlipperUtils.shouldEnableFlipper(this)) {
|
||||
val client = AndroidFlipperClient.getInstance(this)
|
||||
/*
|
||||
add leak canary plugin to flipper
|
||||
*/
|
||||
client.addPlugin(LeakCanary2FlipperPlugin())
|
||||
client.start()
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
That's it!
|
||||
Reference in New Issue
Block a user