Rename package in Android Studio
Questions : 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 refactoring, but I don’t know how. I worked two years with Eclipse and in Eclipse it’s a one-click operation.
Answers 1 :
In Android Studio for Rename package in Android Studio latest version , you can do this: For example, if you want to change
- In your Project pane, click on the little gear icon ( )
- Uncheck the
Compact Empty Middle Packagesoption
- Your package directory will now be broken up into individual directories
- Individually select each directory you want to rename, and:
- Right-click it
- Click on
- In the pop-up dialog, click on
Rename Packageinstead of Rename Directory
- Enter the new name and hit Refactor
- Click Do Refactor in the bottom
- Allow a minute to let Android Studio update all changes
- Note: When renaming
comin Android Studio, it might give a warning. In such case, select Rename All
Another good method is: First create a new package with the desired name by right clicking on the Java folder → New → Package.
Then, select and drag all your classes to the new package. Android Studio will refactor the package name everywhere.
Finally, delete the old package.
You have to manually change AndroidManifest.xml and build.gradle file to the new package if you use this method.
Changing the application ID (which is now independent of the package name) can be done very easily in one step. You don’t have to touch AndroidManifest. Instead do the following:
- right click on the root folder of your project.
- Click “Open Module Setting”.
- Go to the Flavours tab.
- Change the applicationID to whatever package name you want. Press OK.