Pressing Shift+F6 seems only to rename the last directory.
For example, in the project com.example.test
it will offer to rename test only. The same applies if I navigate to package name in .java
or Manifest file and press Shift+F6.
So is there a way to rename the package?
Most of the answers even the most voted answers didn't do the job properly, they seem to work and the builds work however, a closer look at the file structure and references will show you that not much was done. IntelliJ actually does this whole process automatically.
If you want to rename full android package, this is the best way to do that:
Mark as checked - Comapct Emty Middle Packages
Right click on the packcage you want to change, and then Refactor->Rename->Rename all
You can find video tutorial on this link: https://www.youtube.com/watch?v=A-rITYZQj0A
Most of the answers even the most voted answers didn't do the job properly, they seem to work and the builds work however, a closer look at the file structure and references will show you that not much was done. IntelliJ actually does this whole process automatically.
1) Go to Project Tab and make sure Packages is the active Tab in the drop down like so:
find your com.example package (note test as in com.example.test is not there) right-click and choose Refactor->Rename...
It will issue a warning that multiple directories... (which is actually the desired effect), click on Rename package.
Input the new package name and Refactor...
It will do searches and show you refactoring results.
Click on the Do Refactor button and it will do everything and even rename the folders and files involved... every reference is corrected to this new name.
2) Then Finally change the AndroidManifest.xml file
:)
Deselect Hide Empty Middle Packages in Project Explorer Windows settings menu than you will be able to refactor each directory
I found a good work around for this problem. Taking the example mentioned in the question, following are the steps for changing the package name from
com.example.test
tocom.example2.test
:temp
inside the directoryexample
(alongside directorytest
).com.example
and ClickShift + F6
. Now it offers to rename the textexample
. Here you can enter the new text you want and IntelliJ will do the rest for you.temp
from the file system.This idea can be used to refactor any part of the package name.
Good luck!!
What I did was the following :
I simply created the package with the desired name , in the src folder , next to the current package with current name.
I dragged all contents of current package to new package , intellij popped a dialog box asking me if I want to refactor inside package references and project references to new package , I clicked 'yes' and TA-DAAA , worked like a charm.