Every Flutter app has a package name that uniquely identifies your app on the Google Play Store and Apple App Store. In Android, it is called the ‘application ID’ whereas in iOS it is referred to as the ‘Bundle Identifier’. While developing the Flutter app, you may come across a situation where you need to change the package name or upload a new version of the app with completely a new package name. In this tutorial, we’ll learn the top 3 ways to change package name in Flutter.
Here’s what we’ll cover:
- Creating Project with New Package Name
- Changing Package Name Manually
- Change Package Name in Flutter using Dependency (Recommended)
Creating Project with New Package Name
If you just started working on the project and haven’t written much code, creating a project with the new package name is the quickest and cleanest solution. This method uses the
flutter create command to create a new project.
Steps to create a project with a new package name
Step 1: Open the terminal.
Step 2: Locate the folder where you want to create a new project.
Step 3: Hit the following command:
flutter create --org com.example newproject
The above command will create the new project with the package name as com.example.newproject where newproject is the name of the project.
Step 4: Once the new project is created, copy all the files (under the lib folder) and assets from the old project.
Changing Package Name Manually
If your project is big enough and you don’t want to create a new project and then copy old files over, you should change the package name manually.
Steps to change package name manually for Android
- Step 1: Navigate to the android>app> src>main > AndroidManifest.xml file and update the package value to the new one.
// Old <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.change_package.test1"> //New <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.change_package.test2">
Hint: Similarly update the AndroidManifest.xml file under the android>app> src>debug and android>app> src>profile.
- Step 2: Open the android>app> build.gradle file. Find the defaultConfig section and update the applicationId to the new package name.
Step 3: Now, navigate to the android> app> src> main> kotlin> MainActivity.kt and change the package name in the first line.
Step 4: Change the directory structure as per the new package name. For example, if you change the package name from com.example.oldcompany to com.example.newcompany, make sure to refactor/rename the oldcompany directory to newcompany.
Hint: If you added one more identifier at the last, make sure to create a new directory for that identifier. For example, if the old package name was com.example.company and the new package name is com.example.company.subscompany, you should create a new folder for subcompany and then move the MainActivity.kt file under the new folder.
Steps to change the package name for iOS
Step 1: Open your Flutter project in Xcode.
Step 2: Click on the Runner in the left side menu.
Step 3: Select the General tab.
Step 4: Under the Identity section, find the Bundle Identifier and change it to the new package name.
Change Package Name in Flutter using Dependency (Recommended)
If you don’t want to change the package name by yourself, there exists a dependency that does the job for you. Its called change_app_package_name. It updates all the files and changes the directory structure that is required to successfully change the package name.
Here are the steps:
Step 1: Add the dependency to pubspec.yaml under the dev_dependencies section.
dev_dependencies: flutter_test: sdk: flutter flutter_lints: ^1.0.0 change_app_package_name: ^1.0.0 //Here
Step 2: Get the dependency using the following command.
flutter pub get
Step 3: Run the following command in the terminal.
flutter pub run change_app_package_name:main com.example.newpackage
Replace the com.example.newpackage with your desired package name and your are done!
Looking to customize your app’s icon too? Check out our blog post on “Changing App Icons in Flutter” for an easy step-by-step guide to updating your app icon. With the
flutter_launcher_icons package, you can quickly and easily generate all the required icon sizes for both Android and iOS platforms.
In this tutorial, we learned the top 3 ways to change package name in Flutter with a practical example. This included changing the package name manually as well as using the dependency.