Renaming modules in Android Studio?

前端 未结 9 2513
闹比i
闹比i 2020-12-12 18:05

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

\"\"

相关标签:
9条回答
  • 2020-12-12 18:40

    In AndroidStudio 2.2.2 renaming the module alone via refactor/rename worked for me. (32-bit linux Mint)

    The rename dialog presents two options: "directory" or "module" (radio buttons so mutually exclusive, at least in one pass). I wasn't sure which to pick so I ended here looking for an answer. One answer said "do both" as two steps, another answer said "do module, then directory" as two steps. So I chose "module" first. To my surprise that was all that was needed, both module and directory were changed. settings.gradle was updated by the refactor/rename in the one step as well.

    "gradle synce" and "clean build" were also triggered. Upon build to my tablet, no complaint about the name change.

    just adding this answer in case someone else with 2.2.2 or later is unsure which to pick. Also to re-iterate what others have said, back up your project first.

    0 讨论(0)
  • 2020-12-12 18:40

    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.

    0 讨论(0)
  • 2020-12-12 18:43

    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
    0 讨论(0)
提交回复
热议问题