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
The approach used by me for renaming the package name is simple as follows:-
Step 1 : Select the Project option from left menu of Android Studio
Step 2 : Right click on java and add a new package and set the desired package name
Step 3 : Enter you new packagename
Step 4 :Copy all the files from your old package and paste in the new package
Step 5 :Rename the package name in manifest file
Step 6 :Rename the package name in build.gradle file
Step 7 :Then right click the old package and delete it with all its data, and delete that directory as well
Step 8 :Then Rebuild your project
Step 9 :Then you will find some errors of old import packagename in your project Select the old package name in any file and press CTRL + Shift + R , and enter you new package name in replace box, then press find
Step 10 :Then a popup appears like below and select All files option from it
Step 11 :Rebuild your project again, bingo your project packagename has been changed :)
How to rename com.example.app
to com.android.app
:
in package com.example.app
select example
Shift + F6
choose rename package
rename example to android
confirm do refactor
The best way is to write the new package name and drag from the older package name.
The second way, if you click Refactor then move option then rename the package name, it will rename the package name and then rebuild.
In Build.gradle you have to do manually, if you Refactor then it will not rename in Build.gradle.
Select option
Uncheck the Compact Empty Middle Packages option.
Renaming directory crl to crl1
Finally click on Do Refactor button marked in image below enter code here
After Changes done
Open the file:
app → manifests → AndroidManifest.xml
Highlight each part in the package name that you want to modify (don't highlight entire package name) then:
Do these steps in each part of the package name.
Open (Gradle Script) >> (build.gradle(Modul:app))
and update the applicationId to your package name
Open the menu (build) and choose (Rebuild Project).
Another good method is: First create a new package with the desired name by right clicking on the Java folder → New → Package.
Then, select and drag all your classes to the new package. Android Studio will refactor the package name everywhere.
Finally, delete the old package.
Done.
Very important:
You have to manually change AndroidManifest.xml and build.gradle file to the new package if you use this method.