Azure Pipeline: No such file or directory
Docker image: Ubuntu 18.04 Language: Kotlin UI Test framework: Espresso
Hello!
I read the Medium article "Android UI Testing in Azure DevOps" to able my pipeline to run my Android UI Tests. But i'm having some troubles trying to start the emulator on pipeline. For some reason when i run the command with "$ANDROID_SDK_ROOT/emulator/emulator" or "$ANDROID_SDK_ROOT/platform-tools/adb " is returned "No such file or directory"
I put some logs in pipeline and as we can see on print, the folders "emulator" and "adb" exists and have the executable

The image was downloaded and cached successfully
Can you help me?
Here is my azure-pipeline file:
[...]
stages:
- stage: Build
displayName: Build
jobs:
- job:
displayName: Build
pool:
name: Default
steps:
- task: Gradle@2
displayName: 'gradlew build'
inputs:
gradleWrapperFile: 'obasos/gradlew'
tasks: 'ktlintCheck build sonarqube -D sonar.branch.name=$(Build.SourceBranchName)'
gradleOptions: '-Xmx3072m'
workingDirectory: obasos
- task: CacheBeta@0
displayName: 'Caching System Images for Emulator'
inputs:
key: 'AVD_IMAGE_30_86'
path: '$(ANDROID_SDK_ROOT)/system-images'
cacheHitVar: 'AVD_IMAGES_RESTORED'
continueOnError: true
condition: succeededOrFailed()
- bash: |
$ANDROID_SDK_ROOT/tools/bin/sdkmanager --list
displayName: 'Android installed packages'
condition: succeeded()
- bash: |
echo "y" | $ANDROID_SDK_ROOT/tools/bin/sdkmanager --install 'system-images;android-30;google_apis;x86'
displayName: 'Download and install Android Emulator Image'
condition: ne(variables.AVD_IMAGES_RESTORED, 'true')
- bash: |
echo "Available: $(ANDROID_SDK_ROOT/emulator/emulator -list-avds)"
echo "no" | $ANDROID_SDK_ROOT/tools/bin/avdmanager create avd -n android_emulator -k 'system-images;android-30;google_apis;x86' -d 17 --force
echo "$(ANDROID_SDK_ROOT/emulator/emulator -list-avds) are available"
echo "Emulator created"
displayName: 'Create Emulator'
condition: succeeded()
- bash: |
echo "Devices: $(ANDROID_SDK_ROOT/platform-tools/adb devices)"
nohup $ANDROID_SDK_ROOT/emulator/emulator -avd android_emulator -skin 1080x1920 -no-snapshot -no-audio -no-boot-anim -accel auto -gpu auto -qemu -lcd-density 420 > /dev/null 2>&1 &
displayName: 'Start Emulator'
condition: succeeded()
- bash: |
$ANDROID_SDK_ROOT/platform-tools/adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed | tr -d '\r') ]]; do sleep 1; done'
$ANDROID_SDK_ROOT/platform-tools/adb devices
echo "Emulator started"
displayName: 'Wait for Emulator'
condition: succeeded()
timeoutInMinutes: 5
- bash: |
./gradlew connectedDebugAndroidTest --console=plain --stacktrace
./gradlew --stop
displayName: 'Run Instrumented Tests'
continueOnError: true
- task: PublishTestResults@2
displayName: 'Publish Instrumented Test Results'
inputs:
testResultsFiles: '**/outputs/androidTest-results/**/TEST*.xml'
failTaskOnFailedTests: true
testRunTitle: 'Instrumented Test Results'
condition: succeededOrFailed()
[...]
When using a path that uses an environment variable, the first thing to check is that the environment variable actually exists. My local system doesn't have $ANDROID_SDK_ROOT. I use $ANDROID_HOME both locally and in my pipelines.
You can see that I use $ANDROID_HOME in my variables section and in my emulator-related steps.
If you want to see all your environment variables, you can do a PowerShell one-liner step in your yaml:
- pwsh: Get-ChildItem env:
(trailing colon is not a typo, try out Get-ChildItem env: on your own machine.)