Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add leakcanary to Android library project? #182

Closed
hidroh opened this issue Jun 12, 2015 · 3 comments
Closed

Add leakcanary to Android library project? #182

hidroh opened this issue Jun 12, 2015 · 3 comments

Comments

@hidroh
Copy link

hidroh commented Jun 12, 2015

This may be related to #9. Our setup is a multi-project Gradle build, where multiple Android application projects depend on a common Android library project (which we want to use leakcanary to verify leaks).

I was trying to add leakcanary to a library project when I realized that Gradle only builds release variant of library projects, which is a known Gradle Android plugin issue, which means leakcanary-android-no-op would be built instead of leakcanary-android if we include leakcanary in our library project as follows:

dependencies {
    ...
    debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1'
    releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1'
}

Forcing Gradle Android plugin to publish library as 'debug' of course works, but that would affect our 'release' setup.

android {
    defaultPublishConfig "debug"
}

Another workaround would be to always compile leakcanary-android, and then exclude leakcanary logic based on some build type specific configuration during runtime, but that would defeat the purpose of having leakcanary-android-no-op.

dependencies {
    ...
    compile 'com.squareup.leakcanary:leakcanary-android:1.3.1'
}
if (debug) {
    LeakCanary.install(this);
}

Have anyone encountered the same problem? Any other workarounds?

@iNoles
Copy link

iNoles commented Jun 12, 2015

Did you try with Android Studio? in latest version of Android Studio, I see my library set to debug in the build variant panel.

@GabrielCastro
Copy link

You can depend on a none default config of a library, ie.

app.gradle

dependencies {
    debugCompile project(path: ':appslib', configuration: 'debug')
    releaseCompile project(path: ':appslib', configuration: 'release')
}

@hidroh
Copy link
Author

hidroh commented Jun 15, 2015

Damn, I missed that one. Thanks. The above configuration works, provided the library is configured with

android {
    publishNonDefault true
}

@hidroh hidroh closed this as completed Jun 15, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants