androidandroid-studiogradlenewrelicandroid-productflavors

How to apply plugin to only one flavor in gradle?


I have a multi-flavored, multi-build-typed android project and I want to integrate the NewRelic plugin. But I have to apply it only for one of the customers, thus only for one product flavor.
NewRelic uses instrumentation and the plugin would generate code in other flavors if I applied the plugin there, and that is not permitted for us.

So my question is: How can I use the apply plugin: something command in the gradle file to be applied to only one of my flavors?


Solution

  • Use this code:

    if (!getGradle().getStartParameter().getTaskRequests()
            .toString().contains("Develop")){
        apply plugin: 'com.google.gms.google-services'
    }
    

    getGradle().getStartParameter().getTaskRequests().toString() returns something like [DefaultTaskExecutionRequest{args=[:app:generateDevelopDebugSources],projectPath='null'}] so as stated in the comments Develop must start with an uppercase.