478

Is there any way to change Package Name of Flutter project?

I want to change package name and application name in flutter project.

Abc Xyz
  • 5,907
  • 5
  • 11
  • 7
  • 8
    Just search and replace all occurrences of the old package name in all files. There is no command or similar to update the name yet. – Günter Zöchbauer Jul 26 '18 at 09:00
  • 19
    When you create a new project you can specify the package name with `flutter create --org com.domain app_name` – Victor Apr 14 '20 at 10:35
  • Does this answer your question? [How to change app package name in Flutter without using Android Studio?](https://stackoverflow.com/questions/60400655/how-to-change-app-package-name-in-flutter-without-using-android-studio) – Jannie Theunissen Jul 30 '21 at 14:53
  • 1
    @JannieTheunissen That question seems to be more specific than this one. If anything, that one should be closed as a duplicate of this question. – cigien Jul 30 '21 at 23:18
  • @Victor The `app_name` will be appended as a package so in the end you will have something like `com.domain.app_name`. So if you have a domain subdomain like `app.foo.com` and you want to create the app with name `app` you will end-up with `com.foo.app.app` which is ugly – Alex Nov 02 '22 at 14:35

34 Answers34

681

For Android App Name

Change the label name in your AndroidManifest.xml file:

 <application
    android:name="io.flutter.app.FlutterApplication"
    android:label="TheNameOfYourApp"   

For Package Name

Change the package name in your AndroidManifest.xml (in 3 of them, folders: main, debug and profile, according what environment you want to deploy) file:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="your.package.name">

Also in your build.gradle file inside app folder

defaultConfig {
    applicationId "your.package.name"
    minSdkVersion 16
    targetSdkVersion 27
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

Finally, change the package in your MainActivity.java class (if the MainActivity.java is not available, check the MainActivity.kt)

    package your.package.name;

    import android.os.Bundle;
    import io.flutter.app.FlutterActivity;
    import io.flutter.plugins.GeneratedPluginRegistrant;
    public class MainActivity extends FlutterActivity {

Change the directory name:

From:

  android\app\src\main\java\com\example\name

To:

  android\app\src\main\java\your\package\name
  

EDITED : 27-Dec-18

for package name just change in build build.gradle only

defaultConfig {
    applicationId "your.package.name"
    minSdkVersion 16
    targetSdkVersion 27
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

For iOS

Change the bundle identifier from your Info.plist file inside your ios/Runner directory.

<key>CFBundleIdentifier</key>
<string>com.your.packagename</string>

UPDATE

To avoid renaming the package and bundle identifier, you can start your project using this command in your terminal:

flutter create --org com.yourdomain appname
diegoveloper
  • 93,875
  • 20
  • 236
  • 194
  • 2
    I had to update the directory name below too (changing 'example' to 'woods') C:\Users\andytwoods\IdeaProjects\gear_log\android\app\src\main\java\com\woods\gearlog – andyw Oct 24 '18 at 10:14
  • 1
    How about for iOS? – Suragch Mar 12 '19 at 17:23
  • 1
    @Suragch change the bundle identifier from your Info.plist file – diegoveloper Mar 12 '19 at 17:23
  • 33
    My bundle identifier is `$(PRODUCT_BUNDLE_IDENTIFIER)`. Where is that variable hiding? – Suragch Mar 12 '19 at 17:26
  • 3
    search the variable : PRODUCT_BUNDLE_IDENTIFIER – diegoveloper Mar 12 '19 at 17:26
  • 9
    PRODUCT_BUNDLE_IDENTIFIER is stored in multiple places in project.pbxproj file the ios/Runner.xcodeproj directory. – Safa Alai May 02 '19 at 19:52
  • 11
    It's worth mentioning that the appID must be in the format of 3 words separated by dots. – r_a_k Aug 03 '19 at 17:15
  • So I only have to change the package name in build.gradle file ? how does the manifest and directory structure get updated? – user2570135 Sep 14 '19 at 19:25
  • 1
    The MainActivity.kt for the new flutter auto generated app – Mohamed Dernoun Oct 23 '19 at 07:53
  • @diegoveloper Do I have to search and replace all PRODUCT_BUNDLE_IDENTIFIER values inside project.pbxproj OR I can simply update Info.plist once? – Raj Chaudhary Jul 08 '20 at 08:33
  • You can open xcworkspace file and change bundle identifier there for the target. Info.plist will pick that variable. – Amber K Aug 05 '20 at 14:17
  • if you get "Execution failed for task ':app:processDebugManifest'." - There is also a debug manifest at android > app > src > debug > AndroidManifest.xml You might also want to change the package name there as well – Divakar Rajesh Aug 23 '20 at 13:59
  • I don't have this android\app\src\main\java\com\example\name directory in my project should I create it? – AliAzad Aug 24 '20 at 04:25
  • @diegoveloper may be you can check this question https://stackoverflow.com/questions/64186598/flutter-notificationlistener-in-tabcontroller-for-infinite-scroll – Roxx Oct 04 '20 at 02:54
  • Getting this error for Android `Overlay manifest:package attribute declared at has a different declared in main manifest at AndroidManifest.xml` – Shajeel Afzal Nov 30 '20 at 18:45
  • Note that most new Flutter apps come with MainActivity.kt instead of MainActivity.java. Remember to rename the package declaration at the top of this one and move it to a subfolder that reflects the new package name. – Dzhuneyt Jul 03 '21 at 19:49
  • 1
    Additionally i have updated. ` – byJeevan Jul 10 '21 at 14:25
  • easy way to update package name is https://pub.dev/packages/change_app_package_name – SULPHURIC ACID Jul 26 '21 at 06:35
  • namespace also needs to be updated in build.gradle android { namespace "com.newpackage.name" } – SWIK Aug 23 '23 at 10:38
143

Changing name manually doesn't seem to work, throws gradle errors, well in my case it does throw error.

So I usually create a new flutter project.

I use below mentioned command to create a new flutter app

flutter create --org com.yourdomain appname

your project will have the package name as -> com.yourdomain.appname


if you just want to keep your package name as com.appname then make some changes as below

flutter create --org com appname

to add java instead of kotlin for android add -a java

flutter create -a java --org com.yourdomain appname

EDIT


If you have already created a project you can use change_app_package_name package to change the package name.

flutter pub run change_app_package_name:main com.package.appname
Vicky Salunkhe
  • 9,869
  • 6
  • 42
  • 59
  • 7
    'flutter create --org com.yourcompany --project-name new_app_name .' (add the period if you are inside the existing project -- you should trash the android and ios folders first to have them regenerated). MAKE A BACKUP should be an important prerequisite for the answer. – Tommie C. Jan 31 '20 at 17:21
  • you can create a new project and then just copy over the pubspec.yaml dependencies, run pub get, and then copy your dart files from the lib folder – Filippos Zofakis Sep 28 '20 at 16:15
87

For those like me that doesn't like to change specific files, I've used https://pub.dev/packages/rename.

Using this, you simply run these commands in your terminal and your app name and identifiers will be changed.pub global run

Installing: pub global activate rename

And then, Run this command inside your flutter project root.

pub global run rename --bundleId com.example.android.app --target android

finx
  • 1,293
  • 9
  • 9
50

Android

In Android the package name is in the AndroidManifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    ...
    package="com.example.appname">

iOS

In iOS the package name is the bundle identifier in Info.plist:

<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>

which is found in Runner.xcodeproj/project.pbxproj:

PRODUCT_BUNDLE_IDENTIFIER = com.example.appname;

Changing the name

The package name is found in more than one location, so to change the name you should search the whole project for occurrences of your old project name and change them all.

Android Studio and VS Code:

  • Mac: Command + Shift + F
  • Linux/Windows: Ctrl + Shift + F

Thanks to diegoveloper for help with iOS.

Update:

After coming back to this page a few different times, I'm thinking it's just easier and cleaner to start a new project with the right name and then copy the old files over.

Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393
  • Hi I have a question. It might not related to Flutter topic but how can I push the renamed project to a current project on github if I create a new project? – Ooto Nov 02 '20 at 15:43
  • 1
    @Ooto, You can delete the old project (except for the `.git` directory at the root) and then put the new project in the same directory as the old one. Then commit and push the changes. – Suragch Nov 02 '20 at 23:42
33

This is how i renamed package for both ios and android

  1. Go to build.gradle in app module and rename applicationId "com.company.name"
  2. Go to Manifest.xml in app/src/main and rename package="com.company.name" and android:label="App Name"
  3. Go to Manifest.xml in app/src/debug and rename package="com.company.name"
  4. Go to Manifest.xml in app/src/profile and rename package="com.company.name"
  5. Go to app/src/main/kotlin/com/something/something/MainActivity.kt and rename package="com.company.name"
  6. Go to app/src/main/kotlin/ and rename each directory so that the structure looks like app/src/main/kotlin/com/company/name/
  7. Go to pubspec.yaml in your project and change name: something to name: name, example :- if package name is com.abc.xyz the name: xyz
  8. Go to each dart file in lib folder and rename the imports to the modified name.
  9. Open XCode and open the runner file and click on Runner in project explorer.
  10. Go to General -> double click on Bundle Identifier -> rename it to com.company.name
  11. Go to Info.plist click on Bundle name -> rename it to your App Name.
  12. close everything -> go to your flutter project and run this command in terminal flutter clean
Gagan Raghunath
  • 1,673
  • 1
  • 8
  • 5
29

Change name attribute in pubspec.yaml (line 1)

For the name of apk, change android:label in AndroidManifest.xml

CopsOnRoad
  • 237,138
  • 77
  • 654
  • 440
Fa Kur
  • 323
  • 2
  • 2
29

As easy as possible use this change_app_package_name package first add dependencie

 dev_dependencies: 
  change_app_package_name: lates version

and then run this command

flutter pub run change_app_package_name:main com.new.package.name
samad shukr
  • 561
  • 7
  • 15
21

Quickest and cleanest way to change your package name!

Warning:

If you have edited the contents of the folders android/, ios/ and windows/, you need to make sure you have those changes backed up somewhere before proceeding.

1. Delete your folders at the root of your flutter project:

  • android/
  • ios/
  • windows/
  • build/

Let's say you want to rename from com.oldcompany.oldproject to com.newcompany.newproject.

2. Launch the following command from the root of your project:

flutter create --org com.newcompany --project-name newproject .

If you want to limit your projects to specific platforms (for example android and iOS) run :

flutter create --platforms=android,ios --org com.newcompany --project-name newproject .

PS:
To make sure everything is set up correctly, you can search for your package names in your files, by running the following commands

grep --color -r com.oldcompany.oldproject *
grep --color -r com.newcompany.newproject *
Jack'
  • 1,722
  • 1
  • 19
  • 27
  • 2
    This is the best answer, definitely the cleanest and quick solution! In case you've modified platform specific files, be sure to backup them and put the changes back. The easiest way is to use GIT repo and go through changes this process did. – Micer Jan 08 '21 at 22:09
  • 2
    This is the quickest and most straightforward solution by far. Please remember to back up any files in **android/** and **ios/** before deleting them! – gmdev Mar 30 '21 at 23:47
  • 1
    I also deleted macos/ and web/ folders; However I didn't deleted the build/ folder (I didn't have it). Then the flutter create command re-generated all those folders in a clean way. Great. – Yoric Oct 03 '22 at 07:19
16

If you not started the project, this is the best possible way.

flutter create --org com.yourdomain appname

If you already created the project, install this package in your dev_dependencies and run this command.

flutter pub run change_app_package_name:main com.new.package.name

This will change all the complex stuffs of changing package name in android. And right click on the iOS folder of flutter and open with Xcode.

In Xcode > select Runner > In general tab you can change the bundle Identifier.

This is the easiest possible way if you already created a project and don't know the complexity of change the package name.

MBK
  • 2,589
  • 21
  • 25
16
  1. First, run this in your terminal

    dart pub global activate rename

  2. Run this in your Flutter Project Root Directory

    dart pub global run rename --bundleId com.company.appname --target android

This will update the gradle build file with right id in defaultConfig

 defaultConfig {
        applicationId "com.company.appname"
        minSdkVersion 21
        targetSdkVersion 33
        versionCode flutterVersionCode.toInteger()
 }

And that's everything, now you changed your package name :)

enter image description here

Zhar
  • 3,330
  • 2
  • 24
  • 25
Vasanth Korada
  • 267
  • 3
  • 3
  • In my case this wasn't enough...Many errors were happening because a lot of auto-generated folders and imports inside the code had the old package name. I had to change the MainActivity.kt import manually among many other folder and code changes. And even worse...I forgot about my local git and my remote git...It'd be a good idea to create a new branch to attempt this...just in case... – Ramiro G.M. Apr 30 '23 at 05:14
11

Updated You have to change the package name to your desired package name in these five locations.

1.) src/profile/AndroidManifest.xml
2.) src/debug/AndroidManifest.xml
3.) src/main/AdroidManifest.xml
4.) app/build.gradle
     build.gradle .
       defaultConfig {
           applicationId
       }
5.) MainActivity.java or MainActivity.kt on "package"

the last step is to run flutter clean

Amoo Faruk
  • 63
  • 5
Atul Chaudhary
  • 1,491
  • 2
  • 15
  • 23
  • when changing package name , in the module-android , need to change folders name. ( example : com.google.app ) has 3 folder named com & google & app . – Esmaeil Ahmadipour May 12 '22 at 13:04
9

change in all AndroidManifest.xml files of your Flutter Project, --> package="your.name.app" (app/src/debug/AndroidManifest.xml) and (app/src/main/AndroidManifest.xml) and (app/src/profile/AndroidManifest.xml)

good look !!

Percy Rojas
  • 201
  • 2
  • 1
9

On Visual Studio code

Edit > Replace in Files

vs code replace in files

On Android studio

1. Right click on your project > Replace in path

replace in path

2. Write your old package and new package > Replace all

replace all screenshot

shb
  • 5,957
  • 2
  • 15
  • 32
9

According to the official flutter documentation you just need to change the ApplicationId in app/build.gradle directory. Then you have to just build your apk and the package name of the manifest file will be changed according to the ApplicationId you changed in build.gradle. Because of flutter while building an apk and google play both consider ApplicationId from build.gradle. This solution worked for me.

source: Official Documentation

Sunil Lulla
  • 797
  • 10
  • 18
yash
  • 91
  • 1
  • 3
7

Change App Package Name easily using change_app_package_name package

just add the above package in dev dependencies

dev_dependencies:
  flutter_test:
    sdk: flutter
  change_app_package_name: ^0.1.2

and run the following command, replace "com.new.package.name" with your new package name

flutter pub run change_app_package_name:main com.new.package.name

Package Link on Pub Dev

screenshot of Package

Javeed Ishaq
  • 6,024
  • 6
  • 41
  • 60
6

the right to change path for default way for both Android and Ios.

for Android

open AndroidManifest.xml,

  • go to this path.

app/src/main/AndroidManifest.xml

  • select on package name, and right click,

enter image description here

  • after click on rename, rename popup(dialog) show.

enter image description here

  • enter the new package name here,

enter image description here

  • after changes name text, click on refactor button.

__________________________________________________________________________

for Ios

  • select ios folder from drawer, and right click on these,

enter image description here

  • select,and double click on Runner in drawer,and then select General

enter image description here

  • and then, change your Bundle Identifier(Package Name).
  • after changes Bundle Identifier(Package Name), Your Package Name is changed for Ios.
Shirsh Shukla
  • 5,491
  • 3
  • 31
  • 44
6

To change package name in flutter , you have to do it for all platforms.

To make it easier, I suggest you to use rename package .

Just run this command inside your flutter project root.

pub global run rename --bundleId com.onat.networkApp

Here, com.onat.networkApp is your package name

To target a specific platform use the "-t" option. e.g:

pub global run rename --bundleId com.example.android.app -t android

You can learn more about rename package here

Kab Agouda
  • 6,309
  • 38
  • 32
5

Change App Package Name with single command by using following package. It makes the process very easy and fast.

flutter pub run change_app_package_name:main com.new.package.name

https://pub.dev/packages/change_app_package_name

Aung Ko Man
  • 502
  • 6
  • 13
3

Even if my answer wont be accepted as the correct answer, I just feel all these answers above caused me to have more problems here is how I fixed it

  1. Get Sublime Text (crazy, right? No, just follow my steps)
  2. Click on file and select open folder, then choose the folder of the project you are working on
  3. Now click on Find from the Tabs, and select find in files or just do Ctrl + Shift + F (for Windows users, for mac users you already know the drill)
  4. Now copy and paste exactly the name of the package you want to change in the Find section and paste in the replace section what you would like to replace the package name with.
  5. Click on FIND (do not click on REPLACE just yet).
  6. Now clicking on Find lists all available package name in your project which matches your search criteria, if you are satisfied with this then repeat from no. 3 but this time click on REPLACE.
  7. Rebuild your project and have fun

Conclusion: a simple find and replace program is all you need to sort this problem out, and I strongly recommend Sublime Text 3 for that.

halfer
  • 19,824
  • 17
  • 99
  • 186
  • 2
    It is required to also update the file path as @diegoveloper suggested in his answer. By searching, we cannot search the path. – Rahmat Ali Aug 04 '20 at 11:46
3

After trying all of the above. Simple work for me to rename package flutter with Android Studio:

Step 1:

Mac: Command + Shift + R

Linux/Windows: Ctrl + Shift + R

After change to new package and press Replace All and wait Android Studio run finish.

flutter rename package in Android Studio

Step 2:

Next, go to AndroidManifest.xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="your.package.name">

and copy package name and do the same Step 1 to rename package in AndroidManifest and build.gradle.

Finally, change the package in your MainActivity.java class (if the MainActivity.java is not available, check the MainActivity.kt)

package your.package.name;

import android.os.Bundle;
import io.flutter.app.FlutterActivity;
import io.flutter.plugins.GeneratedPluginRegistrant;
public class MainActivity extends FlutterActivity {

Change the directory name. For details see the following link this:

From:

android\app\src\main\java\com\example\name

To:

android\app\src\main\java\your\new_package\name

Doan Bui
  • 3,572
  • 25
  • 36
2

EASY way, in editor search E.g.VS CODE your.package.name E.g com.example.application through all files.,

  • 3 AndroidManifest files(profile, debug, main)
  • 1 build.gradle
  • 1 java or kt file

these will popup

Replace all these and voila. If you have already build your project, numerous files will popup in the build directory, you can ignore that files, no need to change those

Ajay Tom George
  • 1,890
  • 1
  • 14
  • 26
2

As of Android Studio 4.1.3, changing package name couldn't be more easy.

If you don't use Firebase or any other external service, just change the package name in these files:

  1. In the build.gradle (app) file
  2. In the Manifest file (main, debug and profile)
  3. Package import in code files (Android Studio. will handle the changes)

NOTE: Also change the directory name (under Kotlin or Java).

If you use Firebase or any other external Service, you need to change the package name there too.

Dhruvam Sharma
  • 1,661
  • 14
  • 22
2

Add Change App Package Name to your pubspec.yaml in dev_dependencies: section.

dev_dependencies:

change_app_package_name: ^1.1.0

Update dependencies flutter pub get

Run this command to change the package name.

flutter pub run change_app_package_name:main com.new.package.name

Where com.new.package.name is the new package name that you want for your app. replace it with any name you want.

kayTech
  • 21
  • 1
2

if you are using VS Code, you could replace all your com.example to your package name

To do so, CTRL+SHIFT+H set the word to replace com.example set the word replace with [your package] then REPLACE ALL

Anah
  • 51
  • 3
1

I had two manifest.xml file in my app section,so I needed to change package name in bothHere you can see

Progga Ilma
  • 578
  • 6
  • 8
1

In Android, change application id in

> build.gradle

file and iOS change

> bundle name from project settings.

Community
  • 1
  • 1
1

If you don’t like changing files in such a way then alternative way would be to use this package.

https://pub.dev/packages/rename

rename --bundleId com.newpackage.appname
pub global run rename --appname "Your New App Name"

Using this, you simply run these 2 commands in your terminal and your app name and identifiers will be changed.pub global run

mr.boris
  • 3,667
  • 8
  • 37
  • 70
  • 1
    This seems to have only changed the applicationId in one place (build.gradle). It did not update AndroidManifest. Did you get a different result? – Swift Dec 18 '20 at 04:43
1

I have done global search for existing package name, and changed all fields with new package name. Then changed

app->src->main->yourOldFolderName

folder name as per new package name. After that, changed all imported package name to new package name. It was a lot of manual work but was worth it, without any issues.

Note: Watch for the blank space before package name it may give built errors

Short-cuts:

global search- ctrl+shift+f

To change package

file search- ctrl+f

To change import package name

Sweta Jain
  • 3,248
  • 6
  • 30
  • 50
Vinay Bakle
  • 133
  • 13
1

Use this plugin (2022)

https://pub.dev/packages/change_app_package_name

Usage

flutter pub run change_app_package_name:main com.new.package.name

Old Package Name: com.example.oldname
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
Dabbel
  • 2,468
  • 1
  • 8
  • 25
0

You can follow this official documentation by Google: https://developer.android.com/studio/build/application-id.html

Application ID should be changed in Build.gradle, while package name can be changed in AndroidManifest.xml.

However one should be careful changing package name.

Also while re uploading the app, one should be careful since it matches the application ID of previously uploaded app with new upload.

Abby
  • 51
  • 4
0

I don't think it's the proper solution for the problem. But you can just create a new project with the package name you want and then copy all the source files to the new project from your existing projects.

**NOTE: You'll have to copy all the contents of pubspec too. In the case of firebase and other APIs, that solution may be a bit lengthy.

0

In Vs Code, What I did was search and replace it all and it worked! like a charm.

com.example.appName

restart your vs code.

enter image description here

Jalo Lagunoy
  • 109
  • 1
  • 1
0

Step by step

  1. Open the project folder in your preferred IDE.

  2. Locate the pubspec.yaml file in the root of the project.

  3. Add the following line to the pubspec.yaml file:

name: <your_new_package_name>

  1. In the same directory, open `android folder.

  2. Open app folder and locate the build.gradle file.

  3. Replace the current package name with your new package name.

  4. Open ios folder.

  5. Locate Runner.xcodeproj file in the ios folder.

  6. Open the info.plist file.

  7. Replace the current package name with your new package name.

  8. Save all changes and close the files.

  9. Run the command flutter clean.

  10. Finally, run the command flutter pub get.

Bawantha
  • 3,644
  • 4
  • 24
  • 36
-1

One-liner:

for F in $(grep -F "com.old.old" . -Rl); do sed -i 's|com\.new\.new|com\.new\.new|g' ${F}; done
Fmstrat
  • 1,492
  • 2
  • 17
  • 24