Skip to content

skip android emulator launch fails on Linux unless you set $ANDROID_AVD_HOME #204

Description

@dfabulich

https://github.com/skiptools/skipstone/actions/runs/22827276828/job/66210543724#step:17:1117
avdmanager list avd is showing:

executing command: /usr/local/lib/android/sdk/cmdline-tools/latest/bin/avdmanager list avd
Available Android Virtual Devices:
    Name: emulator-34-medium_phone
  Device: medium_phone (Generic)
    Path: /home/runner/.config/.android/avd/emulator-34-medium_phone.avd
  Target: Google APIs (Google Inc.)
          Based on: Android 14.0 ("UpsideDownCake") Tag/ABI: google_apis/x86_64
  Sdcard: 512 MB

That's $HOME/.config/.android/avd, which is in the XDG_CONFIG_HOME under the XDG Base Directory Specification.

The problem is, the latest version of emulator doesn't actually check there! When you try to launch an unknown emulator, emulator says:

(Note: Directories are searched in the order $ANDROID_AVD_HOME, $ANDROID_SDK_HOME/avd and $HOME/.android/avd)

That feels like a bug in emulator; it should at least try to check the default directory that avdmanager uses.

It seems like Google sanitizes this by adding environment variables like these: https://android.googlesource.com/platform/tools/base/+/mirror-goog-studio-main/bazel/avd/emulator_launcher.sh.template#109

export ANDROID_USER_HOME=$HOME/.android
export ANDROID_EMULATOR_HOME=$ANDROID_USER_HOME
export ANDROID_AVD_HOME=$ANDROID_EMULATOR_HOME/avd

I believe that will make avdmanager and emulator agree on ~/.android as the AVD directory. (I think only ANDROID_AVD_HOME actually matters, but I'm not too sure about that.)

That raises questions about how/where we want to use that information.

  1. We could try to set ANDROID_AVD_HOME ourselves in AndroidCommand.swift (yielding to the user's environment if they've set it)
    1. We could set it to the XDG dir ~/.config/.android/avd. (Presumably we'd only do that on Linux…?)
    2. Or we could set it to ~/.android/avd (on all platforms…?)
  2. We could just set environment variables ourselves in ci.yml (and let end users do the same)

@marcprux Do you have any intuition on what would be best here?

Originally posted by @dfabulich in #203 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions