How can I regenerate ios folder in React Native project?

后端 未结 13 621
忘掉有多难
忘掉有多难 2020-11-29 20:13

So a while ago I deleted the /ios directory in my react native app (let\'s call it X). I\'ve been developing and testing using the android emulator but now I\'d like to make

相关标签:
13条回答
  • 2020-11-29 20:41

    As @Alok mentioned in the comments, you can do react-native eject to generate the ios and android folders. But you will need an app.json in your project first.

    {"name": "example", "displayName": "Example"}
    
    0 讨论(0)
  • 2020-11-29 20:44

    The process you need to follow is so similar to renaming a react native app. Basically you just need to run react-native upgrade in your root project directory. For further info you can check another question here. The instructions below explains how to create another react native project based on a copied one with a new name.

    • 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.
    • Run $react-native upgrade to generate /ios and /android folders again.
    • Run $react-native link for any native dependency.
    • Finally run $react-native run-ios or anything you want.
    0 讨论(0)
  • 2020-11-29 20:46
    1. Open Terminal/cmd
    2. Move to the folder/directory where the project "ProjectName" folder exist(Do not go into project directory)
    3. run command as: react-native init "ProjectName" and it will warn that project directory already exist but you continue.
    4. It will install all updated node modules as well as missing platform (android/ios) folders inside project without disturbing the code already written.
    5. cd "ProjectName" and then cd ios and then run pod install

    PS: Take backup of your code in case it changes App.js

    0 讨论(0)
  • 2020-11-29 20:50

    I just found myself with this problem too, but I just solved it.

    Surely when running the "react-native upgrade" command, it gave them the message that it was not necessary to update or with the command "react-native eject" that the command is not recognized.

    react-native upgrade

    Now you should use the react-native upgrade --legacy true command to back up your android folders or ios as the case may be as this command will replace your files.

    react-native upgrade --legacy true

    Now it's just telling you not to replace your package.json

    0 讨论(0)
  • 2020-11-29 20:51

    It seems like react-native eject is no more available. The only way I could find for recreating the ios folder was to generate it from scratch.

    Take a backup of your ios folder

    mv /path_to_your_old_project/ios /path_to_your_backup_dir/ios_backup
    

    Navigate to a temporary directory and create a new project with the same name as your current project

    react-native init project_name
    mv project_name/ios /path_to_your_old_project/ios
    
    

    Install the pod dependencies inside the ios folder within your project

    cd /path_to_your_old_project/ios
    pod install
    
    0 讨论(0)
  • 2020-11-29 20:52

    If you are lost with errors like module not found there is noway other the than following method if you have used react native CLI.I had faced similar issue as a result of openning xcode project from .xcodeproj file instead of .xcworkspace. Also please note that react-native eject only for Expo project.

    The only workaround to regenarate ios and android folders within a react native project is the following.

    • Generate a project with same name using the command react-native init
    • Backup your old project ios and android directories into a backup location
    • Then copy ios and android directories from newly created project into your old not working project
    • Run pod install within the copied ios directory

    Now your problem should be solved

    0 讨论(0)
提交回复
热议问题