Leakcanary: build.gradle recipe for different productFlavors

Created on 17 Jul 2019  路  4Comments  路  Source: square/leakcanary

Hey there, I know that this is quite common to do, but I think that would be good a small recipe on how to setup LeakCanary for different product flavors on build.gradle.

[EDIT] Sorry about the "Hey guys, my bad.

documentation

All 4 comments

Thanks, that's an interesting idea!

Can you provide me with examples of why you'd want a different LeakCanary configuration depending on the product flavors? What is it that you (or someone) might be trying to achieve?

Note: "Hey guys" is not an inclusive statement and we refrain from using it in this community. Thanks!

The reason that I want a different configuration for the LeakCanary is that we have 3 product flavors in our project, dev, qa and prod. By setting the default debugImplementation for LeakCanary it will run on every debug product flavor, but our QA team ask us to disable LeakCanary for them because it was impacting some test scenarios, and also we have to record a demo for the client and for that we want the LeakCanary disabled too. Here is how I did it.

  • Define the Flavors for your app:
flavorDimensions "app"
    productFlavors {
        dev {}
        qa {}
        prod {}
    }
  • Define a custom configuration for which flavor do you want to enable LeakCanary
configurations {
    devDebugImplementation {}
}
...
dependencies {}
  • Add LeakCanary dependency using the defined configuration
devDebugImplementation 'com.squareup.leakcanary:leakcanary-android:<current_version>'

Looks like this could be a good contribution to https://github.com/square/leakcanary/blob/master/docs/recipes.md . Feel free to open a PR :)

Merged, published on next release.

Was this page helpful?
0 / 5 - 0 ratings