How to build AOSP on M1

Before we start this job, let’s check how my laptop looks. Here are some factors of my M1 MacBook Pro 2020
- OS version : macOS Monterey 12.1 Beta (21C5021h)
- Chipset: Apple M1
- Memory size: 16 GB
First of all, you will need to install the XCode command-line tools.
xcode-select --install
And, you should also install Rosetta for code-building.
/usr/sbin/softwareupdate --install-rosetta
When I tried to install Rosetta, I found some system errors, and I can’t solve that, but it seems that doesn’t matter. You can still build the AOSP project.
Now, we should prepare a case-sensitive disk image cause the AOSP should build on the Ubuntu system, but MacOS is not a case-sensitive file system ref.
hdiutil create -type SPARSE -fs 'Case-sensitive Journaled HFS+' -size 350g ~/aosp_source.dmg
After this, let’s create a ZSH environment. You might first time hear about ZSH. Here are some helpful tools for empowering your ZSH env, such as Oh My Zsh, Powerlevel10k, etc. I highly recommend that you try PowerLevel10k, a successor of the powerlevel9k, and it’s a perfect theme for ZSH env.
When you finish up installing/setting the ZSH, we need to create and edit the .zshenv with the following content:
# set the number of open files to be 2048
ulimit -S -n 2048
# Compiler cache
export USE_CCACHE=1
# Mount the Android Tree
function mountAOSP { hdiutil attach ~/aosp_source.dmg.sparseimage -mountpoint /Volumes/aosp_source; }
#Unmount the Android Tree
function umountAOSP() { hdiutil detach /Volumes/aosp_source; }
export PATH="/opt/local/bin:/opt/local/sbin:$PATH"
export PATH=~/.bin:$PATH
Let’s use this env setting and start downloading the AOSP code. We are going to use android-11.0.0_r48 for the building.
$ source ~/.zshenv
$ mkdir ~/.bin
$ curl https://storage.googleapis.com/git-repo-downloads/repo > ~/.bin/repo
$ chmod a+x ~/.bin/repo
$ mountAOSP
$ cd /Volumes/aosp_source
$ mkdir aospsrc
$ cd aospsrc
// setup your gitconfig
$ 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_r48
$ repo sync
Here are some commands to build AOSP:
$ source build/envsetup.sh
$ lunch aosp_arm-eng
$ make -j24
Then, you can start enjoying the AOSP journey now.
[Reference]
[Q&A]
-
Could not find a supported mac sdk: [“10.10” “10.11” “10.12” “10.13” “10.14” “10.15”]?
If you see this error message, you can check your MacOSX SDK under
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/To make sure you have correct SDKs for building. If you can’t see the needed SDKs under this folder, there are two ways you can solve this error:
a. You can download corresponding SDKs from
https://github.com/phracker/MacOSX-SDKsand put these SDKs into the folder.b. You can edit the
build/soong/cc/config/x86_darwin_host.goand add your current pointed SDK into this file.
-
When seeing : system/core/base/cmsg.cpp:36:21: error: use of undeclared identifier
PAGE_SIZEAdd this line into the file
size_t psize = getpagesize();namespace base { size_t psize = getpagesize(); ssize_t SendFileDescriptorVector(borrowed_fd sockfd, const void* data, size_t len, ...And then, replace the two distances of the PAGE_SIZE with
psize.if (cmsg_space >= psize) {
-
When seeing
Segmentation fault: 11Edit this file
system/sepolicy/tests/Android.bpby deleting this linelibc++_staticand then re-compile.Check this official fix from google.
-
When seeing these errors
external/python/cpython2/Modules/getpath.c:414:50: error: incompatible pointer types passing 'unsigned long *' to parameter of type 'uint32_t *' (aka 'unsigned int *') [-Werror,-Wincompatible-pointer-types] else if(0 == _NSGetExecutablePath(progpath, &nsexeclength) && progpath[0] == SEP) ^~~~~~~~~~~~~or
external/python/cpython3/Modules/getpath.c:414:50: error: incompatible pointer types passing 'unsigned long *' to parameter of type 'uint32_t *' (aka 'unsigned int *') [-Werror,-Wincompatible-pointer-types] else if(0 == _NSGetExecutablePath(progpath, &nsexeclength) && progpath[0] == SEP) ^~~~~~~~~~~~~You can solve these errors by modifying them.
#ifdef __APPLE__ #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 uint32_t nsexeclength = MAXPATHLEN; #else unsigned long nsexeclength = MAXPATHLEN; #endif #endifto
#ifdef __APPLE__ uint32_t nsexeclength = MAXPATHLEN; #endif#Android #Android/Build