如何在 React Native 项目中重新生成 ios 文件夹?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42506068/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I regenerate ios folder in React Native project?
提问by Tam Borine
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.
所以不久前我删除了我的本机应用程序中的 /ios 目录(我们称之为 X)。我一直在使用 android 模拟器进行开发和测试,但现在我想确保它可以在带有 xcode 模拟器等的 ios 上运行。
So my current idea is to create a new react native bare project (let's call it Y) with ios folder, then follow these stepsto 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
.
所以我现在的想法是用 ios 文件夹创建一个新的 react native 裸项目(我们称之为 Y),然后按照以下步骤重命名 Y,使其具有 X 的名称,然后将 /ios 目录从 Y 移动到 X 和试图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.
我在谷歌上搜索了很多东西“重新生成 ios 文件夹”“删除的 ios 文件夹”“将 ios 文件夹添加到现有......”,但没有任何帮助。也许我的 googlefu 不够好,但如果有人有任何建议,非常感谢。
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).
第 2 步将确保它由于依赖项和其他东西而编译,但现在我的目标是将 /ios 文件夹恢复到项目中,并使 React Native 知道它的存在(它具有所有必要的配置)。
Thanks
谢谢
回答by milkersarac
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.
您需要遵循的过程与重命名 React Native 应用程序非常相似。基本上你只需要react-native upgrade
在你的根项目目录中运行。有关更多信息,您可以在此处查看另一个问题。下面的说明解释了如何基于具有新名称的复制项目创建另一个 React Native 项目。
- 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.
- 首先复制您要更改名称的应用程序所在的目录。并转到您新克隆的目录。
- 更改
index.ios/android.js
作为参数提供给 AppRegistry 的文件中的名称。 - 相应地更改名称和版本
package.json
- 删除
/ios
和/android
它们从旧的应用程序其余文件夹。 - 再次运行
$react-native upgrade
以生成/ios
和/android
文件夹。 - 运行
$react-native link
任何本机依赖项。 - 最后运行
$react-native run-ios
或任何你想要的。
回答by Khurshid Ansari
Simply remove/delete android and ios (keep backup android and ios folder) and run following command:
只需删除/删除 android 和 ios(保留备份 android 和 ios 文件夹)并运行以下命令:
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.60.0
react-native-cli >= 2.1.0
Ref : link
参考:链接
回答by groundtruth-andy
Note as of react-native 0.60.x you can use the following to regenerate ios/android directories:
请注意,从 react-native 0.60.x 开始,您可以使用以下内容重新生成 ios/android 目录:
react-native upgrade --legacy true
Credit here: https://github.com/facebook/react-native/issues/25526
信用在这里:https: //github.com/facebook/react-native/issues/25526
回答by aleclarson
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.
正如@Alok 在评论中提到的,您可以react-native eject
生成ios
和android
文件夹。但是你app.json
首先需要在你的项目中。
{"name": "example", "displayName": "Example"}
回答by Mizlul
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!
这为时已晚,但是对于仍然存在相同问题并拥有分离的 React Native 应用程序的任何人,我为我所做的我只是在分离的应用程序上运行 exp detach 并创建了 ios 文件夹!
回答by Muthukrishnan
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.
好像react-native eject
已经没有了。我能找到的重新创建 ios 文件夹的唯一方法是从头开始生成它。
Take a backup of your ios folder
备份你的 ios 文件夹
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
在项目中的 ios 文件夹中安装 pod 依赖项
cd /path_to_your_old_project/ios
pod install
回答by akio
? react-native eject
? react-native eject
error Unrecognized command "eject". info Run "react-native --help" to see a list of all available commands.
错误无法识别的命令“弹出”。info 运行“react-native --help”以查看所有可用命令的列表。
? react-native upgrade --legacy true
? react-native upgrade --legacy true
error: unknown option `--legacy'
错误:未知选项`--legacy'
You can init a new project that's named the same in another folder and copy ios dir over:
您可以在另一个文件夹中初始化一个同名的新项目,然后将 ios 目录复制过来:
inside YourProjectName directory
在 YourProjectName 目录中
npx react-native init YourProjectName
mv YourProjectName/ios ios
rm -rf YourProjectName
Make sure you have clean git history before doing so, in case you need to revert
在这样做之前确保你有干净的 git 历史记录,以防你需要恢复
回答by Manju Priya
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”命令时,它给了他们不需要更新的消息,或者使用“react-native eject”命令无法识别该命令。
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”命令来备份你的android文件夹或ios,因为这个命令将替换你的文件。
react-native upgrade --legacy true
react-native upgrade --legacy true
Now it's just telling you not to replace your package.json
现在它只是告诉你不要替换你的 package.json
回答by Paul Gehrke
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.
由于本机弹出在 60.3 中折旧,并且我在尝试将表单 60.1 升级到 60.3 时遇到差异错误,因此重新生成 android 文件夹不起作用。
I had to
我不得不
rm -R node_modules
Then update react-native in package.json to 59.1 (remove package-lock.json)
然后将 package.json 中的 react-native 更新为 59.1(去掉 package-lock.json)
Run
跑
npm install
react-native eject
This will regenerate your android and ios folders Finally upgrade back to 60.3
这将重新生成您的 android 和 ios 文件夹最后升级回 60.3
react-native upgrade
react-native upgrade while back and 59.1 did not regenerate my android folder so the eject was necessary.
react-native 升级,而 59.1 没有重新生成我的 android 文件夹,所以弹出是必要的。
回答by Abey Thomas
Remove the ios folder first
先删除ios文件夹
react-native eject
cd ios/
pod init
pod install
cd ..
react-native link
cd ios
open *.xcworkspace/