To change the app package name manually by editing each file in Flutter is a bit time-consuming, and may cause errors if there you do not update every file. In this example, we are going to show you how to change the package name at once with the terminal command in Flutter.
To change the app package name with command, you need the add dev dependency change_app_package_name by adding the following lines in pubspec.yaml file. Remember, this is not a normal dependency, it is a dev dependency.
dev_dependencies: flutter_test: sdk: flutter change_app_package_name: ^1.0.0
Now, update the dependencies
flutter pub get
After, that use the command below, replace the package name of your choice and hit in the terminal:
flutter pub run change_app_package_name:main com.newpackage.name
Replace the package name with yours before executing this command in the terminal.
The output of this command may look like below:
Old Package Name: com.example.testapp Updating build.gradle File Updating Main Manifest file Updating Debug Manifest file Updating build.gradle File Updating Main Manifest file Updating Debug Manifest file Updating Profile Manifest file Project is using kotlin Updating MainActivity.kt Creating New Directory Structure Deleting old directories
Now, check the AndroidManifest.xml, build.gradle file if the package name is updated or not.
In this way, you can change the package name with the terminal command in Flutter.