Changing the package name of a Flutter project involves updating identifiers for both Android and iOS platforms. This guide provides step-by-step instructions to ensure that your app’s package name is updated correctly and that the application continues to function as expected.
Open the Project in Your IDE
Open your Flutter project in Android Studio or Visual Studio Code.
Update AndroidManifest.xml
android/app/src/main/AndroidManifest.xml
.package
attribute in the manifest
tag and update it to the new package name:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.new.package.name">
Update build.gradle
android/app/build.gradle
.applicationId
in the defaultConfig
block to the new package name:
defaultConfig {
applicationId "com.new.package.name"
...
}
Rename Package Directories
android/app/src/main/java/com/old/package/name/
.com
directory and select Refactor
-> Rename
in Android Studio. Rename it to match the new package name’s structure.Update MainActivity.java
or MainActivity.kt
android/app/src/main/java/com/new/package/name/MainActivity.java
and verify the package statement at the top matches the new package name.MainActivity.kt
.Open the Project in Xcode
ios
directory of your Flutter project..xcworkspace
file in Xcode.Update the Bundle Identifier
General
tab.Bundle Identifier
field and update it to the new package name (usually formatted as com.new.package.name
).Update Info.plist
ios/Runner/Info.plist
.Update Project Settings
Project
-> Build Settings
.Product Bundle Identifier
is updated to the new package name.Search for Old Package Name
Clean the Project
Open your terminal or command prompt and navigate to your project directory. Run:
flutter clean
Get Dependencies
Run:
flutter pub get
Rebuild the Project
Run:
flutter build
Run on Emulator or Device
Ensure that the app builds and runs successfully on your emulator or physical device.
Check for Errors
Verify that no errors related to the package name persist and that the app functions as expected.
You have successfully changed the package name of your Flutter project for both Android and iOS platforms. By following these steps, you ensured that the new package name is correctly reflected in your project’s configuration files and codebase.
For more detailed information, refer to the official Flutter documentation and platform-specific guides for Android and iOS.