如何更改使用 Flutter 构建的应用程序显示名称?

How can I change the app display name build with Flutter?

我已经使用 Flutter create testapp 创建了应用程序。 现在,我想将应用名称从“testapp”更改为“My Trips Tracker”。我该怎么做?

我已经尝试从 AndroidManifest.xml 进行更改,它已经更改了,但是 Flutter 是否提供了一种方法来做到这一点?

更新:从评论来看,这个答案似乎已经过时了

Flutter 文档指出了您可以在何处更改 Android 和 iOS 应用程序的显示名称。这可能是您正在寻找的:

对于Android

您似乎已经在 AndroidManifest.xml 中找到了 application 条目。

Review the default App Manifest file AndroidManifest.xml located in /android/app/src/main/ and verify the values are correct, especially:

application: Edit the android:label in the application tag to reflect the final name of the app.

对于iOS

参见 Review Xcode project settings 部分:

Navigate to your target’s settings in Xcode:

In Xcode, open Runner.xcworkspace in your app’s ios folder.

To view your app’s settings, select the Runner project in the Xcode project navigator. Then, in the main view sidebar, select the Runner target.

Select the General tab. Next, you’ll verify the most important settings:

Display Name: the name of the app to be displayed on the home screen and elsewhere.

您可以在 iOS 中更改它而无需打开 Xcode,方法是将 project/ios/Runner/info.plist <key>CFBundleDisplayName</key> 编辑为您想要的字符串。

FWIW - 我对 Xcode 和 Flutter 中的更改感到沮丧,所以我在打开 Xcode 之前开始提交所有更改,这样我就可以看到更改在 Flutter 项目中的显示位置.

一个问题是,在 iOS 设置 (iOS 12.x) 中,如果您更改显示名称,它会在 iOS 设置中保留应用程序名称和图标旧版本。

  • 查看位于 <app dir>/android/app/src/main

    的默认应用程序清单文件 AndroidManifest.xml
  • android:label 编辑为您想要的显示名称

Android

