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

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


当前回答

有几种可能性:

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.xml或Info.plist。

2-为Android和info编辑AndroidManifest.xml。plist for iOS

对于Android,只编辑AndroidManifest.xml文件中应用程序标签中的Android:label值,该文件位于: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标签内的值。plist位于ios/Runner文件夹中。

代码:

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

截图:

如果遇到问题,执行扑动清理并重新启动应用程序。

其他回答

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

插件flutter_app_name (https://pub.dev/packages/flutter_app_name)是一个几乎相同的包,具有良好的零安全,可以与Flutter 2.0一起工作。

设置您的开发依赖项和应用程序的名称

dev_dependencies:
  flutter_app_name: ^0.1.1

flutter_app_name:
  name: "My Cool App"

在项目目录下运行flutter_app_name

flutter pub get
flutter pub run flutter_app_name

你的启动器现在的名称将是“My Cool App”。

有几种可能性:

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.xml或Info.plist。

2-为Android和info编辑AndroidManifest.xml。plist for iOS

对于Android,只编辑AndroidManifest.xml文件中应用程序标签中的Android:label值,该文件位于: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标签内的值。plist位于ios/Runner文件夹中。

代码:

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

截图:

如果遇到问题,执行扑动清理并重新启动应用程序。

如果你像我一样喜欢从命令行自动化一些东西,你可以使用这个

appName="TestApp"
declare -a androidAppTypes=(
    "main"
    "debug"
    "profile"
)

# Change app name for Android
for appType in ${androidAppTypes[@]}
do
    xmlstarlet ed -L -u '/manifest/application/@android:label' -v "$appName" android/app/src/$appType/AndroidManifest.xml
done

# Change app name for Android
plutil -replace CFBundleDisplayName -string "$appName" ios/Runner/Info.plist

你可以通过编辑文件*project/ iOS /Runner/info.plist在iOS中修改它,而不需要打开Xcode。设置<key>CFBundleDisplayName</key>为你想要作为你的名字的字符串。

对于Android,在AndroidManifest.xml文件中的Android文件夹中更改应用程序名称,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>

自2019年12月21日起,您需要更改pubspec.yaml文件中的名称[NameOfYourApp]。然后转到“路径”中的“编辑→查找→替换”菜单,替换之前出现的所有名字。

另外,为了更好地衡量,更改android目录下的文件夹名称,例如android/app/src/main/java/com/example/yourappname。

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

flutter clean