Changing the project name

Flutter

Flutter Problem Overview


Is it possible changing the project name of a Flutter project? With project name I mean the name you provide when creating a flutter project flutter create name.

Flutter Solutions


Solution 1 - Flutter

That depends on what you are trying to achieve. If you want to change the name of the app which is displayed in the mobile phones menu together with the app icon, you have to change the android:label in the android/app/src/main/AndroidManifest.xml (Code Sample 1) and the CFBundleName in the ios/Runner/Info.plist (Code Sample 2).

Last time I did this it took me ages to find out, why the name of the app was not changed in the list of currently running apps on Android. For that you also need to change the title of your MaterialApp (Code Sample 3).

For renaming it everywhere I would suggest to use search and replace in the project. If you do this, you have to choose a name without spaces or special characters. A project name 'new project' in the pubspec.yaml for example will break the build.

Code Sample 1:

<application
    android:name="io.flutter.app.FlutterApplication"
    android:label="New Name"
    android:icon="@mipmap/ic_launcher">  

Code Sample 2:

<key>CFBundleName</key>
<string>New Name</string>

Code Sample 3:

return new MaterialApp(
  title: 'New Name'
  ...);

Solution 2 - Flutter

To change project name , you need to change it for all platforms .

You can use rename package to make it easy .
Run this command inside your flutter project root

pub global run rename --appname "Application Name"

You can also specify the platform you want to apply the change

pub global run rename --appname yourappname -t macOS  // support also ios and android

or

Edit AndroidManifest.xml for Android and info.plist for iOS

Do a flutter clean and restart your application if you have a problem.

Solution 3 - Flutter

To add to Rainer's answer, you may also have to change the com.example.myprojectname file under android/app/build.gradle

Also for the com.example.myprojectname, do not use underscores (ie: com.example.my_project_name)

You may also have to find and replace the com.example.myproject name in the files project.pbxproj and MainActivity.java.

Solution 4 - Flutter

If you want to change the project name, simply change it in all these files.

  1. build.gradle (app)
  2. AndroidManifest.xml
  3. MainActivity.java

Rebuild your app and you should be good to go.

Solution 5 - Flutter

You can let flutter do this for you:

Using Terminal:

cd /path/to/existing/flutter_project
flutter create --project-name newprojname --org com.yourorgdomain .

Next change the name on line 1 of pubspec.yaml

Trash all generated folders to remove all references of the old project name.

> NB - Some import statements will need to have their package references > updated manually to the new name. Review the project structure (in > your IDE) for any references to the old project name inside of IDE > generated files.

Recreate the trashed generated files by using flutter create . (including the space and period at the end) from within the project folder.

Now run flutter clean then debug as normal

Gotchas

You should expect that the project name still resides in all the generated folders for the various environments and in comments/strings. You can use a tool to search all files in the project or folder structure (e.g Cmd + Shift + F in Android Studio or ag {the_silver_searcher in Homebrew}) to find the old name and trash any generated folders including ios, windows, linux. After trashing the generated folders remember to re-create them by running flutter create .

Solution 6 - Flutter

1-flutter clean

2- Search and replace all OLD_PROJECT_NAME with NEW_PROJECT_NAME

3- Search for OLD_PROJECT_NAME in the project folder, and replace them with NEW_PROJECT_NAME one by one. Some of them are in the text files, make sure that you have changed them too.

Solution 7 - Flutter

If you are using Android Studio, follow these steps:

  1. Right-click your project in the Project window (Alt+1 to show).
  2. Click Refactor > Rename.
  3. Enter new name.

This will rename the project's name on all required places except in the test directory.

Solution 8 - Flutter

Steps to rename your project: (For Editors that has search & replace across project feature)

  • Use VSCode's any other editor's search and replaceAll across entire project feature. But always turn on the match cases (for vscode: located on right side).
    • You have to do this two time as for the first you have to replace com.orgname.currentname with com.orgname.newname then
    • currentname with newname.
  • Rename the folders inside /android/app/src/main/kotlin/com/orgname/currentname to new /android/app/src/main/kotlin/com/orgname/newname.
  • If you're using only Java with flutter than just replace the kotlin with java.
  • rename the currentname.iml of your root project folder to newname.iml

Solution 9 - Flutter

Ctrl+Shift+R then Replace for one by one replace
or Replace All for all at a time.
Be cautious , if your project name is similar with other variable or class name then don't do that. Before doing that check twice.

Solution 10 - Flutter

If you are using Android Studio, from the Menu > Edit > Find > Replace in files > Enter old and new name...

enter image description here

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBram VanbilsenView Question on Stackoverflow
Solution 1 - FlutterRainer WittmannView Answer on Stackoverflow
Solution 2 - FlutterKab AgoudaView Answer on Stackoverflow
Solution 3 - FlutterLawrence DuView Answer on Stackoverflow
Solution 4 - FlutterCopsOnRoadView Answer on Stackoverflow
Solution 5 - FlutterTommie C.View Answer on Stackoverflow
Solution 6 - FlutterasasahinView Answer on Stackoverflow
Solution 7 - FlutterbasedusamaView Answer on Stackoverflow
Solution 8 - FlutterKR TirthoView Answer on Stackoverflow
Solution 9 - FlutterSK. FuadView Answer on Stackoverflow
Solution 10 - Flutterthanhbinh84View Answer on Stackoverflow