How can I change top level package name in IntelliJ IDEA?

前端 未结 2 435
感情败类
感情败类 2020-12-23 16:01

I have a package structure: com.report.domain.model

I would like to change it to com.reporting.domain.model. When I select RefactorRename on pac

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-23 16:41

    To change the full package name:

    User jkovacs has already answered this, but I'm going to cover this in a bit more detail. For example, if you want to change com.example.app to my.awesome.game, then:

    1. In your Project pane, click on the little gear icon (Gears icon)

    2. Uncheck / de-select the Compact Empty Middle Packages option:

      Compact Empty Middle Packages

    3. Your package directory will now be broken up in individual directories.

    4. 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:

        Enter image description here

    5. Now open your Gradle Build File (build.gradle - Usually app or mobile). Update the applicationId to your new Package Name and Sync Gradle, if it hasn't already been updated automatically:

      Refactor Directories

    6. Done! Anyway, Android Studio needs to make this process a little simpler.

提交回复
热议问题