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 https://medium.com/@christopherney/building-android-o-with-a-mac-da07e8bd94f9
Official Android documentation: https://source.android.com/setup/requirements
“Essential Products: device_essential_mata” by Jean-Baptiste Théou and Gary Bisson https://github.com/EssentialOpenSource/device_essential_mata
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
- Install Xcode from the Mac Appstore: https://apps.apple.com/us/app/xcode/id497799835?mt=12
- Install Xcode command line tools with:
$ 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. https://github.com/EssentialOpenSource/device_essential_mata
$ source ~/.zshenv
$ mkdir ~/.bin
$ curl https://storage.googleapis.com/git-repo-downloads/repo > ~/.bin/repo
$ chmod a+x ~/.bin/repo
$ mountForest
$ cd /Volumes/Forest
$ mkdir aosp_mata
$ cd aosp_mata
$ git config --global user.name "Your Name"
$ git config --global user.email "you@example.com"
$ repo init -u https://android.googlesource.com/platform/manifest -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 https://github.com/EssentialOpenSource/device_essential_mata.git 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 vendor.zip "https://storage.googleapis.com/essential-static/vendor-QQ1A.200105.088.zip"$ unzip vendor.zip
$ rm -f vendor.zip
$ 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/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/
Download Mac SDKs: https://github.com/phracker/MacOSX-SDKs/releases
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/envsetup.sh
$ 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.
https://developer.android.com/studio/releases/platform-tools
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