Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android build on ARM Mac without Rosetta gives error "Bad CPU type in executable" #1000

Closed
mhsmith opened this issue Dec 12, 2022 · 2 comments · Fixed by #1007
Closed

Android build on ARM Mac without Rosetta gives error "Bad CPU type in executable" #1000

mhsmith opened this issue Dec 12, 2022 · 2 comments · Fixed by #1007
Labels
android The issue relates to Android mobile support. bug A crash or error in behavior. macOS The issue relates to Apple macOS support.

Comments

@mhsmith
Copy link
Member

mhsmith commented Dec 12, 2022

Describe the bug

Briefcase installs an x86 version of Java, because there's no ARM build available for Java 8 (see #827 for why we're still on that version). But the x86 build won't run unless Rosetta is installed.

Steps to reproduce

On an ARM Mac which doesn't have Rosetta, follow the Android section of the BeeWare tutorial.

Expected behavior

Build succeeds.

Screenshots

No response

Environment

  • Operating System: macOS 12.6
  • Python version: 3.11
  • Software versions:
    • Briefcase: 0.3.11

Logs

% briefcase create android

[java] The Java JDK was not found; downloading and installing...
Downloading OpenJDK8U-jdk_x64_mac_hotspot_8u242b08.tar.gz...
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100.0% • 00:17
Installing AdoptOpenJDK... done

[android_sdk] The Android SDK was not found; downloading and installing...
Downloading commandlinetools-mac-8092744_latest.zip...
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100.0% • 00:20
Installing Android SDK Command-Line Tools... done

The Android tools provided by Google have license terms that you must accept
before you may use those tools.
/Users/msmith/Library/Caches/org.beeware.briefcase/tools/android_sdk/cmdline-tools/latest/bin/sdkmanager: line 172: /Users/msmith/Library/Caches/org.beeware.briefcase/tools/java/Contents/Home/bin/java: Bad CPU type in executable
/Users/msmith/Library/Caches/org.beeware.briefcase/tools/android_sdk/cmdline-tools/latest/bin/sdkmanager: line 172: /Users/msmith/Library/Caches/org.beeware.briefcase/tools/java/Contents/Home/bin/java: Undefined error: 0

Error while reviewing Android SDK licenses. Please run this command and examine
its output for errors.

    $ /Users/msmith/Library/Caches/org.beeware.briefcase/tools/android_sdk/cmdline-tools/latest/bin/sdkmanager --licenses

Log saved to /Users/msmith/git/beeware/helloworld/logs/briefcase.2022_12_12-17_06_16.create.log

briefcase.2022_12_12-17_06_16.create.log

Additional context

As shown here, this can be fixed by running softwareupdate --install-rosetta. Briefcase should do this automatically.

@mhsmith mhsmith added bug A crash or error in behavior. macOS The issue relates to Apple macOS support. android The issue relates to Android mobile support. labels Dec 12, 2022
@mhsmith
Copy link
Member Author

mhsmith commented Dec 12, 2022

Unfortunately that leads to another problem: all the binaries installed by the sdkmanager are x86, so the emulator doesn't work:

(bw-311) msmith@mbp helloworld % briefcase run android

Select device:

  1) Create a new Android emulator

> 1

You need to select a name for your new emulator. This is an identifier that
can be used to start the emulator in future. It should follow the same naming
conventions as a Python package (i.e., it may only contain letters, numbers,
hyphens and underscores). If you don't provide a name, Briefcase will use the
a default name 'beePhone'.

Emulator name [beePhone]: 

[android_sdk] Obtaining pixel_3a device skin...
Downloading mirror-goog-studio-main-artwork-resources-device-art-resources-pixel_3a.tar.gz...
Installing device skin... done

[android_sdk] Downloading the 'system-images;android-31;default;arm64-v8a' Android system image...
[=======================================] 100% Unzipping... arm64-v8a/data/misc/
Creating Android emulator beePhone... done
Adding extra device configuration... done

Android emulator 'beePhone' created.

In future, you can specify this device by running:

    $ briefcase run android -d @beePhone

[helloworld] Starting emulator beePhone...
Starting emulator...
INFO    | Android emulator version 31.3.13.0 (build_id 9189900) (CL:N/A)
emulator: INFO: Found systemPath /Users/msmith/Library/Caches/org.beeware.briefcase/tools/android_sdk/system-images/android-31/default/arm64-v8a/
PANIC: Avd's CPU Architecture 'arm64' is not supported by the QEMU2 emulator on x86_64 host.

Android emulator was unable to start!

Try starting the emulator manually by running:

    $ /Users/msmith/Library/Caches/org.beeware.briefcase/tools/android_sdk/emulator/emulator @beePhone -dns-server 8.8.8.8

Resolve any problems you discover, then try running your app again. You may
find this page helpful in diagnosing emulator problems.

    https://developer.android.com/studio/run/emulator-acceleration#accel-vm

Log saved to /Users/msmith/git/beeware/helloworld/logs/briefcase.2022_12_12-17_56_47.run.log

briefcase.2022_12_12-17_56_47.run.log

(bw-311) msmith@mbp helloworld % cd /Users/msmith/Library/Caches/org.beeware.briefcase/tools/android_sdk/emulator      
(bw-311) msmith@mbp emulator % file emulator
emulator: Mach-O 64-bit executable x86_64

I was able to work around this by installing the emulator through Android Studio:

(bw-311) msmith@mbp helloworld % file ~/Library/Android/sdk/emulator/emulator
/Users/msmith/Library/Android/sdk/emulator/emulator: Mach-O 64-bit executable arm64

... and setting ANDROID_SDK_ROOT to that location.

But I'm not sure what the proper solution to this is, or why it hasn't been reported by anyone else.

@freakboy3742
Copy link
Member

That's odd... I don't remember explicitly installing Rosetta on my M1. I can only assume it was implicitly installed by one of the (many) other tools that I installed when I was setting up my machine.

I do have "fond" memories of wrestling Android through x86 compatibility though :-)

The one thing that I remember is that I spent of lot of time purging caches and "starting clean". If the Android tools installation broke half way, I essentially needed to start from scratch next time, or Android would get itself tied in knots trying to work out whether it needed x86 or ARM binaries. Purging the Briefcase Android cache and the .android folder was the only reliable way to get it to pick up the right versions. If it found an x86 image during install, it would shift back into x86 mode, and nothing could convince it to stay on ARM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
android The issue relates to Android mobile support. bug A crash or error in behavior. macOS The issue relates to Apple macOS support.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants