Change package name for Android in React Native

后端 未结 20 1798
鱼传尺愫
鱼传尺愫 2020-11-30 16:13

I used react-native init MyApp to initialise a new React Native app. This created among others an Android project with the package com.myapp.

相关标签:
20条回答
  • 2020-11-30 16:48

    After running this:

    react-native-rename "MyApp" -b com.mycompany.myapp
    

    Make sure to also goto Build.gradle under android/app/... and rename the application Id as shown below:

    defaultConfig {
            applicationId:com.appname.xxx
    ........
    }
    
    0 讨论(0)
  • 2020-11-30 16:53

    Follow the simple steps to rename your app name and Package name in case you have not made any custom changes in android folder(ie. scenario where u just initialized the project)

    1. Simply change the name in the package.json file as you need and save it.
    2. Remove the folder named android
    3. run the command react-native upgrade

    Note:As ivoteje50 mentioned in comment,Don't remove the android folder if you have already followed the official instructions to generate a keystore, since it will remove the keystore and you cannot sign a new app again.

    0 讨论(0)
  • 2020-11-30 16:55

    In VS Code, press Ctrl + Shift + F and enter your old package name in 'Find' and enter your new package in 'Replace'. Then press 'Replace all occurrences'.

    Definitely not the pragmatic way. But, it's done the trick for me.

    0 讨论(0)
  • 2020-11-30 16:56

    Goto Android studio

    Right click your package (most probably com)-> Refractor -> Rename -> Enter new package name in the dialog -> Do Refractor

    It will rename your package name everywhere.

    0 讨论(0)
  • 2020-11-30 16:57

    I've used the react-native-rename package.

    In terminal run the command to install:

    npm install react-native-rename -g
    

    In the root of your React Native project, run the following command:

    react-native-rename "NewNameOfApp" -b com.companyname.newnameofapp
    
    0 讨论(0)
  • 2020-11-30 16:57

    very simple way :

    cd /your/project/dir
    

    run this command :

    grep -rl "com.your.app" . | xargs sed -i 's/com.your.app/com.yournew.newapp/g'
    

    rename your folder

    android/app/src/main/java/com/your/app
    

    change to

    android/app/src/main/java/com/yournew/newapp
    
    0 讨论(0)
提交回复
热议问题