Renaming Android Package

From time to time you may find you need to rename an android package while developing in Android Studio. There seem to be several explanations around the web. The following method seems to be the method that worked the first time everytime for me. Example, change package com.example.test to com.example.testing:

  1. Click Project in the left sections bar → the Project Pane will open.
  2. Select Java under src / main of the app with the package to be renamed.
  3. Click the Small Gear on Project Pane top action bar → an options menu will appear.
  4. Uncheck the Compact Empty Meddle Packages in the options menu → the directories under java will cascade down.
  5. Select the package name to change (ex: test) and right click → a dropdown menu will appear.
  6. In the dropdown menu, select Refactor / Rename → a window will appear
  7. In popup window, select Rename package → a window will appear
  8. Enter the new package name, click search in comments & strings and search for text occurances
  9. Press Refactor

Refactoring should replace all needed directory names, and references within your files, producing a new package.

Leave a Reply