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
If your package name is more than two dot separated, say com.hello.world
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:
com/
, com/hello/
). You can
achieve this by first add two files to package com.hello.world, saycom.hello.world.PackageInfo1.java com.hello.world.PackageInfo2.java
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 com.hello.world.R
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.