How to Change a Package Name in Flutter: Android, iOS, and Dart Configuration
To change a package name in Flutter, update the applicationId in android/app/build.gradle for Android, the CFBundleIdentifier in ios/Runner/Info.plist for iOS, and optionally the name field in pubspec.yaml for Dart imports.
In a Flutter project, the term "package name" refers to three distinct identifiers: the Android applicationId, the iOS bundle identifier, and the Dart package name used for imports. According to the flutter/flutter repository source code, these values are stored in separate platform-specific configuration files and must be updated individually to ensure your app builds correctly across platforms.
Understanding Package Names in Flutter
Before renaming anything, it is important to understand how Flutter distinguishes between native platform identifiers and the Dart package name.
Android Application ID
On Android, the package name is the applicationId defined in android/app/build.gradle. This is the unique identifier used by the Google Play Store and the Android operating system. The Flutter tool references this value when attaching to running processes, as seen in packages/flutter_tools/lib/src/commands/attach.dart, which describes the "package name (Android) or bundle identifier (iOS) for the app."
iOS Bundle Identifier
On iOS, the equivalent is the CFBundleIdentifier stored in ios/Runner/Info.plist. Xcode uses this value to uniquely identify your app on the App Store and device. The Flutter engine reads this identifier during build and attach operations.
Dart Package Name
The Dart package name is defined in pubspec.yaml under the name: field. This determines the import path used in Dart code (e.g., package:my_app/main.dart). Changing this is optional and does not affect the native Android or iOS identifiers.
How to Change the Android Package Name
To update the Android package name, you must modify the Gradle build configuration.
Update applicationId in build.gradle
Open android/app/build.gradle and locate the defaultConfig block. Change the applicationId value to your new identifier:
android {
compileSdkVersion 34
defaultConfig {
// Update this line with your new package name
applicationId "com.yourcompany.newappname"
minSdkVersion 21
targetSdkVersion 34
versionCode 1
versionName "1.0"
}
}
Align the AndroidManifest.xml Package Attribute
While Gradle injects the applicationId into the manifest at build time, you should ensure the package attribute in android/app/src/main/AndroidManifest.xml matches for consistency:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.yourcompany.newappname">
<application
android:label="newappname"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher">
...
</application>
</manifest>
How to Change the iOS Bundle Identifier
iOS configuration requires updating the property list and potentially the Xcode project file.
Update CFBundleIdentifier in Info.plist
Open ios/Runner/Info.plist and modify the CFBundleIdentifier key:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleIdentifier</key>
<string>com.yourcompany.newappname</string>
<!-- Other configuration keys -->
</dict>
</plist>
Xcode Project Configuration
Alternatively, open ios/Runner.xcworkspace in Xcode, select the Runner project, navigate to the General tab, and update the Bundle Identifier field. This automatically synchronizes the value in ios/Runner.xcodeproj/project.pbxproj.
How to Change the Dart Package Name
If you want to change the import path used in Dart code, update pubspec.yaml:
name: new_app_name
description: A Flutter project with a new package name.
publish_to: 'none'
version: 1.0.0+1
environment:
sdk: '>=3.0.0 <4.0.0'
After changing this, update all import statements in your Dart files from package:old_name/ to package:new_app_name/.
Step-by-Step Guide to Rename Your Flutter Package
Follow this sequence to ensure all platform identifiers are updated correctly:
-
Backup your project before making structural changes to native configuration files.
-
Update Android by editing
android/app/build.gradleto set the newapplicationId, then verifyAndroidManifest.xmlaligns with the new name. -
Update iOS by modifying
ios/Runner/Info.plistto changeCFBundleIdentifier, or use Xcode to update the bundle identifier in the project settings. -
Update Dart (optional) by changing the
namefield inpubspec.yamland updating all Dart imports accordingly. -
Clean and rebuild by running
flutter cleanfollowed byflutter build apkorflutter build iosto generate new binaries with the updated identifiers.
How Flutter Generates Package Names Initially
When you create a new Flutter project using flutter create, the tool generates default package names based on the --org flag. According to packages/flutter_tools/lib/src/commands/create.dart, the tool uses this organization string as a prefix for both the Android applicationId and the iOS bundle identifier.
If you run flutter create --org com.yourcompany my_app, the tool sets:
- Android
applicationIdtocom.yourcompany.my_app - iOS
CFBundleIdentifiertocom.yourcompany.myApp
The same file validates that the project name is a valid Dart package name, ensuring consistency across the three platforms during initial creation.
Key Flutter Source Files for Package Management
The following files in the flutter/flutter repository define how package names are handled, validated, and used by the Flutter tool:
| File | Purpose |
|---|---|
packages/flutter_tools/lib/src/commands/create.dart |
Generates initial Android applicationId and iOS bundle identifiers from the --org flag during project creation. |
packages/flutter_tools/lib/src/commands/attach.dart |
Validates and references the "package name (Android) or bundle identifier (iOS)" when attaching to running applications. |
examples/hello_world/android/app/src/main/AndroidManifest.xml |
Demonstrates the package attribute location in Android manifests. |
examples/hello_world/ios/Runner/Info.plist |
Shows the CFBundleIdentifier key structure for iOS configuration. |
android/app/build.gradle (project level) |
Contains the applicationId field that defines the Android package name. |
ios/Runner/Info.plist (project level) |
Contains the CFBundleIdentifier that defines the iOS bundle identifier. |
Summary
- Android package name is the
applicationIdinandroid/app/build.gradle, optionally mirrored inAndroidManifest.xml. - iOS package name is the
CFBundleIdentifierinios/Runner/Info.plist, manageable through Xcode. - Dart package name is the
namefield inpubspec.yamland only affects import statements, not native app stores. - Always run
flutter cleanafter changing identifiers to ensure new binaries reflect the updates. - The Flutter tool generates default names using the
--orgflag duringflutter create, as implemented inpackages/flutter_tools/lib/src/commands/create.dart.
Frequently Asked Questions
What is the difference between the Android package name and the Dart package name in Flutter?
The Android package name is the applicationId defined in android/app/build.gradle that identifies your app on the Google Play Store and Android devices. The Dart package name is the name field in pubspec.yaml used only for Dart import statements (e.g., package:my_app/main.dart). Changing one does not automatically update the other.
Do I need to change the package name in AndroidManifest.xml if I update build.gradle?
Not necessarily. Modern Flutter projects use Gradle to inject the applicationId into the manifest at build time. However, if your AndroidManifest.xml contains an explicit package attribute that differs from your new applicationId, you should update it to match for consistency and to avoid namespace conflicts in native code.
Will changing the iOS bundle identifier affect my App Store listing?
Yes, the iOS bundle identifier (CFBundleIdentifier in ios/Runner/Info.plist) is the unique string that identifies your app on the App Store and user devices. Changing it after publication effectively creates a new app identity, meaning users will not receive updates to the previous version. You should only change this before initial release or when creating a distinct new application.
Is it safe to change the Dart package name in pubspec.yaml after starting development?
Changing the Dart package name is safe for local development but requires updating all import statements in your codebase from package:old_name/ to package:new_name/. If your project is published to Pub.dev or used as a dependency by other packages, changing the name breaks downstream consumers and should be avoided unless you are creating a new package identity.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →