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

Make skip android emulator create much more robust - #194

Closed
dfabulich wants to merge 1 commit into
skiptools:mainfrom
dfabulich:android-emulator-fixes
Closed

dfabulich wants to merge 1 commit into
skiptools:mainfrom
dfabulich:android-emulator-fixes

Conversation

@dfabulich

@dfabulich dfabulich commented Feb 28, 2026 •

Copy link
Copy Markdown
Member

Fixes #187

  1. Ensure we always pass sdkmanager and avdmanager a valid JAVA_HOME, because the stock cmdline-tools don't include one, and fails outright if the /usr/bin/java isn't set up. We're working around sdkmanager doesn't work after installing Skip homebrew-skip#1

    Our Homebrew cask installs the openjdk formula, which does not symlink into /Library/Java/JavaVirtualMachines. So that'll work, but only if we pass JAVA_HOME every time we want to use sdkmanager or avdmanager.

  2. Ensure that we have a valid ANDROID_HOME (from the environment, or by guessing the path to Android Studio's SDK)

  3. Check to see if cmdline-tools are installed in ANDROID_HOME; Android Studio doesn't install them by default

  4. 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 (passing in JAVA_HOME), 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.

  5. At that point, we have a known-good sdkmanager in ANDROID_HOME, which we can use to install platform-tools, the target Android platform, and the emulator.

  6. 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.)

  7. 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.

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.

I had Cursor generate the scaffolding for the tests and the implementation, but then I pretty much rewrote the whole thing by hand. 🤪 Having all of the tests gives me a lot of confidence that this code is robust.


1. Ensure we always pass `sdkmanager` and `avdmanager` a valid `JAVA_HOME`, because the stock cmdline-tools don't include one, and fails outright if the `/usr/bin/java` isn't set up.
    Our Homebrew cask installs the `openjdk` formula, which does _not_ symlink into `/Library/Java/JavaVirtualMachines`. So that'll work, but only if we pass `JAVA_HOME` every time we want to use `sdkmanager` or `avdmanager`.
2. Ensure that we have a valid `ANDROID_HOME` (from the environment, or by guessing the path to Android Studio's SDK)
3. Check to see if cmdline-tools are installed in `ANDROID_HOME`; Android Studio doesn't install them by default
4. 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 (passing in `JAVA_HOME`), 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`.
5. At that point, we have a known-good `sdkmanager` in ANDROID_HOME, which we can use to install platform-tools, the target Android platform, and the emulator.
6. 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.)
7. 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
@cla-bot cla-bot Bot added the cla-signed label Feb 28, 2026

@marcprux marcprux left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking good overall! It mostly just needs to cleanup and de-duplication of logic.

Have you tested locally in a clean UTM image to see if this creates and launches the emulator ?

@dfabulich

Copy link
Copy Markdown
Member Author

Have you tested locally in a clean UTM image to see if this creates and launches the emulator ?

I can't launch an emulator in UTM at all 😭 But I did verify that it creates an emulator.

@marcprux

marcprux commented Mar 1, 2026

Copy link
Copy Markdown
Member

If you want to rebase this pull, you can get the enhancements to the CI (.github/workflows/ci.yml‎) from #199 and try out your enhancements by un-disabling the skip android emulator … commands to see if it works against a fresh build.

It isn't quite the same as a clean UTM-installed image, but once we get it working, we can try running the commands after manually purging the GH runner's pre-installed tools, e.g. with:

rm -r ${JAVA_HOME}
export JAVA_HOME=
rm -r ${ANDROID_HOME}
export ANDROID_HOME=

skip android emulator create
skip android emulator launch --background

@dfabulich

Copy link
Copy Markdown
Member Author

As I was deduplicating and integrating deeper with Skip, I had a different approach, implemented in #200 . Closing this in favor of that one.

@dfabulich dfabulich closed this Mar 2, 2026
@dfabulich dfabulich mentioned this pull request Mar 2, 2026
2 of 5 tasks
@marcprux marcprux mentioned this pull request Mar 16, 2026
5 tasks done
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.

skip android emulator create fails on fresh install

2 participants