gpt4 book ai didi

android - Azure DevOps 管道 android build设置 sdk 位置

转载 作者:行者123 更新时间:2023-12-03 06:28:22 24 4
gpt4 key购买 nike

我正在尝试使用 yaml 管道构建一个 android 应用程序。 gradle build 任务提示它找不到android sdk root。我已经尝试了 local.properties 文件和环境变量 ANDROID_SDK_ROOT,但都不起作用。这是我的构建管道:

# 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
- dev

pool:
name: 'Default'

steps:

- task: UseDotNet@2
inputs:
version: '2.2.x'
packageType: runtime

- task: GitVersion@5
displayName: GitVersion
inputs:
useConfigFile: true
configFilePath: GitVersion.yml

# trying to set the env variable doesn't work.
# - task: PowerShell@2
# inputs:
# targetType: 'inline'
# script: |
# # Write your PowerShell commands here.

# [Environment]::SetEnvironmentVariable("ANDROID_SDK_ROOT", "C:\Users\Administrator\AppData\Local\Android\Sdk", "User")

- task: file-creator@6
inputs:
filepath: '$(System.DefaultWorkingDirectory)/local.properties'
filecontent: 'sdk.dir=C:/Users/Administrator/AppData/Local/Android/Sdk'
fileoverwrite: true

# trying to execute gradlew manually does not work
# - task: CmdLine@2
# inputs:
# script: |
# gradlew.bat assembleDebug
# workingDirectory: '$(System.DefaultWorkingDirectory)'

- task: Gradle@2
inputs:
workingDirectory: '$(System.DefaultWorkingDirectory)'
gradleWrapperFile: 'gradlew'
gradleOptions: '-Xmx3072m'
publishJUnitResults: false
testResultsFiles: '**/TEST-*.xml'
tasks: 'assembleDebug'
这是输出:
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/build/gradle
==============================================================================
SYSTEMVSSCONNECTION exists true
C:\Windows\system32\cmd.exe /D /S /C "C:\VSTS\_work\8\s\gradlew.bat -p C:\VSTS\_work\8\s assembleDebug"
Starting a Gradle Daemon, 1 incompatible and 4 stopped Daemons could not be reused, use --status for details

> Configure project :app
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> SDK location not found. Define location with an ANDROID_SDK_ROOT environment variable or by setting the sdk.dir path in your project's local properties file at 'C:\VSTS\_work\8\s\local.properties'.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 16s
Error: The process 'C:\VSTS\_work\8\s\gradlew.bat' failed with exit code 1
at ExecState._setResult (C:\VSTS\_work\_tasks\Gradle_8d8eebd8-2b94-4c97-85af-839254cc6da4\2.176.0\node_modules\azure-pipelines-task-lib\toolrunner.js:816:25)
at ExecState.CheckComplete (C:\VSTS\_work\_tasks\Gradle_8d8eebd8-2b94-4c97-85af-839254cc6da4\2.176.0\node_modules\azure-pipelines-task-lib\toolrunner.js:799:18)
at ChildProcess.<anonymous> (C:\VSTS\_work\_tasks\Gradle_8d8eebd8-2b94-4c97-85af-839254cc6da4\2.176.0\node_modules\azure-pipelines-task-lib\toolrunner.js:721:19)
at emitTwo (events.js:106:13)
at ChildProcess.emit (events.js:191:7)
at maybeClose (internal/child_process.js:920:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:230:5)
##[error]Error: The process 'C:\VSTS\_work\8\s\gradlew.bat' failed with exit code 1
Finishing: Gradle
如果我 rdp 进入构建代理并使用命令行中生成的 local.properties 文件手动运行 gradlew ,那么构建确实会成功,所以我不确定在管道中运行它的问题是什么。

最佳答案

您可以通过在 Variables 中定义来设置 azure 管道中的环境变量。部分。您可以将以下内容添加到您的 yaml 管道中。

variables:
ANDROID_SDK_ROOT: 'C:\Users\Administrator\AppData\Local\Android\Sdk'
您还可以使用 task.setvariable 设置环境变量 ANDROID_SDK_ROOT the scripts 中的日志记录命令.对于下面的例子。
steps:

- powershell: echo "##vso[task.setvariable variable=ANDROID_SDK_ROOT]C:\Users\Administrator\AppData\Local\Android\Sdk"

关于android - Azure DevOps 管道 android build设置 sdk 位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64305136/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com