android - Dynamically add build flavor from within a custom Gradle plugin -


i'm writing custom gradle plugin add 1 or more tasks android project. 1 of tasks needs add 'ad hoc' build flavor list of existing build flavors defined android project.

i've tried altering 1 of existing build flavors changing name shown following code:

import com.android.build.gradle.internal.dsl.productflavor import org.gradle.api.plugin import org.gradle.api.project  class myplugin implements plugin<project> {      @override     void apply(project target) {         productflavor adhocflavor = target.android.productflavors.first()         adhocflavor.name = 'adhoc'         target.android.productflavors.add(adhocflavor)     }  } 

the problem here build flavors in target.android.productflavors read-only @ point , throws following error:

cannot set value of read-only property 'name' productflavor_decorated

does have idea how can dynamically add build flavor within plugin?

it should simple this:

@override void apply(project target) {     target.android.productflavors.create("name")     } 

productflavors instance of nameddomainobjectcontainer.

from docs of nameddomainobjectcontainer.create():

creates new item given name, adding container.

thus, create productflavor provided name , productflavors.


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -