Skip to content

Android emulator system image picker - #2843

Open
moondial-pal wants to merge 38 commits into
beeware:mainfrom
moondial-pal:android-sys-img-picker
Open

moondial-pal wants to merge 38 commits into
beeware:mainfrom
moondial-pal:android-sys-img-picker

Conversation

@moondial-pal

@moondial-pal moondial-pal commented May 19, 2026 •

Copy link
Copy Markdown
Contributor

Added two step selection flow that fetches all available compatible images from sdkmanager --list.
Hard coded version is set if default is selected.

This enables the user to select an android version when creating a new emulator.

Fixes #737

PR Checklist:

  • I will abide by the BeeWare Code of Conduct
  • I have read and have followed the CONTRIBUTING.md file
  • This PR was generated or assisted using an AI tool

Assisted-by: Claude Sonnet 4.6

@moondial-pal

Copy link
Copy Markdown
Contributor Author

The approach was revised during the PyCon sprint after a discussion with @mhsmith.
Am going to work on aligning tests and see if I can nail this down.

@moondial-pal

Copy link
Copy Markdown
Contributor Author

Are the 3 CI failures pre-existing or am I goofing something here?

  • docs-lint broken https://www.x.org/ link in x11passthrough.md, not touched by my PR
  • Windows ARM PySide6 build, similar failure visible in recent main branch CI runs
  • ReadTheDocs appears to be an infrastructure build failure?

I checked recent CI runs on main and found some of these issues crop up there.
I'm not sure how to get them to pass at this point 😅

@moondial-pal
moondial-pal marked this pull request as ready for review May 23, 2026 16:36
@mhsmith

mhsmith commented May 25, 2026

Copy link
Copy Markdown
Member

Yes, the failures aren't related to this PR, so you don't need to worry about them.

Thanks for the updates, I'll look at this in a couple of days.

@mhsmith
mhsmith self-requested a review May 25, 2026 13:40
for line in output.splitlines():
package = line.split("|")[0].strip()
if not package.startswith("system-images"):
continue

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.

The code above this point could be replaced with a call to list_installed_system_images.

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.

Sorry, not replaced exactly, but the duplicate code should be factored out.

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.

The duplication with list_installed_system_images is still unresolved.

@moondial-pal

Copy link
Copy Markdown
Contributor Author

Thanks for the detailed feedback. I'll work through each point.
The suggestion to factor out the parsing logic and treat versions independently makes a lot of sense. I'll get back to you with updates.

@moondial-pal

moondial-pal commented Jun 18, 2026 •

Copy link
Copy Markdown
Contributor Author

Digging into the API level sorting here is the current state of the API level selection wizard for feedback:

image

I had some questions before going any further.

  1. android-CANARY and android-CinnamonBun have no numeric component, so currently they sort to the bottom of the list alphabetically rather than near a numeric position.
    CinnamonBun is the codename for the 37 preview.
    CANARY is a rolling pre-release with no fixed API level.
    How would we want to sort those?

  2. android-37.0 and android-CinnamonBun both appear to refer to the same underlying release.
    Should these be de-duplicated or is showing both acceptable?

  3. The API level prompt currently defaults to 31.
    Do we want to stick with that or have the wizard default to the latest?

That brings up another question that may be out of scope for this pr but how do we want to handle default API level selection as the years progress?

@mhsmith

mhsmith commented Jun 18, 2026

Copy link
Copy Markdown
Member
  1. android-CANARY and android-CinnamonBun have no numeric component, so currently they sort to the bottom of the list alphabetically rather than near a numeric position.
    CinnamonBun is the codename for the 37 preview.
    CANARY is a rolling pre-release with no fixed API level.
    How would we want to sort those?

The bottom of the list looks fine to me, since they are the newest versions.

  1. android-37.0 and android-CinnamonBun both appear to refer to the same underlying release.
    Should these be de-duplicated or is showing both acceptable?

If they have separate SDK packages, then let's show them separately. At some point, I think the package with the codename will disappear, but existing emulators should continue to work.

  1. The API level prompt currently defaults to 31.
    Do we want to stick with that or have the wizard default to the latest?

