React Native: Rename the project. Do’s and Don’ts

So most common and also the toughest question is can we rename the existing react native project? A simple answer is YES YOU CAN. There are many RIGHT ways to achieve this. but if you miss some minor details then the mistake cost goes very high. You need to follow any method listed right below.

Image for post
Image for post

Method-1

You can change the name attribute in package.json, run react-native upgrade, and just let react overwrite the android/ios files. Don't overwrite your index files if there is unsaved code, however.

Then change your Appregistry line from

AppRegistry.registerComponent('MyAppIOS', () => MyAppIOS);

To:

AppRegistry.registerComponent('MyApp', () => MyApp);

Method-2

What simply works for me several times is instructed below;

  • First copy the directory in which your to-be-name-changed application exists. And go to your newly cloned directory.
  • Change the name at index.ios/android.js file which is given as a parameter to AppRegistry.
  • Change the name and version accordingly on package.json
  • delete /ios and /android folders which are remaining from your older app as well as the app.json file if you have.
  • run $react-native upgrade to generate /ios and /android folders again.
  • run $react-native link for any external dependency.
  • finally, run $react-native run-ios or anything you want.

Method-3 [Onlt For Android]

The way I did this for android (hacky, but it works) is just changed the string app_name field in

android/app/src/main/res/values/strings.xml

It will change the name of your installed android app to whatever you put as the value. After this change re-run the app.

Now the time comes what you need to take care or YOU SHOULD NOT DO

DON’Ts

You might also hear about the npm package (react-native-rename):

Usage:

react-native-rename < newName >

It works fine but……it will ruin your project. Never use this

Hope this helps someday! ❤

Written by

🤠 Internet Cowboy | 💻 JS Aficionado | http://imharshpatel.com/

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store