Android Studio Rename Package

ramzixp 08/20/2017. 30 answers, 386.315 views
android android android-studio android-studio

How do you rename packages in new IDE Android Studio, based on intelijj ?

Is there any automatic refactoring included?

I want to make bulk refactoring but I don't know how. I worked 2 years with eclipse and in eclipse it's one click operation.

Leigh 12/01/2014
Please see my answer here. I have successfully managed to rename my project using the steps I have described.
Leigh 12/02/2014

30 Answers

Sheharyar 05/21/2017.

In Android Studio, you can do this:

For example, if you want to change to, then:

  1. In your Project pane, click on the little gear icon ( Gears icon )

  2. Uncheck / De-select the Compact Empty Middle Packages option

Compact Empty Middle Packages

  1. Your package directory will now be broken up in individual directories

  2. 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 All

enter image description here

  1. Now open your Gradle Build File (build.gradle - Usually app or mobile). Update the applicationId to your new Package Name and Sync Gradle, if it hasn't already been updated automatically:

Refactor Directories

  1. Done! Anyways, Android Studio needs to make this process a little simpler.
16 stevebot 03/20/2015
THANK YOU! So stupid that they have this set as the default. why collapse packages, so user unfriendly it makes me upset.
11 Sheharyar 04/11/2015
Clean and rebuild.
6 ricky.tribbia 04/17/2015
WARNING: if you select "Rename all" when renaming also "com" it will rename not only things into the selected module but into all modules into this project
10 Richard 07/28/2015
@Antonio drag the files in com.example.test to com.example and then delete com.example.test.
19 nevzo 07/31/2015
This procedure worked for me. I had to also change the AndroidManifest.xml to reflect the new name. For example -> package="" >

user10F64D4 01/18/2016.

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. AndroidStudio will refactor the package name everywhere.

Finally, delete the old package.


One more thing very important

You have to Change manually Android Manifest and gradle file to the new package if you use this method.

61 Richard 04/04/2014
You may need to update your Android Manifest file to reference the new package if you use this method. Very simple step though, great solution.
10 Christoph 04/17/2014
You might have to restart Android studio to update the .idea/workspace.xml
21 Samik Bandyopadhyay 08/02/2014
You also may need to change your build.gradle to reflect the new package
30 baboo 09/11/2014
good method but had to do 2 more things(other than updating manifest file) to make it completely work, firstly had to change/rename the R file imports in whole project and secondly appdebug was using old package name( visible in run window of studio) added applicationId "com.packagename" in app build.gradle defaultconfig ..
5 CCJ 11/12/2014
this is the exact opposite of a 'good' solution...

hwat 12/22/2015.

It 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.

The decoupling of Package Name and Application ID is explained here:

3 Jacob R 03/23/2015
This only changes the name in gradle, and nowhere else.
3 sud007 06/09/2015
This is one holy grail answer! Very Smart!
3 Sa Qada 06/29/2015
This needs to be chosen as a correct answer since it is very simple and fast way to follow.
5 RunLoop 07/10/2015
This did not work for me
3 Inder Kumar Rathore 10/25/2015
This needs to be accepted, other answer are lengthy and you can't change com.example.sample to com.example using other answers

GreyBeardedGeek 10/03/2015.

Right-click on the package at the Project Panel.

Choose Refactor -> Rename from the context menu.

1 physphil 04/05/2014
this worked great for me, also had to update the AndroidManifest file too.
104 GilliMonsta 05/16/2014
Refactor > Rename only allows me to rename the last part of the package, e.g. the app in
1 Dharmik 11/12/2014
I did this way but Now it says class not exist at launch time. How did you renamed it?
Erwinus 04/25/2015
I have used the "Refactor" main menu and click on "Rename".
Taranmeet 11/24/2015
@GilliMonsta you can select your app folder in right side panel click settings and un-check Compact Empty Middle Packages

Prince Jayakumar 01/28/2016.
  1. Goto your AndroidManifest.xml.
  2. place your cursor in the package name like shown below don't select it just place it.

enter image description here

  1. Then press shift+F6 you will get a popup window as shown below select Rename package.

