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 option to disable plugin for certain flavors #27

Open
maciekjanusz opened this issue Aug 8, 2016 · 3 comments
Open

Add option to disable plugin for certain flavors #27

maciekjanusz opened this issue Aug 8, 2016 · 3 comments

Comments

@maciekjanusz
Copy link

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:

java.lang.RuntimeException: MethodsTracingManager must be initialized by init(..)

It means that something like this:

if("debug".equals(BuildConfig.BUILD_TYPE) && !"mock".equals(BuildConfig.FLAVOR)) {
    AndroidDevMetrics.initWith(this);
}

is not possible, as the mockDebug build variant will throw the aforementioned exception.

@CaptnBlubber
Copy link

CaptnBlubber commented Jan 3, 2017

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'
}

@rraallvv
Copy link

@CaptnBlubber could this be used in buildTypes to disable certain plugins for the debug variant?

@audiserg
Copy link

audiserg commented Sep 8, 2021

This is not work. On each build, useDevMetrics will be set to true

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

4 participants