打开AndroidManifest.xml(位于android/app/src/main

<application
    android:label="App Name" ...> // Your app name here

iOS

打开info.plist(位于ios/Runner

<key>CFBundleName</key>
<string>App Name</string> // Your app name here

别忘了运行

flutter clean

对于Android,更改 Android 文件夹中的应用名称。在 AndroidManifest.xml 文件中,在文件夹 android/app/src/main 中,让 android 标签引用您喜欢的名称,例如,

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    <application
        `android:label="myappname"`
        // The rest of the code
    </application>
</manifest>

有一个名为 flutter_launcher_name 的插件。

写入文件pubspec.yaml:

dev_dependencies:
  flutter_launcher_name: "^0.0.1"

flutter_launcher_name:
  name: "yourNewAppLauncherName"

和运行:

flutter pub get
flutter pub run flutter_launcher_name:main

您可以获得与编辑 AndroidManifest.xmlInfo.plist 相同的结果。

自 2019-12-21 起,您需要更改文件 pubspec.yaml 中的名称 [NameOfYourApp]。然后转到菜单 编辑查找在路径中替换,并替换所有出现的你以前的名字.

另外,为了更好的措施,更改 android 目录中的文件夹名称,例如android/app/src/main/java/com/example/你的应用名称.

然后在控制台中,在您应用程序的根目录中,运行

flutter clean

iOS和Android的改名方式在文档中有明确说明如下:

但是,在 iOS 的情况下,将 显示名称 Xcode 更改后,您将无法 运行 应用程序以 Flutter 的方式,比如 flutter run.

因为 Flutter 运行 期望应用名称为 Runner。即使您在 Xcode 中更改名称,它也不起作用。

所以,我按如下方式解决了这个问题:

移动到您的 Flutter 项目中的位置,ios/Runner.xcodeproj/project.pbxproj,找到新名称的所有实例并将其替换为 亚军.

那么一切都应该按照 flutter run 的方式进行。

但不要忘记在下次发布时更改名称显示名称。否则,App Store 拒绝您的姓名。

您可以在 iOS 中更改它,而无需打开 Xcode,方法是编辑文件 *project/ios/Runner/info.plist。将 <key>CFBundleDisplayName</key> 设置为您想要用作姓名的字符串。

对于 Android,更改 Android 文件夹中的应用名称,在 AndroidManifest.xml 文件,android/app/src/main。让 android 标签引用您喜欢的名称,例如,

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    <application
        android:label="test"
        // The rest of the code
    </application>
</manifest>

有几种可能:

1- 一个包的使用:

我建议您使用 flutter_launcher_name,因为命令行工具可以简化更新 Flutter 应用程序启动器名称的任务。

用法:

将您的 Flutter Launcher 名称配置添加到您的 pubspec.yaml 文件中:

dev_dependencies:
  flutter_launcher_name: "^0.0.1"

flutter_launcher_name:
  name: "yourNewAppLauncherName"

设置配置后,剩下要做的就是运行包。

flutter pub get
flutter pub run flutter_launcher_name:main

如果你使用这个包,你不需要修改文件AndroidManifest.xmlInfo.plist

2- 为 Android 编辑 AndroidManifest.xml,为 iOS

编辑 info.plist

对于Android,仅编辑 android:label 应用程序中的值 文件 AndroidManifest.xml 中的标记位于文件夹中:android/app/src/main

代码:

<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <application
        android:name="io.flutter.app.FlutterApplication"
        android:label="Your Application Name"  //here
        android:icon="@mipmap/ic_launcher">
        <activity>
        <!--  -->
        </activity>
    </application>
</manifest>

截图:

对于iOS,仅编辑 String 标签内的值在文件 Info.plist 中位于文件夹 ios/Runner .

代码:

<plist version="1.0">
<dict>
    <key>CFBundleName</key>
    <string>Your Application Name </string>  //here
</dict>
</plist>

截图:

如果遇到问题,请执行 flutter clean 并重新启动您的应用程序。

第一个 重命名您的 AndroidManifest.xml 文件

android:label="Your App Name"

第二 在 Pubspec.yaml 文件中重命名您的应用程序名称 name: Your Application Name

第三 更改您的应用程序徽标

flutter_icons:
   android: "launcher_icon"
   ios: true
   image_path: "assets/path/your Application logo.formate"

第四 运行

flutter pub pub run flutter_launcher_icons:main

这里的一些答案建议使用包 flutter_launcher_name,但是这个包不再被维护,并且会导致新的 Flutter 2.0 项目中的依赖性问题。

插件 flutter_app_name (https://pub.dev/packages/flutter_app_name) 是一个几乎相同的包,具有良好的 null 安全性并且可以与 Flutter 2.0 一起使用。

  1. 设置您的开发依赖项和您的应用名称
dev_dependencies:
  flutter_app_name: ^0.1.1

flutter_app_name:
  name: "My Cool App"
  1. 运行 flutter_app_name 在你的项目目录中
flutter pub get
flutter pub run flutter_app_name

您的启动器现在将具有“My Cool App”的名称。

您可以通过更新 Android 和 iOS

的名称来更改应用程序名称

对于Android

只需打开 AndroidManifest.xml 文件,

进入android>app>src>main>AndroidManifest.xml

像这样:-

所以我的应用程序名称是“演示”所以,我将更新标签值。

iOS 相同 只需打开 Info.plist 文件,

进入内部 ios>Runner>Info.plist

像这样:-

并更改此字符串值。

您好,我确实看到了手动解决方案(转到 IOS 和 Android)。 但是我发现了一个可以从一个位置更改名称的插件:

https://pub.dev/packages/flutter_launcher_name

只需执行以下操作: 添加到 pubspec.yaml

dev_dependencies: 
  flutter_launcher_name: "^0.0.1"
  
flutter_launcher_name:
  name: "yourNewAppLauncherName"

运行 在终端中:

flutter pub get
flutter pub run flutter_launcher_name:main

完成。