Renaming modules in Android Studio?

I picked the wrong name of a specific module which I imported to the Gradle project in Android Studio.

In this face I want to rename module Facebook1 to Facebook.

Is this possible in Gradle project and how to do it?


Android Studio >= 1.4.1

  1. Right click the module -> Refactor -> Rename.
  2. Enter the new name of the module, click OK.

Older versions of Android Studio

The following worked for me, tested in Android Studio (AS) 1.1 & 1.0.2, directly after importing a project.

Under the 'Android' tree view (ATV),

  1. Right click the module name: app, Refactor -> Rename (to myApp, click ok)

  2. Open settings.gradle

  3. Change ':app' to ':myApp', and save

  4. You will be prompted to 'Sync Now', do it (the prompt is a blue link above the file)

    (Your project will disappear from ATV, but don't worry, just exit AS)

  5. From a file manager (outside of Android Studio), open your project root directory, and rename the folder app to myApp

  6. Re-open your project in AS, and you will see your module and Gradle scripts re-appear under ATV! :)

Congratulations - your module has now been renamed! (whew, time for some tea)


In the project view on the left in Android Studio,

  1. right click on the module whose name you want to change
  2. select 'refactor' -> 'rename'
  3. choose the rename module option
  4. follow step 1 - 2 and then rename the directory too

Android Studio 1.3.2,
1. switch Project view on the left in Android Studio
2. right click module which want to change -> Refactor -> Rename
3. do both "Rename directory" and "Rename module"
4. open settings.gradle, change module name
5. Build -> Clean Project


You can do it manually, with or without changing the folder structure (consider not change it for a minor impact on version controlling)

Changing folder name accordingly

1- open settings.gradle and change the name of your module (exemple from ':facebook1' to ':facebook')

2- change the folder name accordingly (from xxx/facebook1 to xxx/facebook)

3- If other Modules have dependencies on it: open the corresponding build.gradle and change dependency (from compile project(':facebook1') to compile project(':facebook') )

Without changing folder name

1- open settings.gradle and change the name of your module (exemple from ':facebook1' to ':facebook')

2- add a new line on "settings.gradle":

project(':facebook').projectDir = new File(settingsDir, '/facebook1')

3- If other Modules have dependencies on it: open the corresponding build.gradle and change dependency (from compile project(':facebook1') to compile project(':facebook') )


As of Android Studio 3.4.1

Rename module

  1. In Project window, right-click module and select Refactor > Rename
  2. Choose Rename module and press OK
  3. Enter new module name and press OK
  4. Important settings.gradle is updated automatically. However, you must manually update any build.gradle dependencies to reflect new module name:
dependencies {
    // manually update this after renaming the module
    implementation project(':newmodulename')
}

Rename package to reflect new module name

  1. In Project window, right-click desired package and select Refactor > Rename
  2. If there are other src sets with same package name (test or androidTest), a dialog will ask if you want to rename them as well. If so, select Rename package
  3. Enter new package name and press Refactor
  4. Select Do Refactor in the Refactoring Preview

Tip: Select File > Invalidate Caches / Restart to fix any unresolved resource references caused by renaming a module.