skiptools / skiptools/skipstone

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

Open
#204 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Swift
Stars
106
Forks
20
Avg merge
2d 3h
Merged PRs (30d)
9

Description

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 https://github.com/skiptools/skipstone/issues/203#issuecomment-4019933308

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with AndroidCommand.swift and ci.yml, then compare the avdmanager and emulator search paths shown in the issue. Determine where the environment should be configured and how user-provided ANDROID_AVD_HOME should be handled. Done means the Android emulator launches on Linux without manual configuration and the chosen CI or command behavior is covered.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, linux, swift
Domain
ci-cd, mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.