Andriod Studio配置问题:run是灰色的,编译报错 Could not resolve com.android.tools.build:gradle:3.5.2.

Andriod Stdio run是灰色的,编译报错
Could not resolve com.android.tools.build:gradle:3.5.2.

问题现象

在工具栏的run箭头提示的是灰色的,没有办法添加模拟器,然后编译也是错误的提示有问题。
编译报错

问题分析

1. 检查你的as是不是可以连接外网

点击 File -> sync ProJect with Gradel File 看看编译情况,如果编译很慢,或者提示下载失败,这个可能是你的源设置的不对。

编译位置

配置gradel的源

注意左上角,编辑的是Project
这里建议这里采用ali源,在文件 gradel -> build.gradel 中配置如下

// 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/public' }
        maven { url 'https://maven.aliyun.com/repository/google' }
        maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
        mavenLocal()
        mavenCentral()
        google()
       // jcenter()
        maven { url "https://jitpack.io" }
        jcenter(){url "http://jcenter.bintray.com/"}
    }
    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/public' }
        maven { url 'https://maven.aliyun.com/repository/google' }
        maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
        mavenLocal()
        mavenCentral()  
        google()
        //jcenter()
        maven { url "https://jitpack.io" }
        jcenter(){url "http://jcenter.bintray.com/"}
        
    }
}

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

文件位置
配置完后,若发现还是错误检查是否是你的代理有问题

关闭代理

在 file->setting->Appearance &Behavior ->System Setting中关闭代理,点击OK
关闭代理
现在还不一定生效,点击左上角,把左边的浏览窗口切成 Andriod 然后你可以看见 Gradel Script
点开文件 Gradel Script 下面的 gradel.properties 看到下面的文件依然有配置代理。
全部注释
注释位置
再次点击
File -> sync ProJect with Gradel File
这次编译是成功了。如果你右边的箭头还不是绿色的,但是能编译了,那可能是你没有添加虚拟机。点击Edit Config 去添加一个配置,点击 AVD-Manager(那个手机小图标)添加虚拟机,这里配置不来可以再看看其他博客,工程能编译过了,后面就轻松很多了。
最终配置
这个版本是我2021年1月30日下的andriod Stdio 可能不同版本,后期配置会有些不同
我使用的是 : Project settings: Gradle model version=5.4.1
这里有些问题,其他的大佬说的确是属于版本bug,也不怪自己配置错误。


  • 10
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值