大家的问题应该都属于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'}
这两行代码加到文件中即可。