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 refactorin
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.
Right-click on the package at the Project Panel.
Choose Refactor -> Rename from the context menu.
Your package name will be changed from all the Java files and the manifest file. You have to manually change the package name from build.gradle
.
IntelliJ IDEA 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 IDEA?
Change the Package Name
To rename your package name, all you have to do is go to your AndroidManifest.xml
file, put your mouse cursor in front of the part of the package name you want to change.
Right-Click > Refactor > Rename
In the new window press Rename package
Change name and press Refactor
…and press Do Refactor at the bottom.
Your package name usually is in format com.domain.appname, in this example we changed the appname part, but you can do the same steps for the domain too.
Done! You changed your package name!
Changing the application ID (which is now independent of the package name) can be done very easily in one step. You don't have to touch AndroidManifest. Instead do the following:
Note this will not change the package name. The decoupling of Package Name and Application ID is explained here: http://tools.android.com/tech-docs/new-build-system/applicationid-vs-packagename