41

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"

Meli Oktavia
  • 461
  • 1
  • 4
  • 6

7 Answers7

89

I 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 (File -> Sync Project with Gradle Files) and the root module name was updated.

ggorlen
  • 44,755
  • 7
  • 76
  • 106
Sumit Garai
  • 1,205
  • 8
  • 6
20

In root of your project open setting.gradle and change rootProject.name='YOUR NEW NAME'

then close and restart android studio

A Hashemi
  • 289
  • 2
  • 6
  • 5
    This is the [same answer](https://stackoverflow.com/a/60087611/3025856) that @Tarasantan four months ago. Please be sure to read existing answers prior to contributing a new one. – Jeremy Caney Jun 27 '20 at 20:18
  • 2
    Instead of closing and reopening AS, you can sync the project (File -> Sync Project with Gradle Files). – ggorlen Sep 20 '21 at 17:12
4

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.

Community
  • 1
  • 1
TT--
  • 2,956
  • 1
  • 27
  • 46
4

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)
4

Video tutorial: https://youtu.be/7aQjiae2doU

  1. Refactor the name to com.example.[NewFileName] in path:

    app>java>com.example.[OldFileName]


  1. Go to strings.xml and change code to <string name="app_name”>[NewFileName]</string> in path:

    app>res>values>strings.xml


  1. Go to build.gradle (Module: app) and change code to applicationId "com.example.[NewFileName]” in path:

    Gradle Scripts>build.gradle (Module: app)


  1. Go to settings.gradle (Project Settings) and change code to rootProject.name='[NewFileName]' in path:

    Gradle Scripts>build.gradle (Project Settings)


  1. Press Sync now prompt

  1. Rename your folder to [NewFileName] outside Android Studio

  1. Reopen your project and rebuild project in path:

    Build>Rebuild Project


myworldbox
  • 361
  • 6
  • 11
2

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:

Right-click it

Select Refactor

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

Shanto George
  • 994
  • 13
  • 26
  • Thanks I can rename the package name with your good solution, but I cannot rename the root module. When I renamed it, I got warning "can't rename root mdule". I have tried this soution : http://stackoverflow.com/questions/28568715/android-studio-project-root-directory-name-change-project-name-change but when I imported the project, the root module name, back to the origin name. – Meli Oktavia Aug 11 '16 at 03:04
0

Change in settings.gradle

dependencyResolutionManagement {
        repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
        repositories {
            google()
            mavenCentral()
            jcenter() // Warning: this repository is going to shut down soon
        }
    }
    
    rootProject.name = "project_name" // change this 
    
    include ':app'
Bhavesh Chand
  • 495
  • 6
  • 7