ChatGPT解决这个技术问题 Extra ChatGPT

Change App Name In React Native

I'm trying to figure out how to change a ReactNative app name. The installed APK on my device is simply "App", with the Android icon. How can I change this?

I've tried changing package.json and re-running react-native upgrade but it didn't update AndroidManifest.xml


M
Mufaddal Hamid

The generator does not override the strings.xml file located in android/app/src/main/res/values/, so you have to change the app_name variable manually


Also make sure that the getMainComponentName() in your MainActivity returns your react native app name. i.e. name in app.json
what about IOS ?
react-native-rename is apparently unmaintained and unuseable at this point.
What about iOS ?
to change react-native IOS App display name you can change 'Bundle display name' property from info.plist
C
Chhay Rith Hy

For Android

Modify displayName in app.json file

Modify app_name in android/app/src/main/res/values/strings.xml

then Run these commands one by one

cd android
./gradlew clean
cd ..
react-native run-android

For iOS

Modify Display Name in Project target (General Tab)

https://i.stack.imgur.com/PYp4A.png


Thanks so much, this worked for me after trying so many other solutions
you sir, is a life saver
its not showing my display name in Host Application drop down
displayName is corresponding to key name in app.json
P
Paul Nyondo

Try react-native-rename this npm package will ease the process

This package assumes that you created your react-native project 
using react-native init.

Note: This package does not attempt to properly rename build artifacts such as ios/build or Cocoa Pod installation targets. After renaming your project you should clean, build, and reinstall third party dependencies to get it running properly with the new name.

// in project directory

   npx react-native-rename <newName>

While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
issue addressed
@MikeS. this is not a bad practice since it is NOT a project dependency but a tool, and having them as project dependencies is indeed a bad practice. Is like CRNA, you should have it as a global tool
WARNING: Do not use this library. it will ruine your project. Never use this.
DO NOT USE. As of this writing, this package is deprecated / unmaintained and will make your project unusable.
R
Rahul Rastogi

First of all: Open app.json file in your react-native project directory. And, just replace displayName json property's value in this file. e.g.:

{
    "name": "SomethingSomething",
    "displayName": "My New App Name"
}

For Android app: Open strings.xml file, replace the <string name="app_name"> tag's value to your new app name. e.g.:

<string name="app_name">My New App Name</string>

For iOS: Open info.plist, replace the value after <key>CFBundleDisplayName</key> to your app name. e.g.:

<key>CFBundleDisplayName</key>
<string>My New App Name</string>

Uninstall your previous app installed on your device. Use npm install in project main directory, in ios folder directory run pod install commands. Now, simply install app in your device.


If i want to change the Bundle Identifier?
@OliverD For Android, change application ID in android/app/build.gradle file and for iOS, change the Bundle Identifier in iOS project. Don't forget to re-configure your third-party accounts in case of google sign in, facebook sign in etc.
If you want everything clean you need also to open xcode and rename your app from there.
E
Eduardo Cuomo

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.


I tried this method, but it didnt solve my problem. When app run in my mobile its says with an error "Application has not been registered"
Tried @KlaasNotFound method. Successfully got new build uprunning
I got same problem like @NIKHILCM with react-native 0.56
C
Charitha Goonewardena

UPDATE 2021 React native version: 0.64.0

Android

Find and open following files and change as required.
\android\app\src\main\res\values\strings.xml

<resources>
    <string name="app_name">My App</string>
</resources>

app.json

{
  "name": "MyApp",
  "displayName": "My App"
}

iOS

Find and open the \ios\YourAppName\Info.plist and change as required.
NOTE: if your name has spaces use &#x2007; instead of spaces.

<key>CFBundleDisplayName</key>
<string>My&#x2007;App</string>

Fantastic! Thank you!
K
KlaasNotFound

I find that, if you want to change both the app name and the package name (i.e. rename the entire app), the following steps are necessary:

Make sure you don't have anything precious (non-generated, manually copied resources) in the android/ and ios/ subfolders.

Delete both the android/ and ios/ folder.

