Reputation: 8222
I am trying to build an android app using a yaml pipeline. The gradle build task is complaining that it can't find the android sdk root. I've tried both the local.properties file and the environmental variable ANDROID_SDK_ROOT, and neither work. This is my build pipeline:
# 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:
- 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'
This is the output:
Help : https://learn.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
If I rdp into the build agent and run gradlew manually with the generated local.properties file present from the command line the build DOES succeed though, so I'm not sure what the issue with running it in a pipeline is.
Upvotes: 0
Views: 3891
Reputation: 8222
I figured out the issue. I installed the android sdk on the administrator account, but devops created a separate windows user for builds. Installing the android sdk for that user fixed my build.
Upvotes: 0
Reputation: 30313
You can set environmental variables in azure pipeline by defining it in the Variables section. You can add below to your yaml pipeline.
variables:
ANDROID_SDK_ROOT: 'C:\Users\Administrator\AppData\Local\Android\Sdk'
You can also set the environmental variable ANDROID_SDK_ROOT using the task.setvariable
logging command in the scripts. For below example.
steps:
- powershell: echo "##vso[task.setvariable variable=ANDROID_SDK_ROOT]C:\Users\Administrator\AppData\Local\Android\Sdk"
Upvotes: 1