The package name is an ID that uniquely identifies the app. In Android it’s like com.example.project
, this is the default package name format that Flutter creates when you first make the project.
Today you will explore two ways to change the app package name.
- Using change_app_package_name flutter package
- Change Package Name Manually
In the end, you will learn how you can give your package name when you first time creates your project.
- Assign Package Name When Creating a Project
Let’s First use the change_app_package_name package.
In this Article
Using change_app_package_name flutter package
You will first install the change_app_package_name package in the dev_dependencies by using:
dev_dependencies:
change_app_package_name: ^1.1.0
Get the dependencies by running:
flutter pub get
Now you just run this command for changing the package name.
flutter pub run change_app_package_name:main com.my.package
You can give your own package name instead of com.my.package
. Make sure it is unique if your plan is to publish this app to the corresponding store.
I share the easy method first. Now it’s time to see what this package does under the hood.
or you can say how you can change the package name manually or using vscode.
Here In this example, I am using vs code. A similar IDE feature can also be available if you use Android Studio or any other IDE for flutter development.
Change Package Name Manually
It’s also simple.
Go to the android/app/build.gradle
Here inside the default config
defaultConfig {
applicationId "com.example.cwh"
}
You find your application ID.
Just copy this ID and Search in your project.
When you search the project a list of files with that name will appear.
Make sure you are searching case-sensitive and replace the project name with your own project name.
Here I change my project name from com.example.cwh
to com.codewithhussain.learn
.
Hit replace All Button
Save the project and rebuild the app.
Now this time project builds with the new App ID.
Now
Let’s see how you can create a project with a custom name.
Assign Package Name When Creating a Project
In this method, you will create a project from the command prompt or terminal.
You can change the directory according to your desire.
Now when you create a project you use this command:
flutter create --org com.yourdomain appname
This will solve the problem.
Conclusion:
You find out how you can change the package name in Flutter. You see how you use vscode IDE to change the flutter app package name. An how you can use the change_app_package_name package in a flutter. In the end, you explore how you can create a project with your custom name.
Read more:
- Dismiss keyboard in Flutter
- ListViews inside Column Widget Tutorial
- Create Toast Notification in Flutter
- Create Gradient Screen Background
- Validate Form in Flutter
- Flutter SizedBox widget
Hope this guide was helpful. Thanks!