You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure DevOps构建Wear OS应用报错:无法解析com.android.tools.build:gradle:8.2.2

问题描述

按照官方Android流水线文档操作,已创建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插件版本,还有什么解决办法?

解决办法

核心问题是Azure DevOps流水线默认使用的Java 8与Gradle 8.2.2要求的Java 11不兼容,以下是无需降级的解决方案:

1. 在流水线中指定Java 11环境

修改流水线文件,添加JavaToolInstaller任务强制切换到Java 11,macos-latest镜像预装了该版本,直接调用即可:

trigger:
- master

pool:
  vmImage: 'macos-latest'

steps:
# 添加Java 11环境配置任务
- task: JavaToolInstaller@0
  inputs:
    versionSpec: '11'
    jdkArchitectureOption: 'x64'
    jdkSourceOption: 'PreInstalled'

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

2. 确认项目Gradle Wrapper版本匹配

Gradle 8.2.2对应的Gradle Wrapper版本应为8.2,检查项目根目录下gradle/wrapper/gradle-wrapper.properties中的distributionUrl是否正确:

distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip

若本地已配置正确,流水线会自动下载对应版本,无需额外操作。

3. 统一项目Java版本配置

在项目的gradle.properties中添加以下配置,确保Gradle运行时使用Java 11(推荐配合流水线环境配置,避免本地与构建环境不一致):

org.gradle.java.home=/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home

内容的提问来源于stack exchange,提问作者iMan Biglari

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.30 21:34:53