enter image description here

  1. Enter your new name and select Refactor. (Note since my cursor is on "something" only something is renamed.)

That's it done.

1 Shan Xeeshi 03/07/2016
Thanks working on Android Studio 1.5.1 It changes package automatically No need to create new package and drag and drop files and delete old package Blah Blah Blah
Prabs 12/28/2016
@Prince Jayakumar, your 'don't select it just place it' statement is confusing. just by placing the mouse cursor, shft+f6 won't work. If the caret is somewhere else in the file then you've to click at the package name, then shft+f6 will work
Mark A. 05/31/2017
Thanks. Worked for me.

alhamdi 07/23/2015.


Open the file:

app >> manifests >> AndroidManifest.xml

enter image description here

Highlight each part in the package name that you want to modify (don't highlight entire package name) then:

  • Mouse right click >> Refactor >> Rename >> Rename package
  • type the new name and press (Refactor)

Do these steps in each part of the package name

enter image description here


Open (Gradle Script) >> (build.gradle(Modul:app))

and update the applicationId to your package name

enter image description here


open the menu (build) and choose (Rebuild Project)

Rob Rose 07/24/2015
I tried doing this and I hit a snag. I'm trying to change the to my own domain (which ends .net). I can change 'example' and 'package', but I can't change the 'com'. It also doesn't rename any directories. Any tips?
The Original Android 08/14/2015
@RobertRose, I have a solution for your issue. Are you still working on it?
Rob Rose 08/15/2015
I put it aside and just went ahead and left it. It's not production. For future reference, what did you come up with?
Jemshit Iskenderov 08/22/2015
1st one does not work if i have "" kind of package)
AlleyOOP 12/26/2015
beautiful. the second steps are essential and usually looked over in most answers.

Mehroz Munir 06/21/2017.

The approach used by me for renaming the package name is simple as follows:-

Step 1: Select the Project option from left menu of Android Studio

enter image description here

Step 2: Right click on java and add a new package and set the desired package name

enter image description here

Step 3: Enter you new packagename

enter image description here

Step 4:Copy all the files from your old package and paste in the new package

enter image description here

Step 5:Rename the package name in manifest file

enter image description here

Step 6:Rename the package name in build.gradle file

enter image description here

Step 7:Then right click the old package and delete it with all its data, and delete that directory as well

enter image description here

Step 8:Then Rebuild your project

enter image description here

Step 9:Then you will find some errors of old import packagename in your project Select the old package name in any file and press CTRL + Shift + R , and enter you new package name in replace box, then press find

enter image description here

Step 10:Then a popup appears like below and select All files option from it

enter image description here

Step 11:Rebuild your project again, bingo your project packagename has been changed :)

Osama Ibrahim 06/01/2017
Thanxxx man this the best PRACTICE WHICH WORKED FOR ME
ralphspoon 06/21/2017
Replace In Path is no longer available tru Shift + R in Android studio 2.3.3, highlight the old path, go to Edit -> Find -> Replace In Path. Also make sure to update your gradle files. Cheers
Jevgenij Kononov 08/09/2017
Thanks..good solution
user3760100 08/15/2017
Did not get any errors with old package name. So, didn't have to do anything after step 9. Thanks!
Mehroz Munir 08/17/2017
If you did not get any errors, then do not go after step 9

Matus F. 05/23/2017.

Intelli J has an option called "Compact Empty Middle Packages". Select the option-icon of the Project-tab and de/activate this.

See: How can i change top level package name in IntelliJ

1 Chris Nevill 08/12/2014
This was useful. After 'Deactivating' this feature things were much clearer and I could delete packages that were empty
beretis 02/11/2015
@ChrisNevill and how did u delete those empty packages please?
Chris Nevill 02/11/2015
I think I just selected them and pressed delete. I can't reproduce the issue at the moment so can't remember it exactly.
iaindownie 12/17/2015
I agree, this was REALLY useful. Should be included in all the sub-standard answers I've seen regarding this topic.

hoot 10/06/2014.

select the package will be refactored, refactor->move ->"move xxx to new package"

