DEV Community

Quick guide for updating package name in React Native

Karan Pratap Singh on April 11, 2020

Quick guide for updating package name in React Native Hey, React Native community, in this short article let's see how to change the pac...
Collapse
 
gautham495 profile image
Gautham Vijayan

You sir a legend!!

Collapse
 
gautham495 profile image
Gautham Vijayan

You saved me as google play store is saying "App package name already exists" and I have to do all the steps mentioned here!!

Thanks a lot!

Collapse
 
karanpratapsingh profile image
Karan Pratap Singh

Glad it helped!

Thread Thread
 
gautham495 profile image
Gautham Vijayan

Please add two more things here.

  1. For Splash Screen we have to change the name from old to new.
  2. And in MainApplication.java we have to change package name at class as shown below.
 private static void initializeFlipper(
      Context context, ReactInstanceManager reactInstanceManager) {
    if (BuildConfig.DEBUG) {
      try {
        /*
         We use reflection here to pick up the class that initializes Flipper,
        since Flipper library is not available in release mode
        */

        Class<?> aClass = 
Class.forName("com.<New_Package_name>.ReactNativeFlipper");


        aClass
            .getMethod("initializeFlipper", Context.class, ReactInstanceManager.class)
            .invoke(null, context, reactInstanceManager);
Enter fullscreen mode Exit fullscreen mode
Thread Thread
 
gautham495 profile image
Gautham Vijayan

I ran into errors because of these ones.

Collapse
 
paulg0614 profile image
paulg0614

Thanks!
Worked for most part, but I keep getting a weird warning which I can't seem to figure out.
I am able to get it loaded in Android emulator too.
The warning I get is:
Invalid applications's package name "com.domain.testMe" in AndroidManifest.xml. Read guidelines for setting package name here:.......
Prior to making this change, I didn't get the warning.
Any ideas?

Collapse
 
andrefedev profile image
Andres Osorio

Excellent it helped me a lot, I have a question, after executing "npx react-native run-android" on my android device I get the name of the application "app_name", it does not appear as I put it in app.json displayName: 'App Name', any suggestions?

Collapse
 
xafm profile image
Faruk Mollaoğlu

Great post! Thanks a lot!

Collapse
 
karanpratapsingh profile image
Karan Pratap Singh

Glad it helped

Collapse
 
salmanpixarsart profile image
salman-pixarsart

We also need to update moduleName in appDelegate.m file with our package name. RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
moduleName:@"new_name"
initialProperties:nil];
And make sure you add exact name as you added in app.json file.

Collapse
 
sivaleo profile image
Siva

Thank you its helped well....and simple....Goto VSCode -> search & replace(ctrl+shift+h) ->Enter Search for "OLD_PACKAGE_NAME" enter Replace to "NEW_PACKAGE_NAME" press replace all.....

Collapse
 
pedrohenriquerissato profile image
Pedro Henrique Rissato • Edited

I'm going add to the list to rename inside ios/project_name/AppDelegate.m, since AppName is hard coded.

Collapse
 
adwidianjaya profile image
Adhe Widianjaya

This is the most helpful so far. Thank you so much!

Collapse
 
srinirg profile image
srini-rg

You saved my life. Thanks :-)

Collapse
 
ashackq profile image
Akash Patel

Saved

Collapse
 
firzatullahd profile image
Firzatullah Dwiko Ramadhan

really hellpful. Thanks!