How to Change Package Name in Flutter

Change Package Name in Flutter

1. Update Package Name in Android

To change the package name for the Android version of your Flutter app, follow these steps:

  • Open android/app/build.gradle and locate the defaultConfig block.
  • Update the applicationId to your desired package name:
android/app/build.gradle

defaultConfig {
    applicationId "com.yourcompany.app_name"
}
        

This is where you specify your unique package name for the Android app. Make sure to use a reverse domain name format, e.g., com.example.myapp.

2. Update Package Name in iOS

To change the package name for the iOS version of your Flutter app, follow these steps:

  • Open the ios/Runner.xcodeproj/project.pbxproj file in Xcode.
  • Find and replace all occurrences of the old package name with the new one. Pay attention to the PRODUCT_BUNDLE_IDENTIFIER key.
PRODUCT_BUNDLE_IDENTIFIER = com.yourcompany.app_name;
        

Ensure you change the bundle identifier for both the Debug and Release configurations.

3. Update Package Name Using Automation (Optional)

If you want to automate the process of changing the package name, you can use the change_app_package_name package:

  • First, add the dependency in your pubspec.yaml file:
dev_dependencies:
  change_app_package_name: ^1.0.0
        
  • Run the following commands to get the package and change the package name:
flutter pub get
flutter pub run change_app_package_name:main com.newcompany.app_name
        

Replace com.newcompany.app_name with your desired package name. This will automatically update your package name in both Android and iOS configurations.

4. Update App Namespace (For Android)

To fully update the package name on Android, you also need to change the app’s namespace in the build.gradle file:

  • Open android/app/build.gradle.
  • Update the namespace field to match the new package name:
android {
    namespace "com.yourcompany.app_name"
}
        

5. Clean and Rebuild the Project

After modifying the package name, it’s important to clean and rebuild your project:

  • Run the following commands:
flutter clean
flutter pub get
flutter run
        

This ensures that all configurations are updated and applied to your project.

6. Verify the Changes

Finally, verify the package name change:

  • For Android: Check the applicationId in the generated APK or app bundle.
  • For iOS: Check the PRODUCT_BUNDLE_IDENTIFIER in the generated app.

Leave a Reply