Building Android 11 for PH-1 on Apple Silicon

This process should work on Intel.

This article is based on:

Building Android O with a Mac” by Christopher Ney

Official Android documentation:

“Essential Products: device_essential_mata” by Jean-Baptiste Théou and Gary Bisson

My Environment

  • Device: MacBook Air (M1, 2020)
  • OS: macOS Big Sur 11.1 (20C69)
  • Chip: Apple M1
  • Memory: 16GB
  • Device: Essential PH-1(mata)

Install Xcode and Tools

$ xcode-select --install
  • Install Rosetta with:
$ /usr/sbin/softwareupdate --install-rosetta

Creating a case-sensitive disk image

Case sensitive volume of 350GB with the following command line:

$ hdiutil create -type SPARSE -fs 'Case-sensitive Journaled HFS+' -size 350g ~/forest.dmg

Configure ZSH

Create and edit the .zsh_env file with the following code:

nano ~/.zshenv

Paste into the file

# set the number of open files to be 2048ulimit -S -n 2048# Compiler cacheexport USE_CCACHE=1# Mount the Android Treefunction mountForest { hdiutil attach ~/forest.dmg.sparseimage -mountpoint /Volumes/Forest; }#Unmount the Android Treefunction umountForest() { hdiutil detach /Volumes/Forest; }
export PATH="/opt/local/bin:/opt/local/sbin:$PATH"export PATH=~/.bin:$PATH

Download AOSP source code

We will be using android 11.0.0 r3 to match the mata opensource project.

$ source ~/.zshenv
$ mkdir ~/.bin
$ curl > ~/.bin/repo
$ chmod a+x ~/.bin/repo
$ mountForest
$ cd /Volumes/Forest
$ mkdir aosp_mata
$ cd aosp_mata

$ git config --global "Your Name"
$ git config --global ""

$ repo init -u -b android-11.0.0_r3
$ repo sync

Add the Mata repo (Steps are only needed for PH-1)

$ mkdir -p device/essential$ cd device/essential$ git clone mata$ cd ../../

Revert “sepolicy: support /system_ext and /product mapping files”

BOARD_SEPOLICY_VERS := 29.0 doesn’t build and without it the wrong mapping (1000) is created and 29.0 one is empty. We will revert this change for now.

$ cd system/sepolicy
$ git revert 61178550157fce18861ddd59fa9a6a29cf06c583
$ cd ../../

Download the vendor prebuilt for mata

$ cd device/essential/mata
$ curl -o ""
$ unzip
$ rm -f
$ cd ../../../

Fix the Build for OS X

Correct the SDK version

Download and uncompress the exact missing Mac SDK “10.15” version into the following directory:

  • /Applications/

Download Mac SDKs:

Correct the PAGE_SIZE error in Big Sur

Edit system/core/base/cmsg.cpp

Add a line to the file. “size_t psize = getpagesize();”

namespace base {size_t psize = getpagesize();ssize_t SendFileDescriptorVector(borrowed_fd sockfd, const void* data, size_t len,

Replace the two instances of PAGE_SIZE with psize

if (cmsg_space >= psize) {

Build AOSP

$ source build/
$ lunch mata-userdebug
$ make -j4

Final output should look like this!

[100% 48449/48449] Install system fs image: out/target/product/mata/system.img

#### build completed successfully (03:31:26 (hh:mm:ss)) ####

Flash to Device

Add the google platform-tools to your machine.

I extracted the folder to ~/.bin to keep things clean.

$ nano ~/.zshenv

Paste into the file

export PATH=~/.bin/platform-tools:$PATH

Flash the images to the device.

$ source ~/.zshenv
$ adb reboot bootloader
$ cd $OUT
$ fastboot flash:raw boot_a boot.img
$ fastboot flash:raw boot_b boot.img
$ fastboot flash system_a system.img
$ fastboot flash system_b system.img
$ fastboot flash vendor_a vendor.img
$ fastboot flash vendor_b vendor.img
$ fastboot erase userdata
$ fastboot reboot
$ croot



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store