目录
项目场景:
react native 项目,版本:0.76.6
react版本 18.3.1
macOS版本:15.4
Xcode版本 16.3
开发方式,借助expo。
问题描述
开发环境下,启动iOS模拟器出错:
首先是通过npx expo start启动iOS的时候,显示没有安装:
CommandError: No development build (xxx) for this project is installed. Please make and install a development build on the device first.
Learn more: https://docs.expo.dev/development/build/
其次,执行pnpm run ios,出错:
Run script build phase '[CP-User] [RN]Check rncore' will be run during every build because it does not specify any outputs. To address this issue, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'React-Fabric' from project 'Pods') Run script build phase '[CP-User] [RN]Check rncore' will be run during every build because it does not specify any outputs. To address this issue, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'React-FabricComponents' from project 'Pods') Run script build phase '[CP-User] Generate updates resources for expo-updates' will be run during every build because it does not specify any outputs. To address this issue, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'EXUpdates' from project 'Pods') Run script build phase '[CP-User] [Hermes] Replace Hermes for the right configuration, if needed' will be run during every build because it does not specify any outputs. To address this issue, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'hermes-engine' from project 'Pods')
› 2 error(s), and 4 warning(s)
CommandError: Failed to build iOS project. "xcodebuild" exited with error code 65.
查找网上的解决方案,有的显示是缓存的问题,有的是显示是路径的命名问题,不能有空格,还有是Xcode识别多个相同名称的项目导致的问题(不清楚具体是什么原因)……
以上我都进行了排查,还是解决不了,于是从自身入手,开始细细排查。
原因分析:
大概猜测是:缓存、代码问题、环境问题。
1.清除缓存
watchman watch-del-all
rm -rf ios/build
rm -rf ios/Pods
rm -rf ios/Podfile.lock
rm -rf node_modules
rm -rf .expo
rm -rf .expo-shared
pnpm install
cd ios && pod install && cd ..
pnpx expo prebuild --clean
pnpm run ios:production
无用,我甚至重新安装了pod,依旧无效。
2.代码问题
排除,我的旧电脑是完全OK的,新电脑与旧电脑就是macOS版本不同,从13.x升级到了15.4,相应地Xcode也升级到了16.3。所以考虑是环境问题。
3.环境问题
电脑的环境
我是更换了电脑,于是第一时间考虑这个问题。
构建工具的环境问题很有可能,毕竟是新电脑,我可能环境哪里没有配置好,于是重新检查各种工具的版本与安装位置,没有排查出问题。并且我查看了Xcode的证书,签名等等,因为是根据Apple ID自动设置的,所以原则上没有问题。
并且,我尝试了卸载Xcode,下载了15版本与14版本的,不能安装……(可以想办法安装的,但是没有心力继续下去了),于是重新安装Xcode,好在之前下载的模拟器等等还在。
项目的依赖冲突
因为还是电脑的环境变了,所以考虑可能Xcode升级导致的依赖解析的问题(我也不知道会不会有这方面的问题,就大胆猜测了),于是问了ai能不能饶过这些冲突——失败,最后老老实实地仔细去定位问题:
打开Xcode,进行build,失败,定位失败问题:
发给了ai工具,
一大段,看不懂,于是问ai会不会是版本的问题。
AI给出的方案是升级rn或者降级xcode。
最后我仔细看了终端,prebuild的时候有一个警告:
Using current versions instead of recommended react-native@0.76.9.
✔ Updated package.json | no changes
✔ Finished prebuild,
于是升级!
修改版本,删除依赖,重新prebuild,重新run ios,听到熟悉的风扇声!
我当时觉得大概就成了,于是真的成了!
呜呜呜!成功!
一个版本问题,我花费了两天的时间,断断续续地去花时间去看,有很多时间都是在解决环境与缓存,最终还是版本的问题。不过我也终于,解决了困扰我两天的错误!!