Android Emulator On Macbook M1

Using Android Studio Emulators in M1 Mac:

Android emulator on macbook m1 pro

Previously, when M1 Macbooks were released, Android studio didn’t have any support for emulators. Google has released a different preview build for emulators. You can check this build here.

  1. The few times I do use an Android app on my Chromebooks, for example, is with the touchscreen and the display rotated back. No can do on a MacBook right now. However, there is a key benefit that Apple users will enjoy and that’s the fact that the iOS apps will generally run natively and won’t need to be recompiled for the new Apple M1 chip.
  2. Setup M1 Android Emulator. Go to Tools → AVD Manager, then click +Create Virtual Device. Pick a device definition you like, e.g., Pixel 5. Pick a system image whose ABI is arm64-v8a. If you can't find any of them, check out the 'Other Images' tab. Download the ‘S’ or ‘R (30)’ API level.
Macbook

The problem with this preview build is that you can’t change the emulator device type. It works, but if you want to test your application on different device or different screen sizes, there was no other option available.

Apple M1 MacBooks will soon be able to run Android apps, as well as iOS. It looks like Android apps could be coming to Apple MacBooks and Macs that run on the new M1 chip, with the BlueStacks.

Recently, they released one change to the Android Studio SDK manager and downloading an extra emulator is no loger needed now.

In this post, I will quickly show you how to create Android Emulators on M1 chipset mac in Android Studio.

How to do that:

First, make sure that you have the latest Android Studio installed. If you have 4.1.2 or later Android studio version, this will work.

Android Emulator On Macbook M1 Plus

  1. First, start AVD manager. If you haven’t created any AVD or android virtual device before, you will find it in Tools->AVD Manager.

  2. Click on Create new virtual device button. It will show you a list of different devices. You can select any of these phones.

  1. Click on next. It will show you a list of system images. Basically, it shows different images for different Android Versions that can be used with the current AVD. Make sure to select the ‘Other image’ tab. Images listed under this tab are designed for Macbook M1.

That’s all. It will create one emulator using that selected image. You can also create different virtual devices using the same image.

Android Emulator M1 Preview

Note: There is an official repo now which is preferred: (https://github.com/google/android-emulator-m1-preview). We will still watch this repo for issues and comments, but please redirect your activity to the official repo.

This is a preview of some basic Android emulation functionality on the M1. There are still many issues, but apps work at a basic level. To be updated soon with more fixes. The release tag corresponds to this commit: https://android.googlesource.com/platform/external/qemu/+/aca144a9e9264b11c2d729096af90d695d01455d

Known issues

  • Webview doesn't work
  • No sound
  • No device skins
  • Video codecs not working
  • 32 bit ARM apps won't work
  • Graphical glitches in some Vulkan apps
  • Popup on startup about not being able to find the ADB path (ADB will still notice the emulator if you have it installed though)
  • When building, it may be faster to start then cancel the Python triggered build and then reissue ninja -C objs install/strip versus letting the Python triggered build finish.

How to use

This only works on M1 Apple Silicon Macs. M1 (or equivalently capable) SoCs are required; note that this does not work on DTKs as they do not support ARM64 on ARM64 hardwre virtualization via Hypevisor.framework. However, we have plans to add support there as well via Virtualization.framework.

Go to the Github releases page, download a .dmg, drag to the Applications folder, and run. You'll first need to right click the app icon and select Open and then skip past the developer identity verification step (we are working on providing official identity info). The first few times it starts up it will take a while to show up, but subsequent launches will be faster.

If you've installed Android Studio and Android SDK and adb is available, the emulator should be visible from Studio and work (deploy built apps, debug apps, etc).

How to configure

Android Emulator On Macbook M1

Edit /Applications/Android Emulator.app/Contents/MacOS/aosp-master-arm64-v8a/config.ini. Some notable options:

  • disk.dataPartition.size: size of userdata. When reconfiguring, you'll also need to delete all userdata*.img files in that directory.
  • fastboot.forceColdBoot,fastboot.forceFastBoot: whether to enable snapshots. Current default is snapshots disabled. Set fastboot.forceColdBoot=no,fastboot.forceFastBoot=yes to enable snapshots.
  • hw.lcd.density: Virtual display DPI.
  • hw.lcd.width,hw.lcd.height: Virtual display dimensions.
  • hw.ramSize: RAM limit for the guest. (2GB minimum)
Android emulator on macbook m1 download

How to wipe data

Remove all userdata*.img files in /Applications/Android Emulator.app/Contents/MacOS/aosp-master-arm64-v8a/.

How to build your own emulator

Building the engine

The emulator source code lives (here), but there are a bunch of other dependencies to download, so we use repo.

Emulator

To build, first make sure you have Xcode and Xcode command line tools installed, and that you have Chromium depot_tools in your PATH (link). Then:

Note that canceling the python based build after it gets going and issuing just ninja -C objs install/strip may be faster.

The built artifacts are in /path/to/external/qemu/objs/distribution/emulator. They should be automatically signed. However, the binaries in objs/ are not; to sign them, issue ./sign-objs-binaries.sh. Note that this can only be done after ninja -C objs install/strip is successful.

Android Emulator Apple M1 Github

Building the system image

Android Emulator On Macbook M1 Free

The system image is built from AOSP master sdk_phone_arm64 with a few modifications. Ideally, let's be on a Linux host when building the system image---the build is relatively untested on M1 systems, and at least, we need to create a separate case sensitive partition for the AOSP repo. Assuming you're on Linux:

We first need to make an edit to remove all 32 bit support. Patch this change: link to build/make/target/board/emulator_arm64/BoardConfig.mk. Then:

After that's done, we can use this script to package up the system image for use in /Applications/Android Emulator.app/Contents/MacOS/aosp-master-arm64-v8a/. Assuming you're still in the Android build environment:

Android Studio Emulator Macbook M1

Then, $ZIPPED_NAME.zip can be sent over to the M1 and the contents of its files/ can be coped over into /Applications/Android Emulator.app/Contents/MacOS/aosp-master-arm64-v8a/.