Should I remove the leakage code / classes for the release build?
I have searched for an answer to this question and could not find anything, which probably means his main question. At the risk of showing my ignorance, I will ask anyway. I am preparing my app for release and want to insure a Canary leak that is not showing up for my users. My addictions are leaking as such.
dependencies {
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5'
testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5'
}
I think that since releaseCompile contains no-op
, it means I can continue building the release since it does not remove the Can Canary code. I'm right?
source to share
I found this online.
dependencies {
// Real LeakCanary for debug builds only: notifications, analysis, etc
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1'
// No-Op version of LeakCanary for release builds: no notifications, no analysis, nothing
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1'
}
source to share
I was using the latest 2.0-alpha-1 library in debug mode and I could not find the library release dependencies. I did the following:
- I created separate folders for each build mode (release and debug)
- Debug folder path: app / src / debug
- Release folder path: app / src / release
Then I created a class to initialize the canary leak called LeakCanaryInitializer.kt (I created it inside two build folders)
- debug: app / src / debug / java / LeakCanaryInitializer.kt
- release: app / src / release / java / LeakCanaryInitializer.kt
The class in release mode contains:
import android.content.Context
object LeakCanaryManager {
fun init(context: Context) {
// We should do nothing in the release mode
}
}
The class in debug mode contains:
import android.content.Context
import leakcanary.LeakCanary
import leakcanary.LeakSentry
object LeakCanaryManager {
fun init(context: Context) {
// Here you should write your custom initializing
}
}
Then, in your application class, call the init method:
LeakCanaryManager.init(this)
My Gradle file only contains the debug dependency:
debugImplementation "com.squareup.leakcanary:leakcanary-android:2.0-alpha-1"
source to share