droid kid 02/03/2015
this is d easy method
3 Jose Manuel Abarca Rodríguez 06/23/2015
Doesn't work, changed my package from "" to "". See? This method doesn't allow to change the last component of the name (and I tried several times).

dongxu 06/07/2013.

If your package name is more than two dot separated, say and moreover, you did not put anything in com/ and com/hello/. All of your classes are putting into com/hello/world/, you might DO the following steps to refactoring your package name(s) in Android Studio or IntelliJ:

  • [FIRST] Add something under your directories(com/, com/hello/). You can achieve this by first add two files to package, say

then refactor them by moving them to com and com.hello respectively. You will see com and com.hello sitting there at the Project(Alt+1 or Command+1 for shortcut) and rename directories refactoring is waiting there as you expected.

  • Refactor to rename one or more of these directories to reach your aim. The only thing you should notice here is you must choose the directories rather than Packages when a dialog ask you.

  • If you've got lots of classes in your project, it will take you a while to wait for its auto-scan-and-rename.

  • Besides, you need to rename the package name inside the AndroidManifest.xml manually, I guess, such that other names in this file can benefit the prefix.

  • [ALSO], it might need you to replace all to the new XXX.XXX.XXX.R(Command+Shift+R for short)

  • Rebuild and run your project to see whether it work. And use "Find in Path" to find other non-touch names you'd like to rename.

  • Enjoy it.

Jorgesys 09/15/2016.

I have seen the top voted answers but i found is a little bit different to do this, i try to do the most complete tutorial.

From the Android Studio click over the gear icon ( Gears icon ) and then select the option: "Compact Empty Middle Packages", to see the folders separated in a tree view.

introducir la descripción de la imagen aquí

Now select the folder, click right button to open the contextual menu, select Refactor and then Rename

introducir la descripción de la imagen aquí

You will be advised to refactor the package:

introducir la descripción de la imagen aquí

Then a window will show the coincidences inside the proyect, select "Do Refactor":

introducir la descripción de la imagen aquí

We don´t have to change manually the AndroidManifest.xml or build.gradle files, Refactoring the package will do the job!.

Sebastian Breit 05/15/2015.

Updated answer: May 2015

OK I have been struggling with cloning & renaming projects in Android Studio, but finally I achieved it. Here are the steps to follow:

  1. Copy the project folder, rename it & open it with Android Studio
  2. Rename module directory from explorer
  3. Rename projectName.iml and content
  4. Rename idea/.name content
  5. In your Project pane, click on the little gear icon -> uncheck "Compact Empty Middle Package"
  6. Refactor src directories for new package name (rename package, "not rename directory")
  7. In build.gradle rename application id
  8. settings.gradle rename module

That's it...

I tried the two top-voted solutions but found some issues even though both work to some extent.

  • List item: The new package-drag-drop method leaves some unchanged and creates some undesired effects
  • List item: The rename package only changes the last part of package name

After some experiments I found the following method works well for me.

If you just need to change the last part of package name, use the method outlined by GreyBeardedGeek, namely

Right-click on the package in the Project pane. Choose Refactor -> Rename from the context menu

If you need to change the whole package name, do the following.

Right-click on the package in the Project pane. Choose Refactor -> Move from the context menu

This will create a new package folder (when necessary) but will keep the last part of your package name as before. If you need to change the last part, do the rename accordingly.

Note also that you may need to modify package names in e.g. build.gradle, manifest, and/or any xml resource files, or even in your code if hardcoded. After all that, do Sync/Clean/Rebuild project as necessary.

Shivanand T 04/30/2015.

The common mistake that one can make is one cannot rename the package structure i.e it is not possible to change to when one tries to modify at level.

In order to have the same desired change go one level up i.e and here when you refactor change it to Renamed. This will work always

rajlaxmi_jagdale 05/11/2015.

Right click on package -> refactor and change the name. You can also change it in manifest. Sometimes if u change package name but after creating apk it shows different package name at that time check "applicationId" in build.gradle file.

irobotxxx 10/16/2015.

