HomeAndroid App DevelopmentHow to Rename package in Android Studio

How to Rename package in Android Studio

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.

<img width=

 Answers 1 :

In Android Studio for Rename package in Android Studio latest version , you can do this: For example, if you want to change com.example.app to my.package.game, then:

  1. In your Project pane, click on the little gear icon ( Gears icon )
  2. Uncheck the Compact Empty Middle Packages optionCompact Empty Middle Packages
  3. Your package directory will now be broken up into 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
  • Click Do Refactor in the bottom
  • 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 AllEnter image description here

Answer 2:

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.

Done.

Very important:

You have to manually change AndroidManifest.xml and build.gradle file to the new package if you use this method.

Answer 3:

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:

  1. right click on the root folder of your project.
  2. Click “Open Module Setting”.
  3. Go to the Flavours tab.
  4. Change the applicationID to whatever package name you want. Press OK.

Cheers!

ShareTweetShare

READ MORE

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -

Most Popular

- Advertisment -