I have some questions about how to do this correctly - Documentation from the Flutter team on using Flavors is somewhat lacking and to this date the tutorials and articles all seem to be from people who are posting as they learn about it. I appreciate the effort here but also recognise that the knowledge is incomplete.
The application ID can be set in a number of places, in particular in the AndroidManifest and in the build.gradle files.
Example:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.domain.app">
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<uses-permission android:name="android.permission.INTERNET"/>
Example:
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.domain.appname"
minSdkVersion 23
targetSdkVersion 29
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
flavorDimensions "appFlavor"
productFlavors {
qa {
dimension "appFlavor"
applicationId "com.domain.appflavor1"
}
prod {
dimension "appFlavor"
applicationId "com.domain.appflavor2"
}
dev {
dimension "appFlavor"
applicationId "com.domain.appflavor3"
}
}
The application ID also appears in the Kotlin MainActivity.kt file, as well as in the path to this file under the src directory. As far as I can tell the value specified here does not have any impact on the app functionality. But surely it must have some relevance somewhere.
The values set in the respective config sets for the individual flavors in build.gradle works as expeced.
But when you have multiple AndroidManifest.xml files - eg one per flavor, these all have to specify the exact same package as the one in the main AndroidManifest.xml file. Attempts to leave the value out leads to an error. The value in the main AndroidManifest does not seem to matter as long as it matches the name in the flavor specific AndroidManifest
But this makes no sense - how can the package name and applicationID be different and conflict between the app build.gradle and the AndroidManifest?
Which one will be used for what exactly?
I have another question open on S.E where I'm battling with issues relating to MissingPlugin exceptions which I feel may be related here: Flutter issues with release-mode only APK builds