How to Change the Package Name in Flutter

How to Change the Package Name in Flutter

19 December 2024 Stephan Petzl Leave a comment Tech-Help

Changing the package name in a Flutter project is a common requirement, especially when preparing an app for release. This guide provides a comprehensive approach to effectively changing your package name across both Android and iOS platforms.

Step-by-Step Guide

1. Using Command Line for New Projects

If you are starting a new project, you can set the package name at the creation stage using:

flutter create --org com.yourdomain appname

2. Manually Changing Existing Projects

For existing projects, you can manually change the package name by updating several files:

  • Android:
    • Change the applicationId in build.gradle:
    defaultConfig {
        applicationId "your.package.name"
        minSdkVersion 16
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
    }
  • Update AndroidManifest.xml in main, debug, and profile folders:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="your.package.name">
  • Rename the directory structure under src/main/java to match the new package name.
  • iOS:
    • Change the bundle identifier in Info.plist:
    <key>CFBundleIdentifier</key>
    <string>com.your.packagename</string>
  • 3. Using Automation Tools

    For those who prefer an automated approach, consider using the rename package from pub.dev. This tool simplifies the process by executing a few commands:

    pub global activate rename
    pub global run rename --bundleId com.example.android.app --target android

    Additional Considerations

    Ensure to update any relevant configurations in external services like Firebase to reflect the new package name. Additionally, perform a global search in your IDE to replace any remaining instances of the old package name.

    Using Repeato for Streamlined Testing

    As you modify your Flutter app’s package name, testing becomes crucial to ensure everything functions as expected. Here, Repeato can be a valuable ally. Repeato, a no-code test automation tool for iOS and Android, allows you to create, run, and maintain automated tests swiftly. Its computer vision and AI capabilities make it particularly adept at adapting to changes like package name updates, ensuring your app remains robust and error-free.

    Like this article? there’s more where that came from!