Closed Borlehandro closed 11 months ago
buildkonfig.flavor
is just a property, so you can pass it via gradlew command
./gradlew build -Pbuildkonfig.flavor=release
See detail here: https://docs.gradle.org/current/userguide/build_environment.html#sec:project_properties
Also there's a note in README: https://github.com/yshrsmz/BuildKonfig#product-flavor
It doesn't seem that there's a ton of guidance on this. Perhaps not everyone has the same build environment that this was designed for. One thing I am trying to figure out is how I would specify the flavor when I am using Cocoapods to keep the library in sync with my Xcode project. It's not super apparent how I can vary the flavor from my Xcode build configuration, through Cocoapods, and to Gradle.
Here is what I have done in the meantime. However, this doesn't seem to leverage the actual "flavor" feature.
buildkonfig {
packageName = "com.example.mykmpproject"
defaultConfigs {
when (project.findProperty(KotlinCocoapodsPlugin.CONFIGURATION_PROPERTY)) {
"Debug" ->
buildConfigField(FieldSpec.Type.STRING, "defaultEnvironment", "Debug", const = true)
"Beta " ->
buildConfigField(FieldSpec.Type.STRING, "defaultEnvironment", "Beta", const = true)
else ->
buildConfigField(FieldSpec.Type.STRING, "defaultEnvironment", "Production", const = true)
}
}
}
For the OP case, you can get an actual task name that a user passes to gradlew
via project.gradle.startParameter.taskNames
. So it's possible to dynamically change the value of buildkonfig.flavor
property.
For cocoapods, please open a separate issue as this one is already closed. (And I'm not sure how Cocoapods & Kotlin Cocoapods Plugin build the project.)
Or why not just update buildkonfig.flavor
property with that project.findProperty(KotlinCocoapodsPlugin.CONFIGURATION_PROPERTY)
value? I think that should work.
Ah, that worked well. I put a setProperty
based on that value I was using before, and now I can use buildkonfig
as it was designed. Thanks!
Hi there! Are there any way to specify flavor in build time? As I understand it, now plugin get flavor from properties only once when it's applied. But i want to change
buildkonfig.flavor
dynamically, for example based on my android-app flavor. I try toext.set("buildkonfig.flavor", <someFlavor>)
before:generateBuildKonfig
task but it doesn't work for me.