Building Android 11 for PH-1 on Apple Silicon

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
# 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
$ mkdir -p device/essential$ cd device/essential$ git clone mata$ cd ../../
$ cd system/sepolicy
$ git revert 61178550157fce18861ddd59fa9a6a29cf06c583
$ cd ../../
$ cd device/essential/mata
$ curl -o ""
$ unzip
$ rm -f
$ cd ../../../

Fix the Build for OS X

Correct the SDK version

  • /Applications/
namespace base {size_t psize = getpagesize();ssize_t SendFileDescriptorVector(borrowed_fd sockfd, const void* data, size_t len,
if (cmsg_space >= psize) {

Build AOSP

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

Flash to Device

Add the google platform-tools to your machine.

$ nano ~/.zshenv
export PATH=~/.bin/platform-tools:$PATH
$ 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