从错误日志可以看到,Gradle 只在以下位置搜索:
但没有搜索 Google 仓库! 这就是问题所在。
在项目根目录的 build.gradle 中:
allprojects {
repositories {
google() // 必须在前面!
mavenCentral()
maven { url 'https://maven.aliyun.com/repository/public' }
}
}
或者如果使用 settings.gradle (较新的 Gradle 版本):
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google() // 必须包含!
mavenCentral()
maven { url 'https://maven.aliyun.com/repository/public' }
}
}
allprojects {
repositories {
maven { url 'https://maven.aliyun.com/repository/google' } // Google 镜像
maven { url 'https://maven.aliyun.com/repository/central' } // Central 镜像
google() // 备用
mavenCentral() // 备用
}
}
# 删除这类可能干扰仓库访问的设置
# android.enableR8.fullMode=true
./gradlew clean --refresh-dependencies
./gradlew build
手动验证该版本确实存在:Google 仓库
implementation 'androidx.appcompat:appcompat:1.7.0'
// 或
implementation 'androidx.appcompat:appcompat:1.6.1'