How to Change Package Name in Android Studio

There are some cases when you develop Android application, you need to change your package name. Whether request from your client or your own projects, or there are the same package name in Play Store with your app package name. This package name need to be unique if you want to upload to Play Store. Some people still struggle to change the existing package name, including me. Haha 🙂

After doing some research, this guide is the best solution and easy to follow guide for everyone. I will guide you step by step how to change Android package name in Android Studio. Let’s begin.

First, in this tutorial, let’s say we have package name com.example.sampleapp and we want to change it to com.waysquare.firstapp.

Step 1 Unchecked Compact Middle Packages

The default setting of Android Studio that it has Compact Middle Packages checked. So you need to unchecked it. Go to Android Studio project explorer -> Navigate to gear icon (as picture below) -> Uncheck Compact Media Packages

This option will de-compact your package name so you can easily change the package name later. Notice the project structure change to individual folder.

Step 1. Unchecked Compact Middle Packages – Before

Step 2. Unchecked Compact Middle Packages – After

Step 2 Rename each package subfolder

We want to change our package name from com.example.sampleapp to com.waysquare.firstapp. So, we need to change the second and third subfolder name.

Right click on example folder and choose Refactor -> Rename

Refactor -> Rename

If this popup appear choose Rename package to continue.

Change from example to waysquare.

Rename subfolder

Checked also the two checkbox to apply changes to comments and strings.

Checked also the two checkbox

Confirm your change by clicking Do Refactor button.

You are done by changing the second subfolder. Do the same for third subfolder from sampleapp to firstapp

Now your project structure will appear like below.

Final project structure

Step 3 Replace All Package Name in Code

Next step is to change all the package name shown in our code to our new package name.

Right click on app folder and choose Replace in Path…

Replace package name before and after. If no any available package name to change, the window will show Noting to show message. Confirm by clicking Open in Find Window.

Replace package name

If new dialog box “Do you want to replace this occurnace?” appear, confirm it by clicking “All Files” button.

You are finish. Try to clean your project and rebuild. Check if any error occur.

Leave a Reply

Your email address will not be published. Required fields are marked *