Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 843
szidijani Avatar asked Jul 13 '15 09:07

szidijani


People also ask

How do I add plugins to Gradle settings?

For a plugin that is applied in the settings. gradle file you have three options: declare the plugin class directly in the settings. gradle file (not that useful for production but good for testing) * declare the plugin in the buildSrc project * resolve the plugin as a third party dependency.

What is the use of apply plugin in Gradle?

This plugin will change the name of the APK, move the APK to your desired location, and create a text file in which it'll add all the dependencies for all the APKs you've created through the plugin. In the process, you'll learn about the following topics: Gradle tasks.

What are Buildtypes and product Flavours in Gradle?

Build variants are the result of Gradle using a specific set of rules to combine settings, code, and resources configured in your build types and product flavors. Although you do not configure build variants directly, you do configure the build types and product flavors that form them.

What is plugin base in Gradle?

The Base Plugin adds the base extension to the project. This allows to configure the following properties inside a dedicated DSL block. Example 2. Using the base extension. build.gradle.


1 Answers

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.

like image 78
Pavel Santaev Avatar answered Oct 04 '22 16:10

Pavel Santaev