Breadcrumbs

Below are the steps for changing the PackageName in Android studio.

  • Lets say, I want to change package name com.mycompanyname1.data to com.mycompanyname.data.
  • Click setting icon from Project explorer and check the Flatten package option.

Change the Package Name in Android Studio - 01

  • Now again click on setting option and uncheck Hide Empty Middle Packages.

Change the Package Name in Android Studio - 02

  • So now package name gets divided in different sub-package like com, com.mycompanyname1, com.mycompanyname1.data under java directory.
  • Right click on com.mycompanyname1 package name and click option Refactor->Rename option (Alt+Shift+R) then rename packagename dialog box opens up, just change the package name as you want. For current example, we changed mycompanyname1 to mycompanyname.
  • Click on Refactor button in dialog box.
  • Click on Do Refactor at bottom.
  • Android studio automatically changes package name in whole application except build.gradle.
  • Open build.gradle file under application, rename package name manually.
  • Now, again click on setting option and uncheck Flatten packages option.
  • Sync the application again and the code will be refactored according to new package.