乐闻世界logo
搜索文章和话题

How to change package name in flutter?

1个答案

1

Changing the package name in Flutter involves several steps, primarily because the package name (also known as the application ID or package identifier) is configured differently on iOS and Android platforms. Below, I will explain how to change the package name on both platforms.

Android

To change the package name on Android, you need to modify the following locations:

  1. android/app/src/main/AndroidManifest.xml
    • Change the package name from package="com.example.oldname" to the new package name, e.g., package="com.newcompany.newname".
  2. android/app/build.gradle
    • Update applicationId "com.example.oldname" to the new package name applicationId "com.newcompany.newname".
  3. android/app/src/main/kotlin or java directory
    • Based on the original directory structure, e.g., com/example/oldname, refactor it to the new directory structure com/newcompany/newname.
    • Also, ensure that package references within the directory files are updated.
  4. android/app/src/debug/AndroidManifest.xml
    • If it exists, update the package name.
  5. android/app/src/profile/AndroidManifest.xml
    • If it exists, update the package name.

After making these changes, you may need to clean and rebuild the project in your IDE, or manually delete the build directory to ensure all changes are correctly applied.

iOS

On iOS, changing the package name typically refers to changing the project's Bundle Identifier:

  1. Open the Xcode Project
    • Open ios/Runner.xcworkspace.
  2. Change the Bundle Identifier
    • In Xcode, select Runner > Targets > Runner in the project navigator, then in the General tab, find the Identity section and change Bundle Identifier to the new package name, e.g., com.newcompany.newname.

Ensure that all references to the old package name throughout the project are updated. You can use the global search and replace feature in your IDE to search for the old package name, e.g., com.example.oldname, and replace it with com.newcompany.newname.

Testing

After changing the package name, thoroughly test the application to ensure there are no issues caused by the change. Verify that the app runs normally on both simulators and physical devices, and that all features work correctly.

Important Notes

  • If you have already published the app, changing the package name will be considered a new application. This means users need to download the app again and cannot update to get the new version. Therefore, changing the package name after publishing requires careful handling.
  • Changing the package name may affect integration with third-party services like Firebase and Google Services, as these services may depend on specific package names.

By following these steps, you can successfully change the application's package name in your Flutter project.

2024年7月1日 12:19 回复

你的答案