Rename package in Android Studio

后端 未结 30 1903
深忆病人
深忆病人 2020-11-21 05:21

How do you rename packages in the new IDE Android Studio, based on IntelliJ IDEA?

Is there an automatic refactoring included?

I want to make bulk refactorin

30条回答
  •  臣服心动
    2020-11-21 06:01

    I tried the two top-voted solutions but found some issues even though both work to some extent.

    • List item: The new package-drag-drop method leaves some unchanged and creates some undesired effects
    • List item: The rename package only changes the last part of package name

    After some experiments I found the following method works well for me.

    If you just need to change the last part of package name, use the method outlined by GreyBeardedGeek, namely

    Right-click on the package in the Project pane. Choose Refactor -> Rename from the context menu

    If you need to change the whole package name, do the following.

    Right-click on the package in the Project pane. Choose Refactor -> Move from the context menu

    This will create a new package folder (when necessary) but will keep the last part of your package name as before. If you need to change the last part, do the rename accordingly.

    Note also that you may need to modify package names in e.g. build.gradle, manifest, and/or any xml resource files, or even in your code if hardcoded. After all that, do Sync/Clean/Rebuild project as necessary.

提交回复
热议问题