强制Gradle使用HTTP而不是HTTPS

强制Gradle使用HTTP而不是HTTPS

本文介绍了强制Gradle使用HTTP而不是HTTPS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建react-native android应用程序,作为依赖我看到我有gradle,但无法加载构建。
错误消息:

  *出错:
配置根项目'MobileApp'时出现问题。
>无法解析配置':classpath'的所有依赖关系。
>无法解析com.android.tools.build:gradle:1.3.1。
要求:
:MobileApp:未指定
>无法解析com.android.tools.build:gradle:1.3.1。
>无法获取资源'https://jcenter.bintray.com/com/android/tools/build/gradle/1.3.1/gradle-1.3.1.pom'。
>无法GET'https://jcenter.bintray.com/com/android/tools/build/gradle/1.3.1/gradle-1.3.1.pom'。
>连接到https://jcenter.bintray.com拒绝

问题很明显,我坐在后面企业代理可以阻止任何类似HTTPS连接的错误。
所以我的问题是:如何强制gradle使用HTTP来加载这些文件?这些属性应放在哪里(gradle文件,即gradle.properties中的哪一个)?

我已经在gradle属性文件中设置了这些:

  systemProp.http.proxyHost = myHost 
systemProp.http.proxyPort = myPort
systemProp.http.proxyUser = myUser
systemProp.http.proxyPassword = myPassword

任何链接,建议等都会有很大的帮助。

解决方案

我遇到同样的问题并修复了它。



gradle被迫通过https代理从jcenter获得依赖关系。



如果添加

  maven {urlhttp://jcenter.bintray.com} 

,而不是 jcenter(),gradle将此存储库视为一个带有http代理的简单Maven存储库。



您的项目 build.gradle 应如下所示:

<$ p $
仓库{
仓库{
maven {urlhttp://jcenter.bintray.com}
}
依赖关系{
classpath'com.android.tools.build:gradle:1.3.1'
}
}

allprojects {
repositories {
maven {url http://jcenter.bintray.com}
}
}


I am trying to build react-native android app, as a dependecy I see I have gradle, but it fails to load on build.Error message:

* What went wrong:
A problem occurred configuring root project 'MobileApp'.
> Could not resolve all dependencies for configuration ':classpath'.
   > Could not resolve com.android.tools.build:gradle:1.3.1.
     Required by:
         :MobileApp:unspecified
      > Could not resolve com.android.tools.build:gradle:1.3.1.
         > Could not get resource 'https://jcenter.bintray.com/com/android/tools/build/gradle/1.3.1/gradle-1.3.1.pom'.
            > Could not GET 'https://jcenter.bintray.com/com/android/tools/build/gradle/1.3.1/gradle-1.3.1.pom'.
               > Connection to https://jcenter.bintray.com refused

The issue is clear, I am sitting behind corporate proxy that blocks any HTTPSconnections like these in error.So my questions are: how to force gradle to use HTTP in loading these files? Where these properties should be put(which of gradle files, i.e. gradle.properties)?

P.S. I already have set these in gradle properties file:

systemProp.http.proxyHost= myHost
systemProp.http.proxyPort= myPort
systemProp.http.proxyUser= myUser
systemProp.http.proxyPassword= myPassword

Any links, suggestions or etc. will help a lot.

解决方案

I had same problem and fixed it.

gradle is forced to get dependencies from jcenter through https proxy.

if you add

maven { url "http://jcenter.bintray.com" }

in your repositories instead of jcenter(), gradle sees this repository as a simple maven repository with http proxy.

your project build.gradle should be like below:

buildscript {
    repositories {
        maven { url "http://jcenter.bintray.com" }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.1'
    }
}

allprojects {
    repositories {
        maven { url "http://jcenter.bintray.com" }
    }
}

这篇关于强制Gradle使用HTTP而不是HTTPS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 15:28