I found another way that works or an extra step to some of the answers here especially if you want to change the domain as well. Works in android studio 1.4. This is what i did:

  1. Open Manifest.xml and change the package name to what you want.
  2. open your app build.gradle file and change the Application Id in defaultConfig to the same name as in manifest and rebuild the project.
  3. if still issue, open a file under the package name, go to the package breadcrumbs(i.e package declaration at head of file) and set your cursor to the domain you want to change and hit "Shift + F6", it would come out with a dialog with multiple use warnings, click on "Rename packages" and then click on "Do Refactor" it should rename everything including the R.Java files.

so for example if you want to rename "" to "", open a file under the package to be renamed, in the package breadcrumbs, set your cursor to "example" part of the domain and hit Shift +F6 and rename package to "YourDomain".

Hope this helps :)

user3295929 08/24/2014.

The first part consists of creating a new package under "java" folder and selecting then dragging all your source files from the old package to this new package. After that you need to remane the package name in android manifest to the name of the new package.

In step 2, here is what you need to do.You need to change the old package name in "applicationId" under the module "build.gradle" in your android studio in addition to changing the package name in the manifest. So in summary, click on "build.gradle" which is below the "AndroidManifest.xml" and modify the value of "applicationId" to your new package name.

Then, at the very top, under "build". clean your project, then rebuild. It should be fine from here.

zafirk 09/18/2014.

Packages serve two purposes. One is to uniquely identify your app in the Google Play Store. The other is to name the package for the class which is generated when you build your project. You can think of the first purpose as the external package and the second as the internal package. Assuming you want to change the external package so you can identify in the Play store, there's a convenient way to do this.

In Android Studio, choose File > Project Structure > Choose your app's module > Click on the Flavors tab > change the Application id. Now, when you build your project, your APK and manifest will use this new package name.

phxhawke 03/24/2015.

This I believe what you are looking for is Refactor > Move. You can also press F6.

You will get two popups. Make sure you select rename package on both. After that you will get a pop up to place the new package name.

Please note that if your package name is, for example, then this will let you change to something else.

One more thing, this will update the applicationId in your build.gradle as well. Just make sure that the checkboxes for "search in comments and strings" and "search for text occurrences" are both checked for it to work.

Ajay Keshri 03/26/2015.

Best way to write the new package name and drag from older package name. Second way if you click Refactor then move option then rename the package name , It will rename the package name then rebuild.

In Build.gradle You have to do manually , If u Refactor then it will not rename in Build.gradle.

DSlomer64 07/03/2015.

Be sure to go way back up to Sheharyar's Answer that starts off In Android Studio, you can do this: because it's GREAT. There are so many Answers and comments that follow it that it would be easy to get confused and give up, but DON'T. That Answer WORKS.

In short, you do THREE THINGS:

Deselect Compact Empty Middle Packages.

Refactor Rename each old directory node by choosing CHANGE PACKAGE (not directory) to match new package name. (Be sure to do a preview of changes.)

Edit build.gradle file and make APPLICATION_ID match new package name.

2 DSlomer64 10/20/2015
Whoever downvoted this truly is missing something, since my Answer is a synopsis of Sheharyar's answer THAT GOT 332 UPVOTES and all I did was simpllify it since it looks so involved (it isn't). The nerve of some shortsighted, trigger-happy people. Would LOVE to see reason for downvote. Have no doubt I won't see it.

Darush 11/16/2016.

Quick and easy way:

1- open or any available java file.

At the top there is the package declaration such as:

package com.example.myapp;

select the package portion that you want to change and press Shift+F6. I personally want to change the example.

In the warning dialog, select Rename package and then insert the desired package name.

2- Open AndroidManifest.xml and inside <manifest> tag change the package to the desired package name.

3- open build.gradle(Module: app) and change the applicationId to the desired package name.

Ishwor Khanal 08/19/2017
Thank you. It is quite simple and straightforward.

himanshu.tiwari 03/17/2017.
  1. Select the package name in Java folder.
  2. Shift+F6
  3. Change package name and Click OK.

Your package name will be changed from all the java files and Manifest file. You have to manually change the package name from build.gradle

Uncaught Exception 03/10/2016
If Shift+F6 is not working for you, then you can try Alt+Shift+R to refactor the package. Rest of the procedure is the same

