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

将Android项目接入Azure DevOps时Gradle构建报错:找不到gradlew

Android项目接入Azure DevOps构建报错:找不到gradlew文件

报错信息

Starting: Build APK
==============================================================================
Task         : Gradle
Description  : Build using a Gradle wrapper script
Version      : 2.219.0
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/build/gradle
==============================================================================
##[error]Error: Not found wrapperScript: /home/vsts/work/1/s/gradlew
Finishing: Build APK

当前使用的Azure Pipelines YAML配置

pool:
  vmImage: 'ubuntu-latest'

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

  - task: CopyFiles@2
    inputs:
      sourceFolder: '$(System.DefaultWorkingDirectory)'
      contents: '**/*.apk'
      targetFolder: '$(build.artifactStagingDirectory)'
    displayName: 'Copy APK files to artifact staging directory'

  - task: PublishBuildArtifacts@1
    inputs:
      pathtoPublish: '$(build.artifactStagingDirectory)'
      artifactName: 'drop'
      publishLocation: 'Container'
    displayName: 'Publish artifacts'

问题背景

已将Gradle wrapper脚本(gradlew、gradlew.bat)从.gitignore中移除并推送到Git仓库,但构建仍报错。仓库结构显示gradlew文件位于MyApp子目录下。

解决方案

1. 修正YAML中gradleWrapperFile的路径

报错核心原因是构建代理在仓库根目录(/home/vsts/work/1/s/)寻找gradlew,但实际文件存放在MyApp子目录下。需将gradleWrapperFile的路径修改为相对于仓库根目录的完整路径:

- task: Gradle@2
  inputs:
    workingDirectory: 'MyApp'
    gradleWrapperFile: 'MyApp/gradlew'  # 修正为实际文件路径
    gradleOptions: '-Xmx3072m'
    javaHomeOption: 'JDKVersion'
    jdkVersionOption: '1.8'
    jdkArchitectureOption: 'x64'
    publishJUnitResults: true
    testResultsFiles: '**/TEST-*.xml'
    tasks: 'assembleDebug'
  displayName: 'Build APK'

2. 确认提交完整的Gradle wrapper文件

Gradle wrapper正常运行需要全套文件支撑,需确保以下文件都已提交到仓库:

  • gradlew(Linux/macOS执行脚本)
  • gradlew.bat(Windows执行脚本)
  • gradle/wrapper/gradle-wrapper.jar
  • gradle/wrapper/gradle-wrapper.properties

若之前仅提交了脚本文件,需将gradle/wrapper目录下的两个核心文件从.gitignore移除并推送到仓库。

内容的提问来源于stack exchange,提问作者Antoni Zwolski

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.16 17:32:36