Question

I developed an application which I want to multiply for different targets. So the source code would stay the same but some vars change for each target. Xcode could easily do this by adding a new target. You could then run all individual targets as individual apps and when you change something in the source its affecting all targets.

How does something like this work with Android? I'm developing in the latest Android Studio.

Was it helpful?

Solution

Android Studio Tips and Tricks advocates that build variants are a feature not yet fully implemented. However you can manage that with Gradle itself, as documented into the Gradle Plugin User Guide. You basically define variants and get an autogenerate BuildConfig.java file. For instance you could define two flavor, release and debug like this:

release {
   buildConfig "public static final String RELEASE = true;"
}
debug {
   buildConfig "public static final String RELEASE = false;"
}

inside your android/buildVariants section into build.gradle and this will include this boolean variable in the automatically generated BuildConfig.java for use in your application to differ in behaviour.

See also Using Build Flavors - Structuring source folders and build.gradle correctly and this blog post about build variants.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top