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
How to Use the Speechrecognizer API Directly for Speech Input
Proguard Warnings "Can't Write Resource [Meta-Inf/Manifest.Mf] (Duplicate Zip Entry)"
Difference Between Android: and App: Prefix in Android Xml
Action Bar Menu Item Text Color
Data Directory Has No Read/Write Permission in Android
How to Delete from Firebase Realtime Database
Cordova - White Screen After Splash, No Exceptions in Console
Android: Total Height of Scrollview
How to Pass Values Between Activities on Android
How to Download a File from a Server and Save It in Specific Folder in Sd Card in Android
Change Device Language via Adb
Android App Integrated with Ok Google
Video Compression on Android Using New Mediacodec Library
Android: Google Maps Location with Low Battery Usage
How to Create Multiple Pendingintents with the Same Requestcode and Different Extras