How to Rename Package in Android Studio

Many new developers will find it hard to rename a package. By default, package names are compacted in Android Studio, and that’s the reason why many can’t find a way to rename them.

  1. Open the project in Android Studio and navigate to the package you wish to rename. Right-click on the package and select “Refactor” from the context menu. From the “Refactor” menu, select “Rename”. You will be prompted to enter a new name for the package. Enter the new name and click “Refactor”.
  2. Update the manifest file. Open the manifest file and change the package name to the new name. This will ensure that the application is now using the new package name.
  3. You will need to update any references to the old package name in your code. Use the “Find in Path” feature to search for any references to the old package name and update them to the new package name. Once all references have been updated, you can save and close the project. Your package has now been renamed and is ready to be used in your project.

Step to refactor package renaming

1) Disable name compact mode

On the Project tab, click on the Gear icon to open a new menu then uncheck the “Compact Empty Middle Packages” menu item.

Now all packages will be listed in the hierarchy.

2) Refactor name

Right-click on the package you want to rename, select Refactor then Rename (You can use Shift + F6 shortcut to quickly access name refactor).

When a new popup menu appears, choose Rename Package then click on Refactor button.

3) Change package name in build.gradle

If Android Studio notifies an error in buld.gradle, open it, and change the package name to a new one.

Leave a Comment

Your email address will not be published. Required fields are marked *


Scroll to Top

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close