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.
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 :
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:
That's it...
I tried the two top-voted solutions but found some issues even though both work to some extent.
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.
I recommend to use the Sublime Text(or Notepad++). Replace com.one.lastname -> 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:)
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.
After you've done that push Replace All to replace your old package name with your new one.
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:
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.
Select the package that will be refactored. Refactor → Move → "Move xxx to new package".