Skip to content

Commit

Permalink
Merge pull request #1519 from rmartin16/android-emulator-aarch64
Browse files Browse the repository at this point in the history
Support downloading Android emulator system image on Linux aarch64
  • Loading branch information
freakboy3742 authored Nov 1, 2023
2 parents ccd1c7c + 0b10614 commit 8e41297
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 18 deletions.
1 change: 1 addition & 0 deletions changes/1519.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
It is now possible to create an Android emulator AVD on Linux for arm64.
28 changes: 19 additions & 9 deletions src/briefcase/integrations/android_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,25 @@ def env(self) -> dict[str, str]:
@property
def emulator_abi(self) -> str:
"""The ABI to use for the Android emulator."""
if self.tools.host_arch == "arm64" and self.tools.host_os == "Darwin":
return "arm64-v8a"
if self.tools.host_arch in ("x86_64", "AMD64"):
return "x86_64"

raise BriefcaseCommandError(
"The Android emulator does not currently support "
f"{self.tools.host_os} {self.tools.host_arch} hardware."
)
try:
return {
"Linux": {
"x86_64": "x86_64",
"aarch64": "arm64-v8a",
},
"Darwin": {
"x86_64": "x86_64",
"arm64": "arm64-v8a",
},
"Windows": {
"AMD64": "x86_64",
},
}[self.tools.host_os][self.tools.host_arch]
except KeyError:
raise BriefcaseCommandError(
"The Android emulator does not currently support "
f"{self.tools.host_os} {self.tools.host_arch} hardware."
)

@property
def DEFAULT_DEVICE_TYPE(self) -> str:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ def android_sdk(android_sdk) -> AndroidSDK:
[
("Darwin", "x86_64", "x86_64"),
("Darwin", "arm64", "arm64-v8a"),
("Windows", "x86_64", "x86_64"),
("Windows", "AMD64", "x86_64"),
("Linux", "x86_64", "x86_64"),
("Linux", "aarch64", "arm64-v8a"),
],
)
def test_create_emulator(
Expand Down Expand Up @@ -117,8 +118,9 @@ def test_create_emulator(
[
("Darwin", "x86_64", "x86_64"),
("Darwin", "arm64", "arm64-v8a"),
("Windows", "x86_64", "x86_64"),
("Windows", "AMD64", "x86_64"),
("Linux", "x86_64", "x86_64"),
("Linux", "aarch64", "arm64-v8a"),
],
)
def test_create_emulator_with_defaults(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ def android_sdk(android_sdk) -> AndroidSDK:
[
("Darwin", "x86_64", "x86_64"),
("Darwin", "arm64", "arm64-v8a"),
("Windows", "x86_64", "x86_64"),
("Windows", "AMD64", "x86_64"),
("Linux", "x86_64", "x86_64"),
("Linux", "aarch64", "arm64-v8a"),
],
)
def test_create_emulator(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ def test_managed_install(mock_tools, android_sdk):
[
("Darwin", "x86_64", "x86_64"),
("Darwin", "arm64", "arm64-v8a"),
("Windows", "x86_64", "x86_64"),
("Windows", "AMD64", "x86_64"),
("Linux", "x86_64", "x86_64"),
("Linux", "aarch64", "arm64-v8a"),
],
)
def test_emulator_abi(mock_tools, android_sdk, host_os, host_arch, emulator_abi):
Expand Down
1 change: 1 addition & 0 deletions tests/integrations/android_sdk/AndroidSDK/test_verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ def test_unsupported_arch(mock_tools):
("Darwin", "arm64"),
("Darwin", "x86_64"),
("Linux", "x86_64"),
("Linux", "aarch64"),
("Windows", "AMD64"),
],
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import platform
from subprocess import CalledProcessError

import pytest
Expand All @@ -10,7 +11,7 @@
"host_os, host_arch",
[
("Windows", "arm64"),
("Linux", "arm64"),
("Linux", "armv7l"),
],
)
def test_unsupported_abi(mock_tools, android_sdk, host_os, host_arch):
Expand Down Expand Up @@ -56,7 +57,7 @@ def test_incompatible_abi(mock_tools, android_sdk, capsys):
"""If the system image doesn't match the emulator ABI, warn the user, but
continue."""
# Mock the host arch
mock_tools.host_arch = "x86_64"
mock_tools.host_arch = "AMD64" if platform.system() == "Windows" else "x86_64"

# Verify a system image that doesn't match the host architecture
android_sdk.verify_system_image("system-images;android-31;default;anything")
Expand All @@ -79,7 +80,7 @@ def test_incompatible_abi(mock_tools, android_sdk, capsys):
def test_existing_system_image(mock_tools, android_sdk):
"""If the system image already exists, don't attempt to download it again."""
# Mock the host arch
mock_tools.host_arch = "x86_64"
mock_tools.host_arch = "AMD64" if platform.system() == "Windows" else "x86_64"

# Mock the existence of a system image
(
Expand All @@ -96,7 +97,7 @@ def test_existing_system_image(mock_tools, android_sdk):
def test_new_system_image(mock_tools, android_sdk):
"""If the system image doesn't exist locally, it will be installed."""
# Mock the host arch
mock_tools.host_arch = "x86_64"
mock_tools.host_arch = "AMD64" if platform.system() == "Windows" else "x86_64"

# Verify the system image, triggering a download
android_sdk.verify_system_image("system-images;android-31;default;x86_64")
Expand All @@ -116,7 +117,7 @@ def test_new_system_image(mock_tools, android_sdk):
def test_problem_downloading_system_image(mock_tools, android_sdk):
"""If there is a failure downloading the system image, an error is raised."""
# Mock the host arch
mock_tools.host_arch = "x86_64"
mock_tools.host_arch = "AMD64" if platform.system() == "Windows" else "x86_64"

# Mock a failure condition on subprocess.run
mock_tools.subprocess.run.side_effect = CalledProcessError(
Expand Down

0 comments on commit 8e41297

Please sign in to comment.