配置RN环境遇到的问题总结并记录

1,612 阅读1分钟

1. 起因

rn升级到0.59版本配置自己的模拟器环境发现报错

 cuizhengyang@cuizhengyangdeMacBook-Pro > react-native run-ios --verbose 
 
 error Failed to build iOS project. We ran "xcodebuild" command but it exited with error code 65. To debug build logs further, consider building your app with Xcode.app, by opening wl_cloudpay_rn_web.xcodeproj

2. 修复

2.1 步骤一

在论坛上查到一篇博客,在这边文章中我知道了需要下载几个包并且放到指定的目录下,大家可以根据这篇文章去配置自己的对应的文件。

2.2 步骤二

然后你需要执行如下命令

cd ~/WebstormProjects/wl_cloudpay_rn_web/node_modules/react-native/scripts 
find ./ -name "*.sh" |xargs chmod +x
chmod +x launchPackager.command 
 ./ios-install-third-party.sh 

这个时候你可能会遇到2个错误,第一个错误 :

/usr/bin/env: ‘bash\r’: No such file or directory

这主要是因为\r这个字符的缘故。在linux终端下,输出\r会什么都不显示,只是把光标移到行首。
这个时候需要用到命令: dos2unix ,安装方法如下:

brew install dos2unix

然后执行

dos2unix ios-install-third-party.sh 

如果你再也不想遇到这个问题,可以在node_modules 文件夹所在的目录执行:

 find ./node_modules -name "*.sh" |xargs dos2unix -k

第二个错误:

./ios-install-third-party.sh: line 64: ./ios-configure-glog.sh: No such file or directory

此时你需要执行如下命令:

 cd third-party/glog-0.3.5
 ../../ios-configure-glog.sh

2.3 步骤三

重新执行:react-native run-ios --verbose 模拟器应该起来了,但是模拟器界面上会报错

No bundle URL present.

Make sure you're running a packager server or have included a .jsbundle file in your application bundle.

这个时候执行如下命令:

cd node_modules/react-native/scripts   
chmod  +x launchPackager.command
dos2unix launchPackager.command 

如果依然报同样的错误,那么可能是你配置了代理,或者hosts 中localhost没有指向本地

3. 结束

这样应该就可以正常运行了