Renaming Your Flutter Package

Jackie Moraa
2 min readDec 10, 2021

It wasn’t until the other day when I was connecting my Flutter App to Firebase that I realised I needed to know how to rename my Flutter package. (Perhaps I’ll do a write up on my process to connect Flutter and Firebase in the near future).

Photo by Jess Bailey on Unsplash

If you are familiar with Firebase, you know that you need to specify a package name at some point during the process of adding the new project. Now, when I did this, I used a package name which was not similar to that of the app I had already created in Flutter — the package name used in Firebase needs to be the same as the one in your Flutter app — hence the need to rename. I figured it would be easier to just rename the package in Flutter as opposed to re-creating a new project in Firebase to match the package name already created in Flutter. Then … “error has entered the chat!” lol.

So after failing a couple of times and reading a number of answers on various sites, the following steps helped solve the issue.

When you create flutter apps, a default package name is created. (Unlike with native Android apps where you get to specify your package name when you create the project). And this default package name is referenced across a number of files. So all those files need to be updated in order for the new package name to take effect.

build.gradle at the project level
…/android > app > build.gradle

defaultConfig {
applicationId "com.example.old_name" //rename package here
minSdkVersion 16
targetSdkVersion 30
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}

AndroidManifest.xml
../android > app > src > (debug/main/profile) > AndroidManifest.xml
There are three manifest files: debug, profile and main. All the package names in these files need to be updated.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.old_name"> //rename package here on 3 files
<uses-permission android:name="android.permission.INTERNET"/></manifest>

MainActivity.kt or MainActivity.java
../android > app > src > main > (java/kotlin) MainActivity
Your project may have one or the other.

package com.example.old_name //rename package hereimport io.flutter.embedding.android.FlutterActivityclass MainActivity: FlutterActivity() {}

And that’s it. The package is now renamed!

However, if you are one who usually has the end in mind, you can specify the package name when creating your app by simply running:

flutter create --org com.your_domain appname

And the resulting package name will be

com.your_domain.appname

Also, there are plugins that are said to change the package names. I didn’t have success with the first one and I didn’t attempt the second one.

https://pub.dev/packages/change_app_package_name
https://pub.dev/packages/rename

If you have managed to use any of them and had success, you can let me know. And also if you know of other nifty shortcuts that would come in handy!

As always, thank you for reading ❤

--

--