Android Studio3.5在编译项目出现连接不上gradle该怎么办?

------------恢复内容开始------------

报错原因:

Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.5.3/gradle-3.5.3.pom'

网上说的解决方法都无效,增加了SS代理也无


折腾了一会儿,好像可以了。

  1. 把项目中的build.gradle中google()和jcenter()注释掉,换成阿里云的就可以了。
  2. 将Android Studio中所有的代理全部取消
  3. 另外将~/.gradle/gradle.properties中关于代理的内容全部注释掉。

build.gradle内容改为如下:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        //google()
        //jcenter()
        maven { url 'https://maven.aliyun.com/nexus/content/repositories/google' }
        maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/' }
        maven{ url 'http://maven.aliyun.com/nexus/content/repositories/jcenter'}
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.3'
        
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        maven { url 'https://maven.aliyun.com/nexus/content/repositories/google' }
        maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/' }
        maven{ url 'http://maven.aliyun.com/nexus/content/repositories/jcenter'}
        //google()
        //jcenter()
        
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

------------恢复内容结束------------

上一篇:gradle错误 解决办法 (汇总 不定期更新)


下一篇:【build.gradle】 buildScript块、allprojects块、根级别三种所属的repositories区别