Change Flutter Package Name for Android and iOS

Jyotishgher Astrology
By -
3 minute read
0

 Change Flutter Package Name for Android and iOS

Changing the package name in a Flutter app is a critical step, especially when preparing for production or rebranding a project. The package name is the unique identifier for your app on the Google Play Store (Application ID) and the App Store (Bundle Identifier).

Change Flutter Package Name for Android and iOS

The Recommended Method: Using a Package

The most reliable and least error-prone method is to use a trusted package that handles all the necessary modifications across different platform files automatically. The community-standard package for this is change_app_package_name.

Step 0: Backup Your Project

Before you begin, it is highly recommended to commit your current project state to a version control system like Git, or at least create a manual backup (zip) of your entire project folder. This ensures you can revert if anything goes wrong.

Step 1: Add the Dev Dependency

Open your pubspec.yaml file and add change_app_package_name under dev_dependencies.

YAML

dev_dependencies:
flutter_test:
sdk: flutter
change_app_package_name: ^1.1.0 # Or the latest version

Why dev_dependencies? This is a tool you only use during development, not something that needs to be bundled with your final app, so it belongs in dev_dependencies.

After adding the line, run this command in your terminal at the root of your project to fetch the package:

Bash

flutter pub get

Step 2: Run the Package Command

Now, run the following command in your terminal, replacing com.new.packagename with your desired new package name.

The standard format for a package name is com.companyname.appname.

Bash

flutter pub run change_app_package_name:main com.new.packagename

Example: If you want your new package name to be com.brightapps.navratriguide, you would run:

Bash

flutter pub run change_app_package_name:main com.brightapps.navratriguide

The tool will automatically find and replace the package name in all the necessary files for Android, iOS, and other platforms.

Step 3: Verify the Changes

The tool is very reliable, but it’s good practice to quickly check the key files to ensure the changes were applied:

  • Android:
  • android/app/build.gradle: Check the applicationId field.
  • android/app/src/main/AndroidManifest.xml: Check the package attribute in the <manifest> tag.
  • android/app/src/main/kotlin/.../MainActivity.kt (or java): Check the package declaration at the top.
  • iOS:
  • Open ios/Runner.xcworkspace in Xcode.
  • Click on “Runner” in the project navigator, then select the “Runner” target.
  • Go to the “General” tab and verify the “Bundle Identifier” has been updated.

Crucial Post-Change Steps

After changing the package name, there are a few essential cleanup and configuration steps.

1. Clean Your Project

Run the Flutter clean command to remove old build artifacts that might still reference the old package name.

Bash

flutter clean
flutter pub get

2. Update Firebase and Third-Party Services (Very Important!)

If you are using services like Firebase (for Push Notifications, Analytics, etc.), your app’s connection will break because the package name is used to identify your app.

For Android:

  • Go to your Firebase Project Settings.
  • Under the “Your apps” card, click “Add app” and select the Android icon.
  • Register your app again with the new package name.
  • Download the new google-services.json file.
  • Replace the old android/app/google-services.json with this new one.

For iOS:

  • In your Firebase Project, click “Add app” and select the iOS icon.
  • Register your app with the new Bundle ID.
  • Download the new GoogleService-Info.plist file.
  • In Xcode, open ios/Runner.xcworkspace, right-click the "Runner" folder, choose "Add Files to Runner", and add the new .plist file. Make sure to replace the old one.

The Manual Method (Not Recommended)

For educational purposes, here’s what the manual process looks like. It is tedious and prone to errors.

  • Android:
  • In android/app/build.gradle, change applicationId.
  • In android/app/src/main/AndroidManifest.xml, change the package name.
  • In android/app/src/debug/AndroidManifest.xml, change the package name.
  • In android/app/src/profile/AndroidManifest.xml, change the package name.
  • Go to android/app/src/main/kotlin/ (or java/). You must rename the directory structure to match your new package name. For example, if changing from com.example.app to com.brightapps.navratri, you must rename the folders from com/example/app to com/brightapps/navratri.
  • Open MainActivity.kt (or .java) inside that folder and change the package declaration at the top.
  • iOS:
  • Open ios/Runner.xcworkspace in Xcode.
  • Go to Runner > Target > General > “Identity” and change the Bundle Identifier.
  • Also, open ios/Runner/Info.plist and change the value for the CFBundleIdentifier key.

By following the recommended package-based method, you can avoid the complexity and potential errors of the manual process and get your app’s identity updated in a matter of seconds.


Tags:

Post a Comment

0Comments

Post a Comment (0)