[异常] flutter CDN: trunk URL couldn’t be downloaded

Android Studio 启动 Flutter 项目,使用 iOS 设备,cocoapods 安装插件时,又报错了。

flutter CDN: trunk URL couldn't be downloaded: https://cdn.jsdelivr.net/cocoa/

我怎么感觉每次在 iPhone 上运行项目都会碰到问题,而且都与 cocoapods 有关。

[异常] Error installing cocoapods,Failed to build gem native extension

[异常] Invalid Podfile file: undefined method `exists?’ for File:Class

像这种没法下载依赖或者架包,大多数与国内阉割网络有关。

先在 Android Studio 的终端下,运行命令,查看 CocoaPods 的仓库源。最好进入 ios 目录下运行以下命令。

pod repo list 

如果没意外,你的仓库有一个 Cocoapods trunk CDN 源。但这个 CDN 仓库源下载失败,说明这个源我们用不了。这里添加我们能使用的。

# 官方 CocoaPods 源
pod repo add cocoapods https://github.com/CocoaPods/Specs.git

# 清华大学镜像源
pod repo add tsinghua https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git

上面添加源的命令执行后,需要一点时间。接下来再看仓库里的源。

pod repo list 

不出意外,这里会显示三个仓库,名字分别是trunkcocoapodstsinghua

到这里,其实默认的仓库源地址可以删掉了,不删也行,问题不大。

pod repo remove trunk

现在我们在项目里 /ios/Podfile,配置使用的仓库源地址。

# Uncomment this line to define a global platform for your project
# platform :ios, '11.0'
source 'https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git'
......

我这里使用 tsinghua 的仓库源,所以如上配置,如果你想用 cocoapods ,使用如下

source 'https://github.com/CocoaPods/Specs.git'

再下载安装看看。

pod install

OK,我这边可以了。

本文由老郭种树原创,转载请注明:https://guozh.net/trunk-url-couldnt-be-downloaded/

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注