Change the "name" entry in your package.json to the new name.

Change the app name in both your index.android.js and index.ios.js: AppRegistry.registerComponent('NewAppName', () => App);

Run react-native upgrade to re-generate the platform subfolders.

If you have linked resources (like custom fonts etc.) run react-native link.

If you have other generated resources (like app icons) run the scripts to generate them (e.g. yo).

Finally, uninstall the old app on each device and run the new one.


Just a note: I think step #1 should be create a repo test branch first.
As of today, there's a new npm package that alleges to minimize these issues, react-native-git-upgrade. But I can't get it to run using yarn. My project doesn't use npm, nor do I want to install it globally. So, trying to figure out my options. So far, react-native-git-upgrade fails from CLI
thanks a lot for you steps I followed some and it worked
Also have to do a debug keystore stackoverflow.com/a/57438549/5900793
react-native upgrade does not generate platform subfolders anymore.
M
Mufaddal Hamid

If you are asking only for Android here is solution

Modify displayName in /app.json file

Modify app_name in android/app/src/main/res/values/strings.xml

then Run these commands one by one

cd android
gradlew clean
cd ..
react-native run-android

how come i cant run react-native eject and it says i name must be defined in the app.json but i have it?
this will cause error: Invariant vilation: xxxAPP has not been registered. ( xxxAPP was the older app name)
If youre running on windows gradlew should be run using ./gradlew
@tesshsu Before install the APP with the new name, you should uninstall the previous APP.
G
Green

If you don't have any thing precious in your android folder, you can delete the folder then run react-native upgrade then react-native android. These will recreate AndroidManifest.xml along with necessary files and folders. (Tried on 0.18 in Windows 10)


Works on macOS Sierra as well.
B
Biswajit

for android android/app/src/main/res/values/strings.xml My Android App

for ios Just open it in xCode select project tab general just rename it.


s
saeed eivazi

simply change <string name="app_name"> 'NEW_APP_NAME' </string> located in

[project_dir]/android/app/src/main/res/values/strings.xml

NOTE: recommended

react-native-rename

by Paul Nyondo maybe affect MainApplication.java file, DON'T USE IT!


Agreed, I had isntall react-native-rename and it does another problem in APP
S
Sarath Ak

You can try this

Update displayName in app.json to the new name Delete ios/ and android/ directories Run react-native eject Run react-native link


eject seems not working if over React 0.6 upper, so the command show error: error Unrecognized command "eject".
g
gauravsbagul

before changing the app name get your code's backup and then , Go to following path in and replace your app name with new app name and change i one more file app.json E:***\android\app\src\main\res\values\strings.xml

<resources>
    <string name="app_name">New Name</string>
</resources>

app.json

{
  "name": "oldName",
  "displayName": "New Name"
}

C
Chaurasia

Simply way

PROJECT >android > app > main > res > style

Then change the app name


H
Hussain Abu Alamal

first of all create a whole backup of the project including node modules (in order to restore icons/phots ..etc in the future)

Update name and displayName in app.json to the new name rename app folder the same as app name Delete ios/ and android/ directories delete ndoe modules update name in package.json (you must use new name for import & require() in your code. eg : import {x} from 'NewAppName/src/api') watchman watch-del-all rm -rf /tmp/haste-map-react-native-packager-* rm -rf /tmp/metro-bundler-cache-* restart pc sudo npm install react-native eject restore icons/images react-native link restart pc run app caution : you may have to setup things manually. in my case SplashScreen


very complicated not simple
k
kalyan

Changed my app name in android/app/src/main/res/values/strings.xml as:

<resources>
    <string name="app_name">My App</string>
</resources>

and re-run using npx react-native run-android


G
Ganesh Moorthy A

To change the name of the react-native Application

1 . Open ./android/app/src/main/java/[multiple folders]/MainActivity.java

 @Override
  protected String getMainComponentName() {
    return "NameOfTheApp";
  }

Open android/app/src/main/res/values/strings.xml NEW APP NAME Change Name in App.json and package.json.

4.For clean android project run following command

cd android &&./gradlew clean