gpt4 book ai didi

android - Gradle 同步失败,出现 "Could not resolve dependency"错误

转载 作者:行者123 更新时间:2023-12-05 05:32:23 24 4
gpt4 key购买 nike

我有以下设置:

  • 安卓工作室 2021.3.1
  • 等级:7.4

根级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 Studio 中执行 gradle sync 时,我遇到了以下错误: Dependency failure

文本中的第一个错误:

: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 Studio 缓存并重新启动、切换到另一个网络、关闭我的防火墙—​​—没有任何帮助。我看到 gradle 已经成功地解决了完整列表中的一些依赖项(例如,materialdrawer 和 firebase)。

前段时间一切正常 - 我已经 2-3 个月没有打开该项目了,它之前一直在工作。现在不是了,我不明白为什么。有人可以帮助我吗?

啊,顺便说一下,使用相同依赖项的“gradle clean”和“gradle build”成功完成,真正组装构建,在同一台笔记本电脑上的相同 Android Studio 实例上,只有“gradle同步”失败。这让我真的不清楚发生了什么。

最佳答案

在您的根级别 gradle 中,也许尝试添加

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
}
}

注意:我的 Gradle 是 kts 格式,因此您的格式可能有所不同。

关于android - Gradle 同步失败,出现 "Could not resolve dependency"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74152365/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com