How to Apply Plugin to Only One Flavor in Gradle

How to apply plugin to only one flavor in gradle?

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.

gradle: apply plugin only for specific flavor

In your build.gradle(App)file add this code:

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

N.B.: First letter of flavor name must be in Uppercase

Update 2021-11-23: Please note the solution by Prasoon Abhishek below.

Apply a gradle plugin conditionally depending on a flavour folder contents

After all I followed the solution that enables the plugin, but disables the task it introduces for flavours that should not have the plugin enabled. Since it can be done in the same project.android.applicationVariants block as I checked for the google-services.json file presence, it turned out to be a perfect solution for that case.

See more: https://stackoverflow.com/a/49542745/3187706

Dynamically add build flavor from within a custom Gradle plugin

It should be as simple as this:

@Override
void apply(Project target) {
target.android.productFlavors.create("name")
}

productFlavors is an instance of NamedDomainObjectContainer.

From docs of NamedDomainObjectContainer.create():

Creates a new item with the given name, adding it to this container.

Thus, this will create a ProductFlavor with provided name and it to productFlavors.



Related Topics



Leave a reply



Submit