How to change Flutter app name depending on flavor?

3,444

Solution 1

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!

Solution 2

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/

Share:
3,444
FlutterFirebase
Author by

FlutterFirebase

Updated on December 09, 2022

Comments

  • FlutterFirebase
    FlutterFirebase over 1 year

    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!

  • Martins
    Martins over 3 years
    This is what I was missing! Thanks @Vahab