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

Azure Pipeline构建Android项目遇Bash错误代码1问题求助

问题分析与解决

你的Azure Pipeline构建报错是因为脚本步骤中的两个关键错误:

错误点1:变量名大小写不匹配

任务名定义为localProperties(驼峰格式),但脚本中写成了小写的$(localproperties.secureFilePath),导致变量无法正确解析,路径无效。

错误点2:ln命令逻辑完全错误

你试图将/etc/ssl/certs/链接到local.properties的路径,这完全不符合需求——Gradle需要的是在项目根目录存在local.properties文件,而不是创建SSL证书的链接。同时ln命令的参数顺序也写反了(正确顺序是ln -s 源文件 目标路径)。

修正后的YAML脚本

将原有的script步骤替换为以下内容,把下载的local.properties复制到项目根目录:

- script: |
    echo Copying local.properties to project root...
    cp $(localProperties.secureFilePath) $(Build.SourcesDirectory)/local.properties

完整修正后的Pipeline YAML

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

trigger:
- dev_pooja

pool:
  vmImage: 'macos-latest'

steps:

- task: DownloadSecureFile@1
  name: localProperties
  displayName: 'Download Local Properties file'
  inputs:
    secureFile: 'local.properties'

- script: |
    echo Copying local.properties to project root...
    cp $(localProperties.secureFilePath) $(Build.SourcesDirectory)/local.properties

- 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'

- task: CopyFiles@2
  inputs:
    contents: "**/*.apk"
    targetFolder: "$(build.artifactsStagingDirectory)"

- task: PublishBuildArtifacts@1

额外说明

  • $(Build.SourcesDirectory)是Azure Pipeline的内置变量,指向代码仓库的克隆目录,也就是项目根目录。
  • 不需要修改文件权限,下载的secure文件默认权限足够Gradle读取。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.18 04:45:36