解决cocoapods下载hermes太慢的问题

1,713 阅读1分钟

执行pod install时,到installing hermes engine 直接卡住。

执行pod install --verbose 时,看到下载包的大小478M,但是下载速度高达 20kb/s

当时就难绷

以下是解决方案

  1. 打开node_modules/react-native/sdks/hermes-engine/hermes-utils.rb 文件查看下载路径或者执行pod install --verbose 看看输出的下载地址

我这里是这样的

def release_tarball_url(version, build_type)
    return "https://repo1.maven.org/maven2/com/facebook/react/react-native-artifacts/#{version}/react-native-artifacts-#{version}-hermes-ios-#{build_type.to_s}.tar.gz"
end

然后点击下载地址手动下载它,挂vpn比pod下载快太多

  1. 设置环境变量

同样的文件可以看到上方的代码

def compute_hermes_source(build_from_source, hermestag_file, git, version, build_type, react_native_path)
    source = {}

    if ENV.has_key?('HERMES_ENGINE_TARBALL_PATH')
        use_tarball(source)
    elsif build_from_source
        if File.exist?(hermestag_file)
            build_from_tagfile(source, git, hermestag_file)
        else
            build_hermes_from_source(source, git)
        end
    elsif hermes_artifact_exists(release_tarball_url(version, build_type))
        use_release_tarball(source, version, build_type)
    elsif hermes_artifact_exists(nightly_tarball_url(version).gsub("\\", ""))
        use_nightly_tarball(source, react_native_path, version)
    else
        build_hermes_from_source(source, git)
    end

    return source
end

def use_tarball(source)
    tarball_path = ENV['HERMES_ENGINE_TARBALL_PATH']
    putsIfPodPresent("[Hermes] Using pre-built Hermes binaries from local path: #{tarball_path}")
    source[:http] = "file://#{tarball_path}"
end

可以看到如果存在环境变量HERMES_ENGINE_TARBALL_PATH时,会直接使用环境变量指向的路径。 然后编辑~/.zpprofile文件添加环境变量

添加

  # export HERMES_ENGINE_TARBALL_PATH="/Users/xxx/Downloads/react-native-artifacts-0.72.2-hermes-ios-debug.tar.gz"

上面的路径需要你按照实际情况设置

然后重启终端,执行ENV,查看环境变量是否设置

执行pod install 就可以下载完成了