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 sure it works on ios with xcode simulator etc.
So my current idea is to create a new react native bare project (let's call it Y) with ios folder, then follow these steps to rename Y so that it has the name of X and then moving the /ios directory from Y into X and trying to run-ios
.
I'll update here how that goes, but I wondered if there is a better way and has nobody been in this situation before?
I've googled lots of things 'regenerate ios folder' 'deleted ios folder' 'add ios folder to existing..' and nothing helpful. Maybe my googlefu isn't good enough but if anyone has any suggestions, much appreciated.
Step 2 will be making sure it compiles because of dependencies and stuff but for now my goal is to just get the /ios folder back in the project and for React Native to be aware of it's existence (it has all the necessary config).
Thanks
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.
Simply remove/delete android and ios (keep backup android and ios folder) and run following command:
react-native eject
Supported version :
react-native <= 0.59.10
react-native-cli <= 1.3.0
react-native upgrade --legacy true
Supported version :
react-native >= 0.59.10
react-native-cli >= 1.3.0
Ref : link
Note as of react-native 0.60.x you can use the following to regenerate ios/android directories:
react-native upgrade --legacy true
Credit here: https://github.com/facebook/react-native/issues/25526
This is too late, but for anyone who is still having same issue and have a detached react native app, what i did for me I just run exp detach over my detached app and it created ios folder!
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"}
Since react-native eject is depreciated in 60.3 and I was getting diff errors trying to upgrade form 60.1 to 60.3 regenerating the android folder was not working.
I had to
rm -R node_modules
Then update react-native in package.json to 59.1 (remove package-lock.json)
Run
npm install
react-native eject
This will regenerate your android and ios folders Finally upgrade back to 60.3
react-native upgrade
react-native upgrade while back and 59.1 did not regenerate my android folder so the eject was necessary.
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
来源:https://stackoverflow.com/questions/42506068/how-can-i-regenerate-ios-folder-in-react-native-project