我有以下设置:
2021.3.1
根级build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
google()
maven { url 'https://jitpack.io' }
}
dependencies {
classpath 'com.android.tools.build:gradle:7.3.1'
classpath 'com.github.spotbugs:spotbugs-gradle-plugin:4.7.1'
}
}
allprojects {
repositories {
mavenCentral()
google()
maven { url 'https://jitpack.io' }
}
}模块级build.gradle:
import com.github.spotbugs.snom.SpotBugsTask
buildscript {
repositories {
mavenCentral()
google()
maven { url 'https://jitpack.io' }
}
}
plugins {
id 'com.android.library'
id 'checkstyle'
id 'com.github.spotbugs'
}
repositories {
mavenCentral()
google()
maven { url 'https://jitpack.io' }
}
apply from: "publisher.gradle"
<...>
dependencies {
implementation platform('com.google.firebase:firebase-bom:31.0.0')
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'androidx.preference:preference:1.2.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.mikepenz:materialdrawer:6.1.2'
implementation 'com.github.AppIntro:AppIntro:6.2.0'
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.google.firebase:firebase-crashlytics'
implementation 'com.google.firebase:firebase-database'
implementation 'com.github.sematext:sematext-logsene-android:3.2.0'
implementation 'com.github.mik3y:usb-serial-for-android:3.4.6'
}在Android中执行gradle同步时,我遇到了以下错误:

文本中的第一个错误:
:projectName:main: Could not resolve androidx.appcompat:appcompat:1.5.1.
Required by:
project :projectName
Possible solution:
- Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html正如您在上面看到的,我已经声明了包含这些依赖项的存储库,并且我确信这些版本是存在的。
我已经试过了:清除gradle缓存,清除Android缓存并重新启动,切换到另一个网络,关闭我的防火墙--没有任何帮助。我看到gradle已经成功地解决了完整列表中的一些依赖项(例如,物料抽屉和防火墙)。
一段时间前,一切都很顺利--从2-3个月以来,我还没有开过这个项目,而且它以前也一直在运行。现在不是了,我也不明白为什么。有人能帮帮我吗?
啊,顺便说一句,"gradle洁净“,然后"gradle build",它使用相同的依赖项,正在成功地完成构建,真正地组装在同一台笔记本上的Android Studio的同一个实例上,只有"gradle sync”失败了。这让我不太清楚到底发生了什么。
发布于 2022-10-21 12:50:31
在您的根级级别中,可以尝试添加
maven {
url = uri("https://plugins.gradle.org/m2/")
}所以概述
buildscript {
val kotlinVersion = "1.7.20"
repositories {
maven {
url = uri("https://plugins.gradle.org/m2/")
}
google()
mavenCentral()
}
dependencies {
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}注:我的等级是在kts格式,所以它可能是不同的,在你的一端。
https://stackoverflow.com/questions/74152365
复制相似问题