That brings up another question that may be out of scope for this pr but how do we want to handle default API level selection as the years progress?

The ideal solution is probably to make it default to target_os_version. But you don't have to do that in this PR unless you want to; sticking with the current default is fine.

@moondial-pal

Copy link
Copy Markdown
Contributor Author

Sounds good on all three.
Keeping current sort order for numeric and named entries.
The default will remain android-31 for now, will tackle target_os_version in a separate PR.

@moondial-pal

Copy link
Copy Markdown
Contributor Author

Still working on this. I have been on a camping/road trip for the past 9 days and won't return until 7/6/26 😅. I should be able to submit something that week.

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

Sorry for taking so long. This is looking pretty good now, just a few more comments, plus one unresolved conversation from the previous round.

@moondial-pal

Copy link
Copy Markdown
Contributor Author

Sorry for taking so long. This is looking pretty good now, just a few more comments, plus one unresolved conversation from the previous round.

Not an issue at all, I know this issue has been a bit drawn out.
I'll work on the feedback, thanks.

@mhsmith mhsmith mentioned this pull request Sep 7, 2026
2 of 3 tasks
@moondial-pal

Copy link
Copy Markdown
Contributor Author

Apologies for the delayed submission.
@mhsmith this is ready for further review.

@freakboy3742

Copy link
Copy Markdown
Member

@moondial-pal Looks like you've hit a pre-commit problem...

@mhsmith

mhsmith commented Sep 8, 2026 •

Copy link
Copy Markdown
Member

Since this PR was last merged from the main branch, we've started more strictly enforcing line length limits (#2979).

You'll also have to resolve some merge conflicts with #3033, which added the API level to the default emulator name.

@mhsmith mhsmith changed the title Android sys img picker Android emulator system image picker Sep 19, 2026
# Conflicts:
#	src/briefcase/integrations/android_sdk.py
#	tests/integrations/android_sdk/AndroidSDK/test_create_emulator.py
@moondial-pal

Copy link
Copy Markdown
Contributor Author

Dropping a not that I am working on the fixes. Should have something submitted for review soon.

@mhsmith

mhsmith commented Oct 10, 2026

Copy link
Copy Markdown
Member

Thanks, and FYI, we're planning a Briefcase release on Tuesday, so if you can update the PR by Monday, I'll make sure to merge it in time for that. No problem if it takes longer, though.

@moondial-pal

Copy link
Copy Markdown
Contributor Author

Finally got something submitted, ready for review.

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

Thanks - I've taken this for a spin, and it worked well; but I think there's some tweaks needed in the specific workflow to make it more useful for common use cases. Details inline.

def _parse_system_image(package: str):
"""Parse a system image package identifier into its components.

:param package: e.g. ``"system-images;android-31;default;x86_64"``

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.

Markdown only requires a single backtick.

Suggested change
:param package: e.g. ``"system-images;android-31;default;x86_64"``
:param package: e.g. `"system-images;android-31;default;x86_64"`

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.

Fixed.

"""Sort key for API level strings, ordering numeric levels (and their ext suffixes)
numerically. Non-numeric levels sort after all numeric ones.

e.g. "android-34" -> (0, 34.0, 0) "android-34-ext9" -> (0, 34.0, 9)

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.

packaging.Version is a better representation here than a Float.

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.

Specifically, float will work fine for any of the existing versions, but it will break if the minor version ever gets into 2 digits, because 34.10 would be equal to 34.1.

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.

packaging.Version is overkill for this; replaced with a tuple of ints.


# TODO: Provide a list of options for system images.
system_image = self.DEFAULT_SYSTEM_IMAGE
# Get available images, raise an error if none found.

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.

These questions need to come before we select an emulator name - otherwise the user will select beePhone-31 as their image name, and then select an SDK 34 image.

This likely also means modifying the DEFAULT_AVD property so it's more of a "generate a good base AVD for this set of device properties" method (which, for now, is just the API level - but it could be modified in future to take the device type into account, once we add skin selection)

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.

Fixed.

# TODO: Provide a list of options for system images.
system_image = self.DEFAULT_SYSTEM_IMAGE
# Get available images, raise an error if none found.
available_images = self.list_available_system_images(

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 query takes a bit of time, which makes it look like nothing is happening. We should wrap this in a transient wait_bar so the user knows what is happening while they wait.

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.

Done.

default=(
self.DEFAULT_IMAGE_TYPE
if self.DEFAULT_IMAGE_TYPE in image_types
else image_types[0]

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.

I think it would be better to present "no default", rather than pick one at random. In my testing, I tried using "android-36.1", and it defaulted to "android-wear-signed" as the image type, which won't be a good match.

@mhsmith mhsmith Nov 12, 2026 •

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.

I think a better preference order would be:

  • default
  • google_apis – comes with some closed-source Google apps.
  • google_apis_ps16k – same as google_apis but uses 16 KB pages. This and the corresponding playstore image are the only ones available on the very newest API levels.
  • If none of those are available, then no default. This doesn't happen for any API level that currently exists, but it can be covered by the unit tests.

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.

Done.

# Parse available images once for use in both selection questions.
parsed_images = [_parse_system_image(img) for img in available_images]

# Ask the user to select an API level.

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 approach works, but I think it might need some refinement to be most useful, especially to non-expert users.

At present, by default, the user is faced with 34 options for android SDK, many of which are highly esoteric - e.g., "android-36-ext15". This is entirely correct, but not especially helpful for a non-expert user. Even though there's a good default, 35 options is a little overwhelming; and if you accept the default, you're then faced with the image type question, which I'm not sure even I fully understand :-)

My suggestion would be:

  1. Show an initial list of images that have been filtered to a "provides a default system image type", and also provide a "non-default image types" menu option. This means the user will see "android-24, android-25,... android-37.0, non-default system images" as their list of options - 15 total, and a very "vanilla" list .
  2. If they select one of the images, use it in a "default" image type configuration.
  3. If they select "non-default image types":
    1. show a sorted list of image types that are available - google_apis, google_apis_playstore, aosp_atd, ...
    2. Show a list of API levels that are filtered to that image type

That should make the solve 90% of use cases with an approachable list, while still providing flexibility for the remainder of uses.

Does that make sense?

@mhsmith mhsmith Nov 12, 2026 •

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.

Since #3033 a default device is automatically created and used unless the -d argument is passed, so anyone who gets into this menu is already asking for somewhat advanced behavior.

However, I agree that it's a bit overwhelming, and too easy for the user to get stuck, e.g. if they pick android-34-ext9, then their only image type option will be android-automotive, which is unlikely to be useful.

As I mentioned in my previous comment, I suspect Google is in the process of phasing out default, so we can't privilege it too much. Instead, how about only showing the "vanilla" versions, i.e. those whose name is a dotted sequence of numbers with no additional text? This is roughly what the Android Studio emulator creation dialog does by default. Anyone who really needs one of the other versions should be expert enough to create the emulator themselves outside of Briefcase. I've never needed any of them myself.

In that case, we would keep the image type question, but give it a more intelligent default as in my previous 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.

Done.

@mhsmith

mhsmith commented Nov 23, 2026

Copy link
Copy Markdown
Member

Fixed all outstanding comments, but not ready to merge yet because emulators with dots in their version all fail to boot.

@mhsmith

mhsmith commented Nov 23, 2026

Copy link
Copy Markdown
Member

emulators with dots in their version all fail to boot

As usual, they didn't give any useful error messages whatsoever, but I eventually worked out that we needed to update the command-line tools.


### Android SDK

If you have an existing install of the Android SDK, it will be used by Briefcase if the `ANDROID_HOME` environment variable is set. If `ANDROID_HOME` is not present in the environment, Briefcase will honor the deprecated `ANDROID_SDK_ROOT` environment variable. Additionally, an existing SDK install must have version 19.0 of Command-line Tools installed; this version can be installed in the SDK Manager in Android Studio.

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.

Briefcase installs the required Command-line Tools version automatically, just like it does all other SDK packages. So I've replaced the specific version with a more general statement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve flexibility of Android emulator system image

3 participants