【问题标题】:Gradle project sync failed after Electric Eel | 2022.1.1 updateElectric Eel 后 Gradle 项目同步失败 | 2022.1.1更新
【发布时间】:2023-02-13 02:50:18
【问题描述】:

将我的 Android Studio 更新到最新版本后,即Electric Eel | 2022.1.1,我在创建新项目后得到了Gradle project sync failed

错误:

A problem occurred configuring root project 'BIAssignment'.
> Could not resolve all files for configuration ':classpath'.
   > Could not resolve com.android.tools.build:gradle:7.4.0.
     Required by:
         project : > com.android.application:com.android.application.gradle.plugin:7.4.0
         project : > com.android.library:com.android.library.gradle.plugin:7.4.0
      > No matching variant of com.android.tools.build:gradle:7.4.0 was found. The consumer was configured to find a runtime of a library compatible with Java 8, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '7.5' but:
          - Variant 'apiElements' capability com.android.tools.build:gradle:7.4.0 declares a library, packaged as a jar, and its dependencies declared externally:
              - Incompatible because this component declares an API of a component compatible with Java 11 and the consumer needed a runtime of a component compatible with Java 8
              - Other compatible attribute:
                  - Doesn't say anything about org.gradle.plugin.api-version (required '7.5')
          - Variant 'javadocElements' capability com.android.tools.build:gradle:7.4.0 declares a runtime of a component, and its dependencies declared externally:
              - Incompatible because this component declares documentation and the consumer needed a library
              - Other compatible attributes:
                  - Doesn't say anything about its target Java version (required compatibility with Java 8)
                  - Doesn't say anything about its elements (required them packaged as a jar)
                  - Doesn't say anything about org.gradle.plugin.api-version (required '7.5')
          - Variant 'runtimeElements' capability com.android.tools.build:gradle:7.4.0 declares a runtime of a library, packaged as a jar, and its dependencies declared externally:
              - Incompatible because this component declares a component compatible with Java 11 and the consumer needed a component compatible with Java 8
              - Other compatible attribute:
                  - Doesn't say anything about org.gradle.plugin.api-version (required '7.5')
          - Variant 'sourcesElements' capability com.android.tools.build:gradle:7.4.0 declares a runtime of a component, and its dependencies declared externally:
              - Incompatible because this component declares documentation and the consumer needed a library
              - Other compatible attributes:
                  - Doesn't say anything about its target Java version (required compatibility with Java 8)
                  - Doesn't say anything about its elements (required them packaged as a jar)
                  - Doesn't say anything about org.gradle.plugin.api-version (required '7.5')

我已经试过了使缓存失效和改变摇篮版本从项目结构,但他们都没有工作。我也试过禁用 flutter 插件,但这些方法都不起作用请帮我解决这个问题。

我目前的项目结构:

构建.gradle

plugins {
    id 'com.android.application' version '7.4.0' apply false
    id 'com.android.library' version '7.4.0' apply false
}

构建.gradle

plugins {
    id 'com.android.application'
}

android {
    namespace 'com.biassignment'
    compileSdk 33

    defaultConfig {
        applicationId "com.biassignment"
        minSdk 24
        targetSdk 33
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    buildFeatures {
        viewBinding true
    }
}

dependencies {
    implementation 'androidx.appcompat:appcompat:1.6.0'
    implementation 'com.google.android.material:material:1.7.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'androidx.navigation:navigation-fragment:2.5.3'
    implementation 'androidx.navigation:navigation-ui:2.5.3'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}

【问题讨论】:

    标签: android gradle


    【解决方案1】:

    我通过更改Android Gradle Plugin VersionGradle Version 解决了这个问题。

    文件 > 项目结构 > 项目

    我变了


    添加Fani评论: 将 Gradle JDK 更改为版本 11 也对我有用。

    1. 文件 > 设置 > 构建、执行、部署 > 构建工具 > Gradle。
    2. 将 Gradle JDK 更改为版本 11。

    【讨论】:

    • 奇怪的是,在缓存失效失败后,我将 Gradle 版本升级到 7.5,这自动需要 Android Gradle 插件版本 7.4.0,现在升级后它可以工作了。
    【解决方案2】:

    好的,因为我看到一切都是正确的,只需转到:

    项目结构 --> 模块 并将 Source $ Target 兼容性从“$JavaVersion.VERSION_1_8”更改为“$JavaVersion.VERSION_11”

    【讨论】:

    • 已经尝试过不工作。
    • 打开 android studio 底部的终端并运行:./gradlew --version
    • 告诉我你的 gradle 版本是 7.5 吗?
    • 也去文件 |设置 |构建、执行、部署 |构建工具 | Gradle 并检查“Gradle JDK”。它必须至少是 11。
    【解决方案3】:

    我遇到了同样的问题并应用了以下解决方案:

    我已将 Gradle JDK 更改为 11,问题已解决。

    【讨论】:

      【解决方案4】:

      升级Android Studio后我遇到了同样的问题。您可以按照“Studio 在升级后无法启动”部分的“Android Studio 已知问题”页面中的说明将 Android Studio 重置为其默认状态。

      重置 Android Studio 状态:https://developer.android.com/studio/known-issues#studio-config-directories

      注意:执行此操作时将删除所有第三方插件

      顺便说一句,更改 gradle 版本也对我有用 (this answer)。

      我以前从未回答过问题,如果我遗漏了什么请告诉我

      【讨论】:

        【解决方案5】:

        有同样的错误并升级到这些 Gradle 设置

        我还将 Gradle JDK 更改为:

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2018-09-05
          • 2022-11-11
          • 1970-01-01
          • 1970-01-01
          • 2019-01-22
          • 2015-06-10
          • 1970-01-01
          相关资源
          最近更新 更多