Change namespace of Android App

If you are a Android/Google Play App developer.. I'm sure you would know the pain when it comes to changing the namespace/package name of the app. There is no easy way of doing it and newbies like me always struggle for hours to get this small thing done!
Again, I'm not an expert in this domain but I did not found a good blog anywhere which explains it in simple ways.. hence sharing the way I make it work.

Let's assume that you have downloaded a sample code of android app which has a namespace as:
com.example.helloworld

And all you want to do it is to change the namespace/package name to:
com.abccorp.myworld

To make this change you need to first understand that there are different kind of android code files in your project which might be referring to the com.example.helloworld. Typically these files are:
  • Code files
  • Layouts
  • Resources
  • Gradle files
  • Values etc
We need to make namespace/package name changes in all these files to make the code work.
Changing the namespace/package name has never been so easy before.. just take couple of these steps below and you are good to go.

Step #1: Update Project Structure

Open Windows Explorer and go to your Android Project Folder: src > main > java



You can see that folders here are structured as per the namespace [com.example.helloworld]
Now, simply update the folder names as per the new namespace requirement [com.abccorp.myworld]
After the update it will look like below:


Step #2: Update Project Files

In Windows Explorer; go to the Main project folder - HelloWorld
And search for *.java files



Open all these file together in a tool such as Notepad++ [you can choose your favorite tool].
And click Ctrl+H [Replace] command


Provide -
Find What: com.example.helloworld
Replace With: com.abccorp.myworld

And click - Replace All in All Opened Documents.

This will replace all the occurrences of namspace/package name

Repeat Step #2 for finding and replacing file extensions:
*.xml
*.gradle

Finalize:

Once step #2 is complete and you have modified all the files [*.java, *.xml & *.gradle]; open the Android Studio Project and click:
Build > Clean Project

This would complete the namespace/package name change and you should be able to build and run the project!

Alternately, you can download the Package Name Changer utility from envato market here: