Repository navigation
Conversation
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
marcprux
left a comment
There was a problem hiding this comment.
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 ?
I can't launch an emulator in UTM at all 😭 But I did verify that it creates an emulator. |
|
If you want to rebase this pull, you can get the enhancements to the CI ( 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: |
|
As I was deduplicating and integrating deeper with Skip, I had a different approach, implemented in #200 . Closing this in favor of that one. |
Fixes #187
Ensure we always pass
sdkmanagerandavdmanagera validJAVA_HOME, because the stock cmdline-tools don't include one, and fails outright if the/usr/bin/javaisn't set up. We're working aroundsdkmanagerdoesn't work after installing Skip homebrew-skip#1Our Homebrew cask installs the
openjdkformula, which does not symlink into/Library/Java/JavaVirtualMachines. So that'll work, but only if we passJAVA_HOMEevery time we want to usesdkmanageroravdmanager.Ensure that we have a valid
ANDROID_HOME(from the environment, or by guessing the path to Android Studio's SDK)Check to see if cmdline-tools are installed in
ANDROID_HOME; Android Studio doesn't install them by defaultIf cmdline-tools are not installed, we can "bootstrap" them by running any
sdkmanagerwe 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 inJAVA_HOME), to runsdkmanager --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 inANDROID_HOME.At that point, we have a known-good
sdkmanagerin ANDROID_HOME, which we can use to install platform-tools, the target Android platform, and the emulator.We ask
emulatorfor 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.)If there's no existing emulator with that name, we can finally create the emulator with a known-good
avdmanagerinANDROID_HOME'scmdline-tools.Skip Pull Request Checklist:
swift testI 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.