Canvas 作为著名的开源学习系统,云集了众多开发者为其贡献代码和设计思路,当然也少不了智能手机 App,包括 iOS 和 Android 两个平台。
下面我们详细了解下编译 iOS 版本的过程和可能遇到的问题。
问题一:node 路径问题
Can't find the 'node' binary to build the React Native bundle. If you have a non-standard Node.js installation, select your project in Xcode, find 'Build Phases' - 'Bundle React Native code and images' and change NODE_BINARY to an absolute path to your node executable. You can find it by invoking 'which node' in the terminal.
![](https://cdn.tonylabs.com/media/cms/article/2022-07/6fd5f825-463f-494d-98ed-6586b6c9b151.jpg)
通过查看错误日志,不难发现是关于node 路径报错,具体解决方法如下:
![](https://cdn.tonylabs.com/media/cms/article/2022-07/7b3a5728-c64f-4a14-9a8f-8ef03e4d4814.jpg)
打开 Terminal 工具,输入 which node 查看 node 程序所在路径,如下图:
![](https://cdn.tonylabs.com/media/cms/article/2022-07/ac0a21eb-8328-47b4-b4a4-a915a8541c84.jpg)
得到 node 路径后,再次回到 Xcode,打开 Build Phases 面板,找到 Bundle React Native Code And Images,将原本的 NODE_BINARY 路径修改为 /opt/homebrew/opt/node@16/bin/node,如下图:
![](https://cdn.tonylabs.com/media/cms/article/2022-07/c59ba6a2-5f50-49b1-a48c-d5eee28ad092.jpg)
最后,再次编译 App。
问题二:编译成功后,运行即崩溃:
多次尝试后,发现 Copy only when installing 不可勾选。
![](https://cdn.tonylabs.com/media/cms/article/2022-09/2cdcedac-aa46-463f-9466-a47794cc9eae.png)
问题二:CocoaPods update iphoneos cannot be located 路径问题
![](https://cdn.tonylabs.com/media/cms/article/2022-11/84ff4200-e07f-4af1-8e9a-840c656fe196.png)
首先通过 xcrun -k --sdk iphoneos --show-sdk-path
自测,如返回:
xcrun: error: SDK "iphoneos" cannot be located
继续执行 xcode-select --print-path 查看当前 Xcode 路径,通常返回:
/Applications/Xcode.app/Contents/Developer
如果不是上述路径,执行:
xcode-select --switch /Applications/Xcode.app/Contents/Developer/
修改后,再次运行 pod install
或 pod update