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?
Tried different solutions, but none of them worked for me. This is what I came up with and seems to work as far as I tested:
build.gradle
And outside the configuration, inside the
build.gradle
file:Use this code:
getGradle().getStartParameter().getTaskRequests().toString()
returns something like[DefaultTaskExecutionRequest{args=[:app:generateDevelopDebugSources],projectPath='null'}]
so as stated in the commentsDevelop
must start with an uppercase.I found a solution, but it is not the best so far. So I'm not sure anymore, that what I wanted to do initially is possible. The gradle file evaluation and the choosing of the right flavor and build type is in different phases of the gradle build, so what I've done is:
I use a build parameter from the command line. When that paramerer is true, I apply the plugin, when it is not even there, I also apply it (for IDE build). I use Jenkins, so I could write that parameter in the build job.
build.gradle file:
And you have to run the gradle build by this:
def fl
Initialize variable in you Flavours (and/or builds)
Use if statement -
if (fl == "free") { apply plugin: something }