Shahood ul Hassan
Shahood ul Hassan

Reputation: 789

What is the best way to change the package name of an Android project?

I want to change the package name of my Android project using Android Studio from let's say, com.company.myapp to com.name.company.myapp. While there are many questions and answers that deal with renaming a part of existing package name but I couldn't find any help on how to add a new part to it.

Please help me in this regard.

Thanks

Upvotes: 5

Views: 25819

Answers (5)

saidi mmaka
saidi mmaka

Reputation: 101

Rename package name

  1. From project pane (left), click "Show option menu" it has settings like icon. Then from menu select "Compact Middle Packages"
  2. Then you will observe your main package.name folder expands. Right-click your (Package.name/ middle/ last name of your package name) expanded > Refactor > Rename
  3. Click "Do Refactor" from expanded Find tab at the bottom left of it.
  4. Finally click build.gradle (app-level), then change applicationId to 'your.new.packageName'. Then SYNC NOW
  5. Done

Upvotes: 8

Teekam Suthar
Teekam Suthar

Reputation: 459

Changing the application ID

(which is now independent of the package name) can be done very easily in one step. You don't have to touch AndroidManifest. Instead do the following:

1. Right click on the root folder of your project.
2. Click "Open Module Setting".
3. Go to the Default tab.
4. Change the applicationID to whatever package name you want. Press OK.

P.S. if you're using google-services.json , make sure you update new ID there too.

Upvotes: 9

Aml Salman
Aml Salman

Reputation: 11

To Rename APP package:

  1. create a new package with the desired name by right clicking on the Java folder → New → Package;
  2. Cut then paste all your classes to the new package. Android Studio will refactor the package name everywhere;
  3. delete the old package;
  4. change AndroidManifest.xml and build.gradle file to the new package if you use this method.

Note: it’s more safe to make a new project.

Upvotes: -2

user258959
user258959

Reputation: 93

I tried more than 10 approaches and none of them worked (and sometimes not explained completely, so I deviated a little and found my own way. Again, my way is also not simple, but it does the job and Google Play didn't give me any errors.

My Solution

1. On the Project pane on the left, select Project (it might say Android).
2. Go to nameOfYourProject -> app ->src -> main ->java ->com -> example
3. Right click on "example" -> Refactor -> Rename and type your desired name, select the two check boxes and hit Refactor.
4. Now go one level above example (folder) and right click on "com", but this time DO NOT check the two check boxes (as it will also rename the "com.google...." parts of your project) and hit Refactor.
5. Now open your Manifist file and manually change the package to your desired name.
6. Rebuild your project. If you see any errors, just open the file with the error and change the package name manually.
7. Open your gradle.build file and change application ID, to your new package (only the parts of it, not everything) and hit Sync (top right side). Hopefully this works.

P.S. Another "easy way" might be to use Agent Ransack, search for the package name by enclosing it with quotations and manually change the package name. You might want to get a copy of your project before doing this. I didn't try it, cause I was already knee-deep with all the other methods here and didn't try.

Upvotes: 1

Vahalaru
Vahalaru

Reputation: 400

This answer from the link in the comment provided would be most likely to have any issues arise, and would be simple. Possibly tedious depending on your app. I attempted changing package name once and android studio does not accomplish this very well. Simple solution

Upvotes: 0

Related Questions