android studio gradle插件无法下载,Could not GET xxx, Received status code 400 from server: Bad Request

解决在Android项目gradle build时,总是报错Could not GET xxx, Received status code 400 from server: Bad Request的问题

在安卓项目编译的时候,gradle-xx-all.zip配置好了,还是不行,发现还是在去网络上下载东西,其实这时候下载的是gradle的编译插件,也就是build.gradle里的这个东西:

buildscript {
    repositories {
//        maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' }
        jcenter()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }![这里写图片描述](https://img-blog.csdn.net/20180911213647486?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2xxeF9zdW5oYW4=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70)
    }
    dependencies {
    // 就是这个东西
        classpath 'com.android.tools.build:gradle:2.3.4'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

gradle和gradle插件是不同的概念,下面是对应关系:
这里写图片描述
所以这个插件会根据你配置在build.gradle中的maven url去远程下载,这里的本地缓存目录在用户目录/.gradle/caches/modules-2/files-2.1/.

重点是我们发现就算配置里阿里云的地址也下载不了,直接报400的错,而且在我们复制下载地址去网页访问发现都是正常的。找半天原因后发现是代理问题。你需要进去你的gradle缓存目录,一般也就是用户目录/.gradle/gradle.properties,把其中配置的所有代理都注释掉就ok了。

#systemProp.https.proxyPort=80
#systemProp.http.proxyHost=mirrors.neusoft.edu.cn
#systemProp.https.proxyHost=mirrors.neusoft.edu.cn
#systemProp.http.proxyPort=80

还有问题可以加群:

这里写图片描述

猜你喜欢

转载自blog.csdn.net/lqx_sunhan/article/details/82633275