问题描述
在执行yarn ios
命令行提示We ran "xcodebuild" command but it exited with error code 65.
错误
在mac其他电脑开始也出现了这个错误,但经过面向百度编程,删除pod,重新下载等等解决了问题
让同事把node_modules
和Pods
文件夹压缩发来,放到我的电脑中(同样的代码),依旧无效
真机可运行
原因分析:
- 受国内网络影响,可能在安装Pods的时候 有所丢失,推荐科学上网下载
- 依赖包本身的缓存没有清理干净
- 环境兼容问题
- 在xcode中直接模拟器运行,有错误提示
_OBJC_CLASS_$_FKUserDefaultsPlugin
解决方案:
1、第一件事是转到“ios/Podfile”中的 ios podfile 查找 post_install 脚本并添加这行代码
这个配置是针对 iOS 平台的构建设置,用于排除在模拟器(iphonesimulator)中运行时不支持的架构(architecture)“arm64”。
config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
之后你的代码应该如下所示,如果您在 post_install 上还有其他内容,请添加它们。
post_install do |installer|
react_native_post_install(installer)
...
installer.pods_project.build_configurations.each do |config|
config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
end
end
2、配置终端全局代理地址。不会科学上网的,请点击这里 科学上网助手
export https_proxy=http://127.0.0.1:7890 http_proxy=http://127.0.0.1:7890 all_proxy=socks5://127.0.0.1:7890
3、删除项目依赖包以及 yarn 缓存
rm -rf node_modules && yarn cache clean
4、重新装包
yarn install
5、清除 React-Native 缓存
rm -rf ~/.rncache
6、现在转到项目的 ios 文件夹(cd ios)的终端并运行
pod deintegrate && pod install
7、打开编辑器
打开编辑器,先执行一次模拟器编译,等项目跑起来后关闭模拟器。这一步是为了确保项目编译过一次。
我这边测试,如果不先执行一次的话,直接使用
yarn ios
还是会出现报错
8、打开终端
执行yarn ios
完美运行