M1芯片Mac安装react-native-image-crop-picker时Pod安装失败求助
解决react-native-image-crop-picker安装时Pod无法克隆GitHub仓库的问题
我需要实现多图选择功能,因此选用并安装了react-native-image-crop-picker库,但执行npx pod-install或在iOS目录下运行pod install时,出现以下错误:
[!] Error installing TOCropViewController [!] /usr/bin/git clone https://github.com/TimOliver/TOCropViewController.git /var/folders/dh/mnrtx44j2813tnj3kj_rngvw0000gn/T/d20231114-5160-frh25m --template= --single-branch --depth 1 --branch 2.6.1 Cloning into '/var/folders/dh/mnrtx44j2813tnj3kj_rngvw0000gn/T/d20231114-5160-frh25m'... fatal: unable to access 'https://github.com/TimOliver/TOCropViewController.git/': Failed to connect to github.com port 443 after 75029 ms: Couldn't connect to server Couldn't install Pods. Updating the Pods project and trying again... Command `pod install` failed. └─ Cause: Error installing TOCropViewController [!] /usr/bin/git clone https://github.com/TimOliver/TOCropViewController.git /var/folders/dh/mnrtx44j2813tnj3kj_rngvw0000gn/T/d20231114-5160-frh25m --template= --single-branch --depth 1 --branch 2.6.1 Cloning into '/var/folders/dh/mnrtx44j2813tnj3kj_rngvw0000gn/T/d20231114-5160-frh25m'... fatal: unable to access 'https://github.com/TimOliver/TOCropViewController.git/': Failed to connect to github.com port 443 after 75029 ms: Couldn't connect to server
我尝试了pod install和npx pod-install两种方式均失败,推测是网络代理相关问题导致无法访问GitHub,以下是可行的解决方案:
配置Git代理
如果你的环境需要通过代理访问GitHub,给Git设置全局代理:# 设置HTTP代理 git config --global http.proxy http://[代理地址]:[端口] # 设置HTTPS代理 git config --global https.proxy https://[代理地址]:[端口]若不需要代理或之前配置过错误代理,可清空代理:
git config --global --unset http.proxy git config --global --unset https.proxy给CocoaPods配置代理环境变量
在终端中临时设置代理环境变量,让CocoaPods走代理:export HTTP_PROXY=http://[代理地址]:[端口] export HTTPS_PROXY=https://[代理地址]:[端口]设置完成后重新执行
pod install或npx pod-install手动引入本地依赖
若代理方案无效,可手动克隆依赖仓库到本地,再修改Podfile指定本地路径:- 克隆指定版本的TOCropViewController仓库:
git clone https://github.com/TimOliver/TOCropViewController.git --branch 2.6.1 - 在iOS目录的Podfile中,找到
react-native-image-crop-picker的依赖配置,替换为本地路径:pod 'TOCropViewController', :path => '/[本地仓库的绝对路径]' - 重新执行
pod install
- 克隆指定版本的TOCropViewController仓库:
切换Git克隆协议为SSH
修改Git全局配置,让GitHub仓库克隆默认使用SSH协议,避免HTTPS连接问题:git config --global url."git@github.com:".insteadOf "https://github.com/"确保你已配置好GitHub的SSH密钥,之后再执行
pod install
内容的提问来源于stack exchange,提问作者JackHan
相关产品推荐
相关产品推荐

