Let's suppose this is the package name:
package com.company.name
. How do I change company
?
P.S. I saw how to change name
but not company
.
I'm using Android Studio.
This question is related to
android
android-studio
android-package-managers
In Android Studio, you can do like this:
For example, if you want to change com.example.app to iu.awesome.game, then:
Individually select each directory you want to rename, and:
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.
I have not changed any package name. The following two steps worked for me. After doing the following, the application was installed as a NEW one , eventhough there was two applications with the same package name.
1) In the build.gradle
applicationId "mynew.mynewpackage.com"
2) In the AndroidManifest.xml android:authorities="mynew.mynewpackage.com.fileprovider"
I found another solution for renaming a package in the entire project:
Open a file in the package. IntelliJ displays the breadcrumbs of the file, above the opened file. On the package you want renamed: Right click > Refactor > Rename. This renames the package/directory throughout the entire project.
To rename the package name in Android studio, Click on the setting icon in the project section and untick the Compact empty Middle Packages, after that the package will split into multiple folder names, then right click on the folder you need to change the name, click on refactor-> Rename-> Type the name you want to change in -> Refactor -> Refactor Directory, then import R.java file in the whole project. Working for me.
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.
1) Open the project folder in Android Studio.
2) Select app folder -> Right click, and select refactor.
3) Click on move. It will ask to which package name type you own full package name and it will ask to create a new package yes create new automatically it ask for gradle
to sync
.
I have read almost all the answers. But I think one is missing. Sometimes I may be wrong. I have used the below method and it's working.
3 Methods to change package name in Android Studio
@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.
If your company domain / package name is very long, it is more tricky.
This was the missing link for me. You need to select Project files -> settings -> then uncheck 'compact empty middle classes.
Four steps are given below:
com.new25.impro. press Shift + F6 {Refactor->Rename...} to rename the package and press refactor
.
After that one, see the android monitor. That show change everywhere that packagename. Click refactor
.
Go to module app:change
the application id for you like that name put it. and click sync now
.
Now you can change the package name to what you like.
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.
Hi I found the easiest way to do this.
Done!
The simplest way of doing this would be to rename the root app folder from com.example.MyApp
to com.newcompanyname.MyNewAppName
and then replace all occurrences of the old path to the new path in whatever IDE you're using.
I also faced same problem & here is how I solved :-
I want to change package name np.com.shivakrstha.userlog to np.edu.khec.userlog
I selected shivakrstha and I pressed Shift + F6 for Rename Refract and renamed to khec.
Finally, use the same package name in AndroidManifest.xml, applicationId in build.gradle and don't forget to Rebuild Your Project.
Note:- I tried to change np to jp, so I selected np and I pressed Shift + F6 for Rename Refract and renamed to jp, it's ok to change others too.
Source: Stackoverflow.com