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.
Right click on package -> refactor and change the name. You can also change it in manifest. Sometimes if u change package name but after creating apk it shows different package name at that time check "applicationId" in build.gradle file.
Best way to write the new package name and drag from older package name. Second way if you click Refactor then move option then rename the package name , It will rename the package name then rebuild.
In Build.gradle You have to do manually , If u Refactor then it will not rename in Build.gradle.
Additional answer after 3 years, of course if any previous not works for you because "something".
Done!
I have seen the top voted answers but i found is a little bit different to do this, i try to do the most complete tutorial.
From the Android Studio click over the gear icon ( ) and then select the option:
"Compact Empty Middle Packages"
, to see the folders separated in a tree view.Now select the folder, click right button to open the contextual menu, select
Refactor
and thenRename
You will be advised to refactor the package:
Then a window will show the coincidences inside the proyect, select
"Do Refactor"
:We don´t have to change manually the AndroidManifest.xml or build.gradle files, Refactoring the package will do the job!.
Your package name will be changed from all the java files and Manifest file. You have to manually change the package name from build.gradle
After you follow one of these techniques to get your package renamed, you might start seeing errors.
If / when your R.java is not getting generated properly, you'll get a lot of errors in your project saying
error: cannot find symbol class R
and alsoerror: package R does not exist
.Remember to check your Application manifest xml. The manifest package name must match the actual package name. It seems the R.java is generated from the Application Manifest and can cause these errors if there's a mismatch.
Remember to check the
package
attribute matches in your<manifest package="com.yourcompany.coolapp">