新疆项目时Gradle project sync failed
很多刚接触AS的小白在官网下载Android studio3.6后就在网上找安装教程,然后一步步跟着教程安装,但是当安装完成后却发现新建项目无法成功构建,也无法在模拟器中生成项目,其实问题很容易解决。
大概报错提示都是如下
Could not GET 'https://xxxxx/xxxxx.jar
或者
Could not GET 'https://xxxxx/xxxxx.pom
提示你无法下载某些包,为什么呢?
因为你没有梯子,这些包默认是从外网下载,国内网络很难翻过去。
解决这类问题最佳做法当然是找梯子, 除此之外,国内还有一些镜像地址可以使用。
那么问题就来了,新手刚接触Android studio不知道VPN也不知道什么是镜像源,在刚开始很难找到这类解决方法,因为不懂怎么去检索这类问题。
解决方法:换镜像源
首先打开你的Android studio,找到build.gradle(Project:XXX)
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
这是原先的代码,把它改成如下代码再sync一下就可以了。
buildscript {
repositories {
google()
maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
以上采用的是阿里云的镜像源,本人使用时还是比较稳定的。
接下来就是sync,也可以在File里找到sync
一开始sync可能有点慢,需要耐心等待几分钟。
那么你终于可以满怀欣喜地运行程序与你的Hello World见面了。