Add dependency to specific productFlavor and buildType in gradle

前端 未结 6 1746
长情又很酷
长情又很酷 2020-12-05 11:31

I\'m wondering how to add dependency to specific productFlavor and buildType in gradle. For example I have productFlavor free and build type release

6条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-05 12:09

    Muschko's answer didn't work for me, so this is my solution, written and posted by me here

    Define the task that should only be executed on a specific buildType/variant/flavor

    task doSomethingOnWhenBuildProductionRelease << {
        //code
    }
    

    It's important to use the "<<" syntax or else the task will automatically be called every time.

    Dynamically set the dependency when the tasks are added by gradle

    tasks.whenTaskAdded { task ->
        if (task.name == 'assembleProductionRelease') {
            task.dependsOn doSomethingOnWhenBuildProductionRelease 
        }
    }
    

提交回复
热议问题