Skip to content
This repository was archived by the owner on Nov 10, 2026. It is now read-only.

Fix Ubuntu CI - #203

Closed
dfabulich wants to merge 11 commits into
skiptools:mainfrom
dfabulich:android-home-install-ubuntu
Closed

dfabulich wants to merge 11 commits into
skiptools:mainfrom
dfabulich:android-home-install-ubuntu

Conversation

@dfabulich

Copy link
Copy Markdown
Member

This PR is based on #200, attempting to fix Ubuntu CI.

Skip Pull Request Checklist:

  • REQUIRED: I have signed the Contributor Agreement
  • REQUIRED: I have tested my change locally with swift test
  • OPTIONAL: I have tested my change on an iOS simulator or device
  • OPTIONAL: I have tested my change on an Android emulator or device

  • AI was used to generate or assist with generating this PR. Please specify below how you used AI to help you, and what steps you have taken to manually verify the changes.

This command will ensure that cmdline-tools is installed in `$ANDROID_HOME`, which will be `~/Library/Android/sdk` on macOS by default. This works with or without Android Studio installed, creating the directory if it doesn't exist yet.

If cmdline-tools are not installed, we can "bootstrap" them by running _any_ `sdkmanager` we can find. Our Homebrew cask installs `android-commandlinetools`, which installs its own Android SDK (probably _not_ the one the user wants to use). We can use that to run `sdkmanager --sdk_root=$ANDROID_HOME "cmdline-tools;latest"` to install the command line tools into Android Studio's SDK; then we can use the cmdline-tools in `$ANDROID_HOME`.
1. We now use the new `ensureCmdlineTools` function from `skip android home install`
2. We ask `emulator` for the list of AVDs, skipping creating the AVD if it already exists. (Despite the claim of `--force`, in my experiments, I found that it wasn't able to overwrite an existing AVD, e.g. to change the system_image.)
3. If there's no existing emulator with that name, we can finally create the emulator with a known-good `avdmanager` in `ANDROID_HOME`'s `cmdline-tools`.

Fixes skiptools#187
1. If the user passes no name, we use `emulator -list-avds` to list the AVDs
2. If there happens to be exactly one AVD, we launch that one.
3. If there aren't any AVDs, we fail with a clear error message that we couldn't detect any emulators, inviting the user to run `skip android emulator create`.
4. If there are multiple AVDs, but one of them happens to be the exact name of the emulator that would have been created by `skip android emulator create` if you pass _that_ no arguments, then we launch that one.
5. Otherwise, there are multiple AVDs, but none of them exactly match the name of the `skip android emulator create` AVD, and we just give a clear error message explaining that.

Fixes skiptools#189 and skiptools#202
@cla-bot cla-bot Bot added the cla-signed label Mar 8, 2026
@dfabulich dfabulich mentioned this pull request Mar 8, 2026
2 of 5 tasks
@dfabulich
dfabulich force-pushed the android-home-install-ubuntu branch 3 times, most recently from 4759620 to ef8b33c Compare March 8, 2026 07:28
@dfabulich
dfabulich force-pushed the android-home-install-ubuntu branch from ef8b33c to bf2946d Compare March 8, 2026 08:17
@dfabulich
dfabulich force-pushed the android-home-install-ubuntu branch from 7cbfa19 to 3277223 Compare March 8, 2026 17:51
@dfabulich

Copy link
Copy Markdown
Member Author

I think I've figured it out!

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?

@marcprux

marcprux commented Mar 8, 2026

Copy link
Copy Markdown
Member

So avdmanager is installing in XDG_CONFIG_HOME, but emulator is not checking there, and is instead just always hardcoding ~/.android/avd? That does seem like a bug.

It sounds like reactivecircus has contended with this ReactiveCircus/android-emulator-runner#197 (comment) and ReactiveCircus/android-emulator-runner#405. I'm not sure if their approach is correct, but I'm also not sure what is correct. But I think that it would be OK if we just replicate what they are doing.

At this stage, we mostly just care about this command working well on CI (since I doubt any actual users are using Skip on Linux, at least until we can get app building working), so I don't mind not handling every conceivable user/environment variant (as opposed of macOS, where we do expect end users to be relying on these commands).

So how about we have the launch command set the ANDROID_AVD_HOME environment if 1. it isn't already set, and 2. we detect that XDG_CONFIG_HOME is set AND that there is one or more emulator installed in the XDG_CONFIG_HOME-relative path?

@dfabulich

Copy link
Copy Markdown
Member Author

I'm going to be pretty busy this week, so I think for now I'm just going to add the necessary environment variables in PR #200. I've separately filed #204, which we could fix whenever we want.

And, for now, I'm going to close out this PR (which was really just to diagnose the Ubuntu build failures).

@dfabulich dfabulich closed this Mar 8, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants