How to change Flutter app name depending on flavor?
Asked Answered
L

5

21

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!

Lolitaloll answered 2/2, 2019 at 21:13 Comment(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.Melancholic
flutter.io/docs/deployment/flavorsDistaste
C
52

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!

Crossley answered 15/9, 2019 at 6:13 Comment(2)
This is what I was missing! Thanks @VahabTarim
...and for iOS??Internationalism
N
12

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/

Narbonne answered 12/9, 2019 at 12:25 Comment(0)
I
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

Internationalism answered 8/11, 2022 at 15:0 Comment(0)
C
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

Cytolysin answered 1/6, 2021 at 23:32 Comment(0)
A
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

Abydos answered 15/1, 2022 at 19:17 Comment(1)
is this a package?Panto

© 2022 - 2024 — McMap. All rights reserved.