Skip to main content

LeakCanary Plugin Setup

To setup the LeakCanary plugin, take the following steps:

  1. Ensure that you have an explicit dependency in your application's build.gradle including the plugin dependency, such as is shown in the following snippet:
dependencies {
debugImplementation 'com.facebook.flipper:flipper-leakcanary2-plugin:0.273.0'
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.8.1'
}
  1. Update your the onCreate method in you Application to add the LeakCanary2 plugin to Flipper and the Flipper listener to LeakCanary:
import com.facebook.flipper.plugins.leakcanary2.FlipperLeakEventListener
import com.facebook.flipper.plugins.leakcanary2.LeakCanary2FlipperPlugin

...

override fun onCreate() {
super.onCreate()

/*
set the flipper listener in leak canary config
*/
LeakCanary.config = LeakCanary.config.run {
copy(eventListeners = eventListeners + FlipperLeakEventListener())
}

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()
}
}