In This Article

How to Change Package Name in Flutter? Step-by-step Guide

Changing the package name of a Flutter app can be a bit of a tedious process, but it’s necessary if you need to publish your app under a different name or if you’ve accidentally set the wrong package name in the beginning.

In this blog post, we will go over the steps required to change the package name of a Flutter app for both Android and iOS, with code examples.

Let’s first get to know what packages in Flutter are.

What are Packages in Flutter?

In Flutter, a package is a collection of reusable code that is bundled together and can be easily shared and integrated into other Flutter projects. Packages can include Dart code, assets, and resources, and can be used to add functionality to a Flutter app, such as adding new widgets, integrating with external APIs, or providing support for specific platforms.

Packages can be easily added to a Flutter project using the pub package manager and can be found in the official Dart package repository or on GitHub Copilot. Interestingly, developers from all across the world actively contribute to flutter by identifying pitfalls and suggesting improvements to it. This is one of the reasons which make flutter a reliable platform for cross-platform app development.

Now, let’s move toward changing the package name in Flutter.

How to Change Package Name in Flutter?

Here are the quick steps which you can perform to change the package name in the Flutter app.

Let’s go! 😉

Step 1: Updating the package name in the pubspec.yaml file

The first step in changing the package name of a Flutter app is to update the package name in the pubspec.yaml file. You can find this at the root of your project and it contains the metadata for your app. To update the package name, simply change the value of the name field to the new package name.

Here is the code:

name: my_new_package_name
 

Step 2: Updating the package name in the Android build.gradle file

For Android, the next step is to update the package name in the build.gradle file. This file is located in the android/app directory of your project. Look for the applicationId field and update it with the new package name.

Run the command:

defaultConfig { applicationId "com.example.my_new_package_name" } 

Step 3: Updating the package name in the iOS Info.plist file

For iOS, the next step is to update the package name in the Info.plist file. This file is located in the ios/Runner directory of your project. Here, look for the CFBundleIdentifier key and update its value with the new package name.

Use the following code to do this:

<key>CFBundleIdentifier</key> <string>com.example.my_new_package_name</string> 

Step 4: Updating the package name in the Dart code

The final step is to update the package name in the Dart code of your app. This can be done by doing a global search and replace of the old package name with the new package name in all the Dart files of your app.

Step 5: Updating the package name in the AndroidManifest.xml file

Another step for Android is to update the package name in the AndroidManifest.xml file. This file is located in the android/app/src/main directory of your project. Look for the package attribute and update it with the new package name.

Here is the code:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.my_new_package_name">

Step 6: Updating the package name in the AppDelegate.m file

For iOS, the next step is to update the package name in the AppDelegate.m file. This file is located in the ios/Runner directory of your project. Look for the NSBundle and update its value with the new package name.

You can use the following command:

NSString* bundleID = @"com.example.my_new_package_name"; 

Key Takeaways:

Once you have completed all of the above steps, you should have successfully changed the package name of your Flutter app for both Android and iOS. We would recommend you test your app on both platforms to ensure everything is working correctly.

It’s worth noting that this process is a bit error-prone, so be sure to double-check all the files you’ve changed, and test your app thoroughly after making the changes to ensure that everything is working as expected. It’s also recommended to use some tools like flutter_launch_checks to verify the package name across the app and the files.

Changing the package name will cause some issues with the app like it will lose the installed data and previous user’s data. So we recommended you inform the users about the change and ask them to log in again if necessary.

Conclusion:

This was it for the quick guide to changing the package name in Flutter. After reading this quick guide to changing package name in Flutter, it should be quite easier for you. As always, be sure to thoroughly test your app after making any changes to ensure that everything is working as expected. If you have any questions or run into any issues, feel free to reach out for help. Our team of skilled flutter developers will love to be of help.

See you in the next blog. 😉

Picture of Bashir Ahmad

Bashir Ahmad

When not savoring tortillas, Bashir captivates readers with helpful and engaging prose, driven by his passion for Flutter and a dedication to providing value.

Share on:

Leave a Comment

Your email address will not be published. Required fields are marked *