22

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!

2
  • The simple answer is that there's no simple way to do that, your Continuous Deployment system would have to do these changes and other ones, such as different urls to projects/ database/ auth/ etc, all depending on your environment. Commented Feb 3, 2019 at 0:33
  • flutter.io/docs/deployment/flavors Commented Feb 4, 2019 at 4:36

6 Answers 6

53

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!

Sign up to request clarification or add additional context in comments.

1 Comment

...and for iOS??
13

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/

Comments

5

Android has been covered in multiple answers. On iOS, you can achieve the same by setting up multiple build configurations and schemes, creating a user-defined setting, e.g. APP_DISPLAY_NAME, setting the value of this per build configuration, then in Info.plist setting the Bundle display name to ${ APP_DISPLAY_NAME }.

https://medium.com/swift2go/different-app-display-name-based-on-xcode-scheme-d709307d0c01

Comments

0

Are you sure you have kept project structure proper, like keeping flavor folder outside src package in android can create this issue, please see my flavor package structure for android as below.

flavor depiction

Comments

0

Add in pubspec.yaml:

flutter_flavor:
  dimensions:
    android: "flutter-flavor"
    ios: "flutter-flavor"

  flavors:
    apple:
      android:
        name: "Apple App"
        applicationId: "com.example.apple"
        googleAdsId: "ca-app-pub-1234567890123456~1234567890"
      ios:
        name: "Apple App"
        bundleId: "com.example.apple"
        googleAdsId: "ca-app-pub-1234567890123456~1234567890"

    bannana:
      app:
        name: "Bannana App"
        id: "com.example.bannana"
      android:
        googleAdsId: "ca-app-pub-1234567890123456~1234567890"
      ios:
        googleAdsId: "ca-app-pub-1234567890123456~1234567890"

Generating flavors: > flutter pub run flutter_flavor:main

1 Comment

is this a package?
0

With recent versions of Flutter (3.24), this worked for me:

In android/app/build.gradle:

flavorDimensions "default"
productFlavors {
    prod {
        dimension = "default"
        manifestPlaceholders = [appName: "[PROD] MYAPP"]
        applicationIdSuffix = ""
    }
    demo {
        dimension = "default"
        manifestPlaceholders = [appName: "[DEMO] MYAPP"]
        applicationIdSuffix = ""
    }
    dev {
        dimension = "default"
        manifestPlaceholders = [appName: "[DEV] MYAPP"]
        applicationIdSuffix = ""
    }
}

In AndroidManifest:

<application
    android:label="${appName}"

it will take the appName set in flavor configuration

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.