Android 默认的gradle地址 构建失败,如果是网络问题 可以使用 Android阿里镜像地址构建

构建方法很简单  替换google 的meaven  为阿里的。

1.删除 Android Studio 的代理设置

首先你需要确认你已经在 Settings -> Appearance&Behavior -> System Settings -> HTTP Proxy 中选中了 No Proxy。

然后找到项目根目录下的 gradle.properties 文件,打开查看该文件中是否有关于 proxy 设置(代理的地址和端口)的相关语句,删除这些内容,让该文件看起来大致是这个样子(如果你没有添加其他设置的话):

最后,你需要找到你的另一个 gradle.properties 文件:C:\Users\Administrator.gradle\gradle.properties:

打开该文件,和上面的操作一样,删除与 proxy 设置相关的语句,让该文件的内容看起来大致是这样(如果你没有添加其他设置的话):

2.让项目通过阿里云 maven jcenter 下载依赖资源

打开项目根目录下的 build.gradle(Project:项目名称一级的gradle),如下所示添加阿里 maven 库地址:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
 
buildscript {
    repositories {
 
        // 添加阿里云 maven 地址         
        maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
        maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' }
 
        // jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
 
allprojects {
    repositories {
 
        // 添加阿里云 maven 地址         
        maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
        maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' }
 
        // jcenter()
        google()
    }
}
 
task clean(type: Delete) {
    delete rootProject.buildDir
}

查询构建 

猜你喜欢

转载自blog.csdn.net/qq_36355271/article/details/101678018