首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >“无法解决依赖”错误导致同步失败

“无法解决依赖”错误导致同步失败
EN

Stack Overflow用户
提问于 2022-10-21 10:36:14
回答 1查看 183关注 0票数 3

我有以下设置:

2021.3.1

  • gradle: 7.4
  • Android Studio

根级build.gradle:

代码语言:javascript
运行
复制
// 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:

代码语言:javascript
运行
复制
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同步时,我遇到了以下错误:

文本中的第一个错误:

代码语言:javascript
运行
复制
: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”失败了。这让我不太清楚到底发生了什么。

EN

Stack Overflow用户

发布于 2022-10-21 12:50:31

在您的根级级别中,可以尝试添加

代码语言:javascript
运行
复制
maven {
  url = uri("https://plugins.gradle.org/m2/")
}

所以概述

代码语言:javascript
运行
复制
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格式,所以它可能是不同的,在你的一端。

票数 1
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74152365

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档