yshrsmz / BuildKonfig

BuildConfig for Kotlin Multiplatform Project
Apache License 2.0
783 stars 32 forks source link

flavor support #8

Closed yshrsmz closed 5 years ago

yshrsmz commented 5 years ago

Some thing like Android's product flavor could be useful. But since Kotlin MPP does not support it, we need to come up with some workaround.

buildkonfig {
  targetConfigs {
    android {
      flavor = "dev"
    }
    android {
      flavor = "release"
    }

    ios {
      flavor = "dev"
    }
    ios {
      flavor = "release"
    }
  }
}
yshrsmz commented 5 years ago

passing value via command line will work, but I'm not sure how I can do that in Android Studio/IntelliJ IDEA

$ ./gradlew -Pbuildkonfig.flavor=dev build
yshrsmz commented 5 years ago

This should work

yshrsmz commented 5 years ago

NamedDomainObjectContainer is Set, so duplicated name is not allowed.

buildkonfig {
  defaultConfigs("dev") {}
  defaultConfigs("release") {}

  // void targetConfigs(String flavor, Closure closure)
  targetConfigs("dev") {
    android {
    }
    ios {
    }
  }
  targetConfigs("release") {
    android {
    }
    ios {
    }
  }
}

Also, defaultConfigs should be configurable per flavor