Renaming a React Native project?
Asked Answered
C

15

106

Are there instructions for what needs to be changed in order to rename a React Native project? I have an app called something along the lines of MyAppIOS and I want to rename it to simply MyApp (now that Android support is out)

Chicago answered 28/9, 2015 at 19:5 Comment(0)
M
73

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.

Mudstone answered 29/9, 2015 at 5:34 Comment(3)
Most should pick up on this but just FYI this answer is for ANDROID ONLY.Laurelaureano
for both iOS and Android follow this answer: https://mcmap.net/q/142228/-change-app-name-in-react-nativeVesical
This actually changes the display name not the name of the project. BTW for ios, to change the display name, goto info.plist file and change the value of CFBundleDisplayName key to your desired value.Subak
C
92

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);
Cooperstein answered 13/12, 2015 at 6:2 Comment(4)
I also had to rename the main class correspondingly: class MyApp extends Component { .... etc.Al
this doesn't delete the old MyAppIOS files, so you'll also want to do: $ rm -rf android/app/src/main/java/com/myappios && rm -rf ios/MyAppIOS*Londoner
I think that react-native upgrade will upgrade your react-native too, be careful because this could broken something with your dependencies.Ijssel
We found a number of additional steps scattered around the web - posted a complete list (and accepting pull requests!) at: github.com/2MR/renaming-a-react-native-projectInward
M
73

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.

Mudstone answered 29/9, 2015 at 5:34 Comment(3)
Most should pick up on this but just FYI this answer is for ANDROID ONLY.Laurelaureano
for both iOS and Android follow this answer: https://mcmap.net/q/142228/-change-app-name-in-react-nativeVesical
This actually changes the display name not the name of the project. BTW for ios, to change the display name, goto info.plist file and change the value of CFBundleDisplayName key to your desired value.Subak
L
44

What simply works for me several times is instructed below;

  • First copy the directory 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.
Lor answered 22/11, 2016 at 11:47 Comment(4)
Newer versions of react native have you also change the values in app.json if I remember correctly.Galarza
Yes, it seems that after 0.41 react-native offer an official way to re-generate native folders /ios and /android. For more one could check react-native ejectLor
Good source: medium.com/the-react-native-log/…Maternity
react-native upgrade will actually upgrade your react-native version as well. keep that thing in mindErrecart
R
27

For iOS, the way to change xcodeproj settings is also available.

Show <your app name> -> Info.plist and add Bundle display name.

changing iOS app name:

enter image description here

Rustle answered 22/6, 2016 at 5:56 Comment(0)
K
18

I am probably a bit late, but for the people looking for a solid solution, there is a react-native-rename npm package which can do the magic.

Kirmess answered 29/3, 2017 at 17:22 Comment(1)
Do not use this package. See the many other warning comments in this thread.Knighthead
G
8
  1. Update displayName in app.json to the new name
  2. Delete ios/ and android/ directories in root project
  3. At command line Run:

    react-native eject
    react-native link 
    
Ganglion answered 17/10, 2017 at 3:12 Comment(1)
This is an expo-specific answer. It doesn't apply to standard CRNA or react-native init workflows.Knighthead
P
8
  1. For IOS app, change in xcodeproj settings is also available.

Open Info.plist file from your project directory/ios/{appname} directory and change Bundle display name.

<key>CFBundleDisplayName</key>
<string>NEW APP NAME</string>
  1. For android app, you can change in android folder of your project directory.

    cd android/app/src/main/res/values/

open strings.xml file and change you app name in

 <string name="app_name">NEW APP NAME</string>
Paladin answered 25/1, 2018 at 5:23 Comment(0)
D
5

As mentioned here (https://github.com/facebook/react-native/issues/4227), you don't need to add a Bundle display name key, as said by @janus_wel.

You can simply update Bundle name from $(PRODUCT_NAME) to My App.

Dorren answered 7/9, 2016 at 9:37 Comment(1)
This is the only solution that worked for me. I added a build setting called CUSTOM_DISPLAY_NAME (to support different app names for debug and release), then simply updated Bundle name to be $(CUSTOM_DISPLAY_NAME)Toile
Y
5

You might also want to check out npm package (react-native-rename):

Usage:

react-native-rename < newName >

It works fine for my project.

Yah answered 5/10, 2017 at 12:14 Comment(2)
In my app, this command deletes my java files under android/app/src/main/java/com/appname!Birkner
WARNING: Do not use this library. it will ruine your project. Never use this.Tinhorn
T
5

Rename react-native app with just one command react-native-rename

Installation

yarn global add react-native-rename or npm install react-native-rename -g

Usage run the below command in the project's directory.

react-native-rename <newName>

Example:

react-native-rename "Travel App"

Toothpaste answered 25/4, 2020 at 0:6 Comment(0)
D
1

In-Case None of solution worked for you or trying something broke your app. This is going to basics.

  1. Init a new react-native project with whatever name you want to change your app to.
  2. Copy Dependency list from your previous project to new one's package.json
  3. Copy old project files, make sure of keeping the same structure.
  4. Run npm install
  5. Run react-native run-android

This should get you back on track

Duston answered 9/1, 2020 at 2:20 Comment(0)
S
1

If you are using vs code, then it is much easier and works really fine.

1)Open your project in vs code, goto search tab.There are two text inputs, first takes the input which you want to search in all the files in your project (some files and directories are excluded and you can manage them in settings, but that is not needed). The other text input takes the input with which you want to replace the first input in all the files (in simple words, change all occurences).

  1. In the first input field, search for com.<your_package_name>. This is the older name of your project (current name of project which you want to change).

  2. In the second input field, enter com.<new_package_name> and press the replace button (small icon button on the right side of 2nd input field). It will replace all the occurences of the older package name thus renaming the project.

{Repeat the above two steps with <your_package_name> only too}

  1. Now goto android>app>src>main>java>com>older_package_name .Rename the older_package_name to the new package name and you are done.

  2. cd android && ./gradlew clean && cd ...

  3. And you are done. Run npx react-native run-android to test the app.

Subak answered 28/10, 2022 at 10:5 Comment(0)
R
0
  • First of all copy the address which your want to-be-name-changed application exists. And go to your newly cloned directory.

  • Replace the name at the index.ios/android.js file which is given as a parameter to AppRegistry.

  • update the name and version accordingly on package.json remove /ios and /android folders which are remaining from your older app and from the

  • run $react-native upgrade to generate /ios and /android folders again. and run $react-native link for any external dependency.

  • finally, run $react-native run-ios or else.

Ruth answered 7/9, 2018 at 11:27 Comment(0)
R
0

The following steps must be followed while renaming Project/app in react Native 1. create a new folder test

  1. Copy and paste all files from demo to test folder

  2. Change the name in package.json file

  3. Change the name in package-lock.json file

  4. Change the name in App.json file

  5. Delete /ios and /android folders

  6. Run react-native eject command to create /ios and /android folders again

  7. run react-native link for any external dependency.

  8. finally run your app by using react-native run-android command.

Form more information visit https://youtu.be/_lgH9LXf818

Reopen answered 5/5, 2020 at 13:25 Comment(0)
H
-1

The easiest way for android application is to navigate to /android/app/src/main/res/values You will see file strings.xml

Inside the file you would see.

<resources>
    <string name="app_name">{YOUR NEW NAME}</string>
</resources>
Hypnos answered 19/10, 2022 at 19:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.