Fully change package name including company domain
Solution 1
You can do this:
Change the package name manually in the manifest file. Click on your R.java class and the press F6 (Refactor->Move...). It will allow you to move the class to other package, and all references to that class will be updated.
reference: How do I rename the android package name?
Solution 2
current package : com.company.name
New package : com.mycomapny.name
Steps: 1) Suppose you are at this screen which is shown below.
2) Open project pane and click on settings icon.
3) Deselect Compact Empty Middle Packages.
4) Then your package is now broken into individual parts as shown below .
5) right click on "company" select Refactor -> select rename ->rename directory.
6) Now your "company" has been changed to new "mycomapny" and changes were reflected as shown in below figure.
7) Now change the package name in AndroidManifest.xml file .
8) Open app level build.gradle and change package name .
9) you will get errors as Cannot resolve symbol "R" .
10) Remove line which gives this error and studio will import new R file automatically.
11) If you have multiple files then use find and replace option by pressing " Cntrl+Shift+R "
Or " Select Edit->Find->Replace in path.."
12) select Replace All.
Solution 3
This worked for me, from https://stackoverflow.com/a/18637004/127434
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. AndroidStudio will refactor the package name everywhere.
Finally, delete the old package.
Solution 4
In Android Studio, you can do like this:
For example, if you want to change com.example.app to iu.awesome.game, then:
- In your Project pane, click on the little gear icon (
)
- Uncheck / De-select the Compact Empty Middle Packages option
- Your package directory will now be broken up in individual directories
-
Individually select each directory you want to rename, and:
- Right-click it
Select Refactor
Click on Rename
In the Pop-up dialog, click on Rename Package instead of Rename Directory
Enter the new name and hit Refactor
Click Do Refactor in the bottom
Allow a minute to let Android Studio update all changes
-
Note: When renaming com in Android Studio, it might give a warning. In such case, select Rename All
Now open your Gradle Build File (build.gradle - Usually app or mobile). Update the applicationId in the defaultConfig to your new Package Name and Sync Gradle, if it hasn't already been updated automatically:
You may need to change the package= attribute in your manifest.
Clean and Rebuild.
Done! Anyway, Android Studio needs to make this process a little simpler.
Solution 5
@Luch Filip's solution works well if you just want to rename the App package. In my case, I also want to rename the source package too, so as not to confuse things.
Only 2 steps are needed:
Click on your source folder e.g.
com.company.example
> Shift + F6 (Refactor->Rename...) > Rename Package > enter your desired name.Go to your AndroidManifest.xml, click on your package name > Shift + F6 (Refactor->Rename...) > enter same name as above.
Step 1 will automatically rename your R.java folder, and you can build straight away.
Filip Luchianenco
Passionate and energetic engineer. I love my family, I love what I do, and I love efficient teamwork. I tend to think that persistent people together lead to successful collaborations, increasing the chances of achieving the common goals.
Updated on September 19, 2021Comments
-
Filip Luchianenco almost 3 years
Let's suppose this is the package name:
package com.company.name
. How do I changecompany
?P.S. I saw how to change
name
but notcompany
. I'm using Android Studio. -
kaay almost 9 yearsAll good, except I get "IOException: cannot rename (...)" for the main source folder. Simple project, just opened.
-
LarsH about 8 yearsThis worked partially for me, but it didn't fix the "import com.company.foo" statements. I was able to do the latter with a global replace in the src/ directory.
-
James Grey about 8 yearsI use Android studio 2.1.1 . My specific For example, at first, I have
info.apachehive.cardview
, I want havenet.vyhn.cardview
. Step 1. Choose tree view source code. Step 2. Clickapachehive
, press Shift+F6 Refactor\Rename tovyhn
. Step 3. Clickinfo
folder, press Shift+F6 Refactor\Rename tonet
. FileAndroidManifest.xml
automatically change. Then I run debug, my application works well. -
Asim K T almost 8 yearsMay be you can add some screenshots.
-
Amir Dora. almost 6 yearsthat's not the most reliable way, simply refactoring does the job, imagine someone has more complex project, that has styles, dimens, drawables, libraries. This method takes a lot of time.
-
Martin Jovial almost 6 yearsIt's reliable if you follow my method step by step and it is very speedy if you follow them. Just forget about any complexity and consider you're creating a new project from existing source, then as I can see you don't know where drawable dimens libraries stays, I'll explain to you then you have to upvote my answer. 1- libraries are iside your build.graddle so if you backed up the file you would just have to copy the content inside the new build.graddle 2- drawables, dimens, styles are all inside the res folder. so if you have both projects new/old(package) opened u just have to drag/drop
-
Martin Jovial almost 6 yearsSometime refractoring is more complicated than you can imagine because I tried it without success then using my method every things worked like a charm
-
Amir Dora. almost 6 yearsYes Martin, agree this is also one way and it works. But it is not the fastest method. Thanks for detailed answer.
-
Hasan El-Hefnawy over 4 yearsFor me, this is the best answer. Thanks.
-
Adam Burley over 3 yearsgood answer, but why would you only rename the directory? this is why you get all these issues with unresolved symbol R, etc. I followed your instructions but renamed the package rather than the directory. then I didn't have to change the manifest, R references etc.
-
Chucky over 2 yearsProbably worth saying that I tried a few of these ways and none of them were totally straight forward. I had to manually add a few folders to get the directories right after the rename. It's working now though, so read a few of the approaches and anticipate some hiccups.