How to rename root module in android studio? I have tried (right click the module then click refactor then click rename) but I got warning “can’t rename root module”
This is tested for a pure Java projects (without any C/C++ code):
- close the project and make a copy of the folder containing it
- rename the new copied folder to reflect new project name
- delete all *.iml files
- reopen the project: Android Studio will resync Gradle, rebuild iml files
- review the modules.xml file to remove reference to old project name
- new project renamed works exactly as previous one: you can run the app without completely reinstalling it (all previous app data/settings/cache will be preserved)
In your Project pane, click on the little gear icon ( setting icon at the right top)
Uncheck / De-select the Compact Empty Middle Packages option
Your package directory will now be broken up in individual directories
Individually select each directory you want to rename, and:
Click on Rename
In the Pop-up dialog, click on Rename Package instead of Rename Directory
Enter the new name and hit Refactor
Allow a minute to let Android Studio update all changes
Note: When renaming com in Android Studio, it might give a warning. In such case, select Rename All
I just pressed ctrl+shift+F to search my current root module name,and found the name to be in the settings.gradle file as rootProject.name= ,I renamed it and synced the project, now the root module name is changed.
Close the project. (File > Close)
Rename the root folder of the project.
At the welcome screen “Open an existing Android Studio project” and provide the new path.
On your link that’s the second answer or see also here.
Video tutorial: https://www.youtube.com/watch?v=2Ef8v4KH0cA
- Refactor the name to com.example.[NewFileName] in path:
- Go to strings.xml and change code to
<string name="app_name”>[NewFileName]</string>in path:
- Go to build.gradle (Module: app) and change code to
applicationId "com.example.[NewFileName]”in path:
Gradle Scripts>build.gradle (Module: app)
- Go to settings.gradle (Project Settings) and change code to
Gradle Scripts>build.gradle (Project Settings)
- Rename your folder to [NewFileName] outside Android Studio
- Delete [OldFileName].iml and app.iml in path:
[OldFileName]>[OldFileName].iml and [OldFileName]>app>app.iml
- Reopen your project.
- Clean and rebuild project in path:
Build>Clean Project and Build>Rebuild Project