Android Studio无法下载annotation.jar

问题遇到的现象和发生背景

根据《第一行代码 第2版》编写BroadcastPractice时,出现如下报错:

ERROR: Unable to resolve dependency for ':app@debug/compileClasspath': Could not download annotation.jar (androidx.annotation:annotation:1.0.2)
Show Details
Affected Modules: app


ERROR: Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not download annotation.jar (androidx.annotation:annotation:1.0.2)
Show Details
Affected Modules: app


ERROR: Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not download annotation.jar (androidx.annotation:annotation:1.0.2)
Show Details
Affected Modules: app


app图标显示叉号(app配置有问题)

操作环境、软件版本等信息

软件:Android Studio 3.5

尝试过的解决方法

尝试更改过依赖为 implementation 'androidx.appcompat:appcompat:+',更换网络,换成国内源等方法,一直出现同样的报错。

我想要达到的结果

无报错即可。

img

修改gradle script下的build.gradle文件为以下内容

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

buildscript {
    repositories {
        maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'}

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

        maven{ url 'https://maven.aliyun.com/repository/gradle-plugin'}

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

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

        jcenter()
        //google()

    }
    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 'http://maven.aliyun.com/nexus/content/groups/public/'}
        google()
        jcenter()

    }
}

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


```

1.1.0,1.2.0,1.3.0换个版本试一试
你的整体版本都比较老了,建议都升级到最新版。最近网络屏蔽的厉害,很多外网都无法访问,有条件的可以翻一翻,没条件的试一试阿里云的仓库。