Modifying the bundle identifier, package name & app display name in a Flutter app
This tutorial is part of the Flutter app build and release series. Here is list of all articles in this series.
- Set app icons in Flutter
- Modifying the bundle identifier, package name & app display name in a Flutter app
Android apps on the play store have a unique package name and iOS apps have bundle identifier that serves the same purpose. Often we create our project with some other package and name and before publish we need to change it so here is a guide for you to change the app display name as well as package/bundle id for both android and iOS platforms.
Changing the app display name
Android
android/app/src/main/AndroidManifest.xml
<application
android:name="io.flutter.app.FlutterApplication"
android:label="YourAppName"
android:icon="@mipmap/ic_launcher">
iOS
project/ios/Runner/Info.plist
<key>CFBundleName</key>
<string>YouAppName</string>
That’s all, your new app name will be displayed on the user’s phone now.
Bundle ID and Package Name
Changing package name for the Android platform
This needs to be changed in 4 places.
1. AndroidManifest.xml
This file will be found at 3 places. Repeat the replacement for all three files.
android/app/src/main/AndroidManifest.xml
android/app/src/debug/AndroidManifest.xml
android/app/src/profile/AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.newpackage.app">
2. App level build.gradle
android/app/build.gradle
defaultConfig {
applicationId "com.newpackage.app"
...
}
3. MainActivity
android/app/src/main/kotlin/your — -package/MainActivity.kt
If your app is using java instead of kotlin, it will be MainActivity.java within java folder.
Change the top package statement
package com.newpackage.app
import io.flutter.embedding.android.FlutterActivity
class MainActivity: FlutterActivity() {
}
4. The directory containing the MainActivity.kt file
The file from above step will be within com/example/domainname. You want to replace the ‘example’ with your domain name.
Right click on ‘example’ folder. Go to Refractor → Rename.
Change the name and click Refractor.
Now the new path should be like com/newpackage/app/
That is all. Now your android app is ready with new package.
Change Bundle Identifier for iOS Platform
iOS app has the bundle identifier set in Info.plist file as value for the key CFBundleIdentifier. First check and make sure that this key in Info.plist file points to a variable like this:
project/ios/Runner/Info.plist
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
So now we will find this variable and set its value. It will be present in the following file:
project/ios/Runner.xcodeproj/project.pbxproj file
Find the PRODUCT_BUNDLE_IDENTIFIER variable and change its value to the identifier you want to use.
This variable will be present in at least 3 places. So, you must run a search and replace all occurrences.
PRODUCT_BUNDLE_IDENTIFIER = com.newpackage.app;
That’s all for the iOS app.
Now just run the following command in your terminal and you are done.
flutter clean
— -
Alternative
Don’t like changing files in such a way? An alternative way would be to use this package.
Using this, you simply run these 2 commands in your terminal and your app name and identifiers will be changed.pub global run
rename --bundleId com.newpackage.appname
pub global run rename --appname "Your New App Name"
Creating project with proper identifier
As you can see, changing the package and bundle id requires quite some changes, so from the next time, you can run this command to create your project with the proper identifier.
flutter create --org com.yourdomain appname
That’s all. Thank you for reading. Good luck with your app release! Check out the other articles in this series [List at the top]. Let me know in the comments if you need tutorials on any other topic!
…
Originally published at Fabcoding.