无法解析 com.android.tools.build:gradle:8.2.2

问题描述 投票:0回答:1

我正在按照 https://learn.microsoft.com/en-us/azure/devops/pipelines/ecosystems/android?view=azure-devops

上的步骤操作

我已经创建了一个管道,请求增加 Azure DevOps 中的自由并行度(已获得批准),在我的本地计算机上创建了一个 Wear OS 应用程序,并尝试在管道中构建它。但是,管道失败并显示以下消息

Could not resolve all files for configuration ':classpath'.
   > Could not resolve com.android.tools.build:gradle:8.2.2.
     Required by:
         project : > com.android.application:com.android.application.gradle.plugin:8.2.2
      > No matching variant of com.android.tools.build:gradle:8.2.2 was found. The consumer was configured to find a library for use during runtime, compatible with Java 8, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '8.2' but:
          - Variant 'apiElements' capability com.android.tools.build:gradle:8.2.2 declares a library, packaged as a jar, and its dependencies declared externally:
              - Incompatible because this component declares a component for use during compile-time, compatible with Java 11 and the consumer needed a component for use during runtime, compatible with Java 8
              - Other compatible attribute:
                  - Doesn't say anything about org.gradle.plugin.api-version (required '8.2')
          - Variant 'javadocElements' capability com.android.tools.build:gradle:8.2.2 declares a component for use during runtime, 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 '8.2')
          - Variant 'runtimeElements' capability com.android.tools.build:gradle:8.2.2 declares a library for use during runtime, 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 '8.2')
          - Variant 'sourcesElements' capability com.android.tools.build:gradle:8.2.2 declares a component for use during runtime, 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 '8.2')

我的管道文件非常简单:

# Android
# Build your Android project with Gradle.
# Add steps that test, sign, and distribute the APK, save build artifacts, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/android

trigger:
- master

pool:
  vmImage: 'macos-latest'

steps:
- task: Gradle@2
  inputs:
    workingDirectory: ''
    gradleWrapperFile: 'gradlew'
    gradleOptions: '-Xmx3072m'
    publishJUnitResults: false
    testResultsFiles: '**/TEST-*.xml'
    tasks: 'assembleDebug'

除了降级我的项目 gradle 插件版本之外,您知道如何解决此问题吗?

android azure-devops android-gradle-plugin
1个回答
0
投票
  • 不兼容,因为该组件声明了一个在编译时使用的组件,与 Java 11 兼容,而消费者需要一个在运行时使用的组件,与 Java 8 兼容

根据错误消息,com.android.tools.build:gradle:8.2.2 需要 java 11 或更高版本。

我们可以在 Gradle@2 任务中设置参数:

jdkVersionOption: '1.17'

例如:

- task: Gradle@2
  inputs:
    workingDirectory: ''
    gradleWrapperFile: 'gradlew'
    gradleOptions: '-Xmx3072m'
    javaHomeOption: 'JDKVersion'
    jdkVersionOption: '1.17'
    jdkArchitectureOption: 'x64'
    publishJUnitResults: true
    testResultsFiles: '**/TEST-*.xml'
    tasks: 'assembleDebug'
  displayName: gradlew assembleDebug test

无法解析 com.android.tools.build:gradle:8.2.2。

根据旧的错误消息,似乎无法从项目中的资源集中找到gradle:8.2.2。

要解决此问题,您可以将

google()
添加到 build.gradle 文件中的存储库。

例如:

buildscript {
    repositories {
        jcenter()
        mavenCentral()
        google() 
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:8.2.2'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.