Sometimes, we make our app using the code from youtube tutorials and blogs and may forget to change the package name at the start. Yes, this happens, most of the time.
We don’t want to display other website name or Youtube channel name to be as our package name, We want a package name that defines us. If you are searching for a tutorial about how to change or rename the Android app package name in Android Studio, then this post is for you.
In this post, I am going to discuss 3 methods that I am using and still working.
- Method I – How to rename Android app package name in Android Studio
- Method II – How to change full package name of project by creating new package
- Method III – How to rename android app package name in Android Studio using existing package
Method I – How to rename android app package name in Android Studio
In this example, we will change package name com.androidride.myapplication” to “com.xyz.yourapplication”.
- Open Android Studio project, Select package name or Java, Click the gear icon.
- Deselect Hide Empty Middle Packages. This breaks your folder structure into parts.
- The package is brocken down.
- Right Click on AndroidRide, Refactor -> Rename . You can also use Shift + F6.
A warning will appear.
- Click on Rename package
- Clear AndroidRide and put new Name in it. Here “xyz”
- Click Do Refactor
- Repeat the same process.
- Right click on myapplication,Refactor -> Rename and Rename package.
- Change myapplication to yourapplication
- Click on Do Refactor.
- After changing the package name, open build.gradle(module) and change Application Id
- change applicationid “com.androidride.myapplication” to “com.xyz.yourapplication”.
- After changing applicationid, click on sync now.
Congrats. Package name successfully changed.
- Android Layout? What is that?
- Why setContentView() in Android Had Been So Popular Till Now?
- Do you want to make apk in less time? Use this method
- 2 Strategies about how to run android app over WiFi in Android Studio (without Root)
Method 2 – How to change full package name of project by creating new package
In this method, We are going to change package name “com.androidride.myapplication” to “info.xyz.yourapplication”
- Right click on com.androidride.myapplication package and select Refactor->Move
- Choose Move package “com.androidride.myapplication” to another package and click on OK.
Now you will get a warning dialog shows Multiple directories correspond to package com.androidride.myapplication
- Click on Yes
- Enter the new package name except the last level, For example. If you want to make package name as “info.xyz.yourapplication” then type “info.xyz” only, like above. Avoid the last part, here “yourapplication”.
- Click YES for creating new package.
- Click on Do Refactor. Now package name “com.androidride.myapplication” changes into “info.xyz.myapplication“.
Now we have to change the last package level name,
- Right click on package name -> Refactor -> Rename
- Click on Rename package
- Rename “myapplication” in to “yourapplication”.
- Click on “Do Refactor”
- Use CTRL key and select each package related to old package name and delete. You can use DELETE key in keyboard or right click after selecting old packages and click on delete option from the menu.
- Open build.gradle file, change applicationId and Click on sync now.
Package name successfully changed to “info.xyz.yourapplication“.
Method III – How to rename android app package name in Android Studio using existing package
This method is also same as the second method. Just like second, we change package name “com.androidride.myapplication” to “info.xyz.yourapplication“.
- Right click on Java and select New -> Package
- Next dialog box appears, choose …app\src\main\java as Destination Directory.
- Enter your package name, here info.xyz.yourapplication
- Now move old package files into new package. Here move files from “com.androidride.myapplication” to “info.xyz.yourapplication“. Just use CTRL key to select all files and drag it to new package.
- Files moved.
- Open AndroidManifest.xml and change package name into “info.xyz.yourapplication“
- Open build.gradle (Module: app) file, change applicationId also. Change it to “info.xyz.yourapplication” and Click on Sync now.
Now you might get errors. It is due to the R file import. There are two scenarios, we can do.
- Remove R file import line from both files and check the error still exists. If not then you can delete old package files now
- Otherwise, If the error still exists, do the below steps.
It’s done. You have successfully changed the package name.
- Select R file import line just like above and press CTRL + SHIFT + R . Replace with new package name. Click on replace all.
- Click on replace
- Delete old package and related files
Yes, the package name is changed.
Express your thoughts below and tell your friends about this post. Thank you.