I have development and production flavor for Flutter app.
Issue is label and launcher are same for both development and production app so cannot see difference. (Actually cannot install both on device at same time)
What is simple way to change Flutter app name depending on flavor?
I know can change app label and launcher by modify AndroidManifest.xml and Xcode info.plist. But this not simple: must make additional file for reference in xml and plist file. Modify like this is against aim of Flutter.
Anyone know solution?
Thanks!
The first step is to download google-services. json file(s) from each Firebase project to a temporary location at your machine. Next, create two folders android/app/src/dev and android/app/src/prod for each flavor. The Firebase configuration files go under their flavor folders under android/app/src/ folder..
Simply have this in android project app gradle :
flavorDimensions "default"
productFlavors {
dev {
resValue "string", "app_name", "AppName_DEV"
}
demo {
resValue "string", "app_name", "AppName_Demo"
}
prod {
resValue "string", "app_name", "AppName"
}
}
and then in your AndroidManifest just use this :
android:label="@string/app_name"
it will generate unResolved app_name and it's done!
For android create a directory under src for each flavor. Within each source create a directory named res
, and in that create a directory named values
.
Then in each values
directory create a file named strings.xml
Add the following to the this file:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">App 1</string>
</resources>
This creates a string named app_name
that can be used in the Android Manifest.
To use the string change the android:label in the application tag in the AndroidManifest.xml, as follow:
<application
android:name="io.flutter.app.FlutterApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher">
Also add a default strings.xml
into the main res values directory. Within that one set the value to something like "Default Flavor Res" to make you attend that the flavor doesn't have a resources file for strings.
Reference: http://cogitas.net/creating-flavors-of-a-flutter-app/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With