Kevin van Mierlo 03/20/2017.

I've found a way easier solution to this problem which also changed the generated imports like com.test.testpackagechange.R and only takes about a minute.

Your first step is to open Android Studio and open the replace all window (Mac: cmd + shift + R, Windows I assume: ctrl + shift + R). Type in your old package name and in the one below your new package name. Click Find. This may take a while because it is also looking through the generated items. If it has over 1000 hits, just click continue.

enter image description here

After you've done that push Replace All to replace your old package name with your new one.

enter image description here

Now close Android Studio and go to Finder on Mac or Windows Explorer on Windows. Change the name of the folders to your new package name, like this:

enter image description here

Now open Android Studio again. Gradle will sync and your package name should be changed to the new one.

I've found this to be the easiest one and the one that covers all areas like generated files.

I recommend to use the Sublime Text(or Notepad++). Replace -> com.two.newname and com/one/lastname -> com/two/newname in ...\Projects[MyProject]. and don't forget to rename ...\Projects\MyProject\app\src\main\java\com\one\lastname, ...\Projects\MyProject\app\src\test\java\com\one\lastname and ...\Projects\MyProject\app\src\androidTest\java\com\one\lastname! That's all:)screenshot

Dess64 05/23/2017.

That works very well for me, even for changing the occurrences, in all the modules concerned, for the folders names I want to modify in the package but, for me, it works fine only if I follow exactly the following steps :

  • A - If you want to change the name of the root folder (in other words the folder's name who is normaly used in the package to contain the principal activity), you can do it before or after the following steps (B to C) by exiting from "Android Studio" and rename manually this root folder. Click after on "Import project..." and then on the new name of your project (this import process will automatically readjust the 'Gradle' files with the project files.)
  • B - before the following C step, don't forget to modify manually the folder's names you want to change in the package by changing them in the 3 following files: 'AndroidManifest.xml', '' (or the name you eventually choose for your first activity) and the 'build.gradle (Module: app)' file.
  • C - Follow the steps 1 to 6 described above ("In your Project pane, click on the little gear icon...") ->
  • D - Only if you want to change the name of the root folder now, you can follow the 'A' process, as described above.

Dhiraj Gupta 08/23/2016.

After you follow one of these techniques to get your package renamed, you might start seeing errors.

If / when your is not getting generated properly, you'll get a lot of errors in your project saying error: cannot find symbol class R and also error: package R does not exist.

Remember to check your Application manifest xml. The manifest package name must match the actual package name. It seems the is generated from the Application Manifest and can cause these errors if there's a mismatch.

Remember to check the package attribute matches in your <manifest package="com.yourcompany.coolapp">

ShivBuyya 03/17/2017.
  1. Select option enter image description here

  2. Uncheck the Compact Empty Middle Packages option.

  3. Select which directory you want to change(I have selected 'crl' shown in step 6).
  4. Shift+F6
  5. Rename Package
  6. Renaming directory crl to crl1enter image description here

  7. Finally click on Do Refactor button marked in image belowenter image description hereenter code here

  8. After Changes doneenter image description here

ramzixp 06/20/2016.

Additional answer after 3 years, of course if any previous not works for you because "something".

  • Go to project path>where you located java files and package
  • Create new folders, for example com>super_package>activities
  • Android Studio will refresh project structure
  • Move all Java files to new folders
  • Remove old folders
  • Edit>Find>Replace in path:
  • change old package name to new
  • change also in manifest and build gradle


Raghavendra B 07/15/2016.

If your package starts with mypackageold.something.test then you can't change to mypackagenew.somethingnew.testnew.

In this case, if I follow above accepted answer steps result will be mypackageold.somethingnew.testnew.

Only if your package starts with com.... to New package, above accepted answer will work.

So if you want to change the package from Root Level

  1. Change the Required package name inside manifest,
  2. Remove the old package and Crate New Package under Android tab,
  3. Drag all the Files from old Package to New Package,
  4. Inside the Manifest also change the package name for those files,
  5. Clean Project,
  6. Open build.gradle and update applicationId.

Related questions

Hot questions


Popular Tags