How to change Android package name in a React Native App

blank box
package

In Android the package name is an identifier of your app. In an android device every app should have an identifier for that app and that identifier is the package name. That’s true to publish your app in Google’s Play Store as well, just like any’ android published app store. Just like in a java package the convention is your domain name in reverse, like : com.slashlogs.myawesomeapp.

In this tutorial we gonna learn how to set up that package name for our app in React Native.

For new Apps

If you are just starting up a new app it is straightforward just pass your chosen package name to the react native with the argument –package=.

react-native init MyApp --package=com.slashlogs.myapp

Change the package name of existing React Native app

If you have already started a RN project and want to change the package name the process is not so straightforward and you have to change some files in your project in order to get the new package name to work with your React Native app. Please note that if your app had been already publish in an online store changing the package name is telling that you are building a totally different app, as far as i know you cannot change a app in android play store after publishing. if that’s not the case just continue on.

Follow this steps to change the package name on your React Native android app.

Open up your RN project in your favorite IDE and just follow along. In this example i will change the package name from com.mytestapp to com.slashlogs.superapp:

  • Change the Java’s package name it is just a folder structure, under the folders under “android/src/main/java”.
    from android/app/src/main/java/com/mytestapp to /android/app/src/main/java/com/slashlogs/superapp
  • Inside those folders there are .java files, normally MainActivity.java and MainApplication.java but can be more, all those java files start with package com.mytestapp; change it to package com.slashlogs.superapp;
  • Change the package name on App’s Android Manifest located at android/app/src/main/AndroidManifest.xml to the new package name.
  • in the build grade file change it to the new package name as well, the file is located at android/app/build.gradle be aware to choose that build.gradle file in the right folder there are other folders that have a file named that way.
  • finally go to android/app/_BUCK and change all occurrences of package=”com.mytestapp” to package=”com.slashlogs.superapp”
  • take a deep breath you’re almost done šŸ˜†.

Now the files have changed a lot you should clean your project to do so open a terminal window and navigate to /android folder. then type:

.\gradlew clean

With that done you can now install the app in your emulator or phone. The package name should be the new one. Consequently if you installed this app before you should have now 2 apps installed since the package name changed android thinks that this is a different app. Just uninstall the old one, if you want.

Conclusion

Now you good to go with your new package name. There are npm packages that do this work you but its not that hard to get that done by yourself without having to add another npm dependency to our project.

Good luck with your app and be safe and healthy. If you have any question post it in the comment section bellow.

Leave a comment

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