AndroidStudio build gradle报错

大家的问题应该都属于gradle下载不上的情况

卡到红色标记的位置就走不动了

解决办法

选择build.gradle(项目级gradle),将原来的google()、 jcenter()替换成阿里的仓库即可。
在这里插入图片描述

注意不要使用过时的仓库

过时的仓库源
网上许多的仓库源已经过时,阿里的仓库地址已经更换,所以需要访问阿里仓库 https://maven.aliyun.com/进行查找仓库源,避免网址更换带来的问题。
阿里仓库
将仓库地址复制到build.gradle文件即可

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

buildscript {
    repositories {
        maven{ url 'https://maven.aliyun.com/repository/google'}
        maven{ url 'https://maven.aliyun.com/repository/jcenter'}
//        google()
//        jcenter()
        
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.2'
        
        // 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/repository/google'}
        maven{ url 'https://maven.aliyun.com/repository/jcenter'}
//        google()
//        jcenter()
        
    }
}

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

写到最后

如果不想每次创建新项目都更换仓库源可以更改你AndroidStudio安装目录下的文件,我使用的计算机AndroidStudio安装在D盘。所以我们到达
D:\AndroidStudio\plugins\android\lib\templates\gradle-projects\NewAndroidProject\root
目录下用任意编辑器编辑build.gradle.ftl文件,把

maven{ url 'https://maven.aliyun.com/repository/google'}
maven{ url 'https://maven.aliyun.com/repository/jcenter'}

这两行代码加到文件中即可。
在这里插入图片描述
在这里插入图片描述

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值