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?
This question is related to
android
intellij-idea
I found another solution for renaming a package in the entire project:
This renames the package/directory throughout the entire project.
Super simple approach:
R.java
in the build/generated directoryR.java
to the newly created package. Done!
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.
Deselect Hide Empty Middle Packages in Project Explorer Windows settings menu than you will be able to refactor each directory
Solution 1: I changed src subfolder names, manifest file, activity headers and run/debug configuration. And still got building errors. If your project is not so big, just create a new project, copy-paste old files and change package names in headers of .java files and android manifest.
Solution 2: Inside IntelliJ 12, goto someFile.java and find your old package name
package com.myself.project2
click to which word that you want to change. Press Shift+F6.
Dialog comes, type new name.
Then goto Run/Edit configurations. Inside Launch radio button change package name to new one. It should work.
Other renaming options of IntelliJ are: http://www.jetbrains.com/idea/webhelp/rename-refactorings.html
In Android Studio 1.1, the simplest way is to open your project manifest file
, then point to each part of the package name
that you want to change it and press
SHIFT + F6 , then choose rename package
and write the new name in the dialog box. That's all.
What I did was the following
Done!
I solved this issue by changing the directory name manually from the command line. Intellij then recognized the new package name automatically. I then had to do a search and replace for the package name in each file that imported it. This seems like an ugly workaround, but Intellij seemed unwilling to change the package name otherwise.
Lets address the two use cases
**Rename a package name or Trim a package **
com.mycompany.mystupidapplicationname to com.mycompany.brandname
or
com.someothercompany.mystupidapplicationname to com.someothercompany.mystupidapplicationname
or
com.someothercompany.mystupidapplicationname to someothercompany.brandname
But this will only rename the last part of package name
Delete the dummy file
To Trim a package , simply right click and move the package part inside its grand parent
shift+F6
you will get a popup window as shown below select
Rename package.That's it done.
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
to com.example2.test
:
temp
inside the directory example
(alongside directory test
).com.example
and Click Shift + F6
. Now it offers to rename the text example
. 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!!
Eclipse: Right click on the project > Android tools > Rename application package.
As simple as that...
In Android Studio: open the build.gradle file > rename the applicationId under defaultConfig > synchronize
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
The best way to solve this is going to the AndroidManifest.xml: package="com.foocomp.fooapp
:
Works for me.
Also, replace in Path in Whole Project as it didn't change everything. Then Clean, Rebuild and it works --> In Android Studio / IntelliJ you should unmark "Compact Empty Middle Packages"
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.
This modification needs three steps :
Then clean / rebuild the project
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
:)
In addition to @Cristian's answer above, I had to do two more steps to get it working correctly. I will sum all of it here:
R.java
class and the press F6
(Refactor->Move...). It will allow you to move the class to another package, and all references to that class will be updated.build.gradle
file : android / defaultconfig / application ID [source].Unfortunately all above didn't work for me. After having lots of trials, What worked for me in Android Studio:
do a 'move' on the package to a new package name you want.(right click on package and select Refactor -> Move) If Refactor -> Move didn't work for you, then create a package with the name you want and move manually in the existing package to the new one, and then delete the old empty package.
Change package name in manifest (manually)
Source: Stackoverflow.com