Hi everyone, what is the easiest way to distinguis...
# android
m
Hi everyone, what is the easiest way to distinguish between different Android flavours in a multiplatform project? I would like to have a Huawei and a Google target. Thanks
f
Not sure if this will help in your situation, but here’s something that might work; In your build.gradle, add product flavors: And let the different flavors add different values for a BuildConfigField.
Copy code
flavorDimensions.add("tier")
productFlavors {
  
  create(name= "Huawei") {
    dimension="tier"
    buildConfigField(type="String", name="APP_FLAVOR", value="Huawei")
  }

  create(name= "Google") {
    dimension="tier"
    buildConfigField(type="String", name="APP_FLAVOR", value="Google")
  }
}
Then at runtime, you could use the BuildConfig, to see which flavor is build/running; Like so:
BuildConfig.APP_FLAVOR
, which will contain a different String depending on the Flavor.
c
Build flavors are a Android Gradle plugin concept, you‘ll not be able to retrieve this information in a common multiplatform module for example. You can create a custom configuration in the shared module with your own „buildconfig“ class.
👍 1
a
Since product flavors are android only concept, another possibility would be to declare an interface in commonMain. It will be implemented by android and provided via DI