Open maciekjanusz opened 8 years ago
I've used a workaround for this issue thats not perfect but works.
My app has a a internal and a production flavor. All Debug tools are only included in the Internal variant.
The internal flavor has its own Application that extends from my production flavor Application and adds additional devtools that require application initialization in its onCreate()
method.
Gradle however does not support flavor specific plugin applies, this is why we have to use a "hack" by defining a variable, that gets overridden in the flavor configuration. To actually make this work the plugin has to be applied last.
Here is a stripped sample from my build.gradle:
apply plugin: 'com.android.application'
... other plugins ...
// indicates weather devmetrics should be activated or not.
// Override in desired flavor/buildconfig if you want it
def useDevMetrics = false
android {
... general configuration stuff ...
productFlavors {
internal {
... other stuff ...
useDevMetrics = true
}
prod {
... other stuff ...
}
}
}
// This has to be applied here and not on top with the other plugins
// otherwise the flavor configuration was not done and it would never be true resulting in failing builds
if (useDevMetrics) {
apply plugin: 'com.frogermcs.androiddevmetrics'
}
@CaptnBlubber could this be used in buildTypes
to disable certain plugins for the debug variant?
This is not work. On each build, useDevMetrics will be set to true
There should be an option to disable plugin for certain product flavors, for example I use a specialized flavor for instrumented testing, where I need all debug tools to be off, since their notifications and actions might interfere with Espresso tests. Right now, if the plugin is not initialized in
Application
for every debug product flavor, the app will throw a runtime exception:It means that something like this:
is not possible, as the mockDebug build variant will throw the aforementioned exception.