[ableimage]Android studio 3.6新建项目时Gradle project sync failed

新疆项目时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见面了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值