Although I am familiar with building AOSP source, I still learn something from the following blog post series by Udi Cohen in 2014:

The last time I built AOSP on Mac, there were still some pitfalls. I finally gave up and settled on doing it in Ubuntu. After reading Udi’s posts, I decided to give it a try again. Another motivation is to experiment some new changes that will be available in upcoming Android N:

  • Soong build system
  • Jack/Jill for Java code
  • Clang for C/C++ code

zsh or bash?

zsh with Oh My Zsh is my default shell but I still prefer bash to prevent possible compatibility issues when building AOSP.

$ exec bash -l

exec will replace current shell with bash and -l is necessary for ~/.bash_profile to be executed.

$ export JAVA_HOME=$(/usr/libexec/java_home)

full_eng or full_x86_64-eng?

QEMU-based ARM emulation is slow compared with HAXM-accelerated x86-64 emulation. You should definitely go for x86_64 target if ARM emulation is not important to you.

OS X specific

There are still two tweaks you should do before building AOSP code on Mac:

Java

You need to set JAVA_HOME variable explicitly to prevent build error of “could not find jdk tools.jar”:

curl

AOSP does not like SecureTransport-based curl for unknown reason. You have to build an OpenSSL-based curl and manipulating $PATH to force its use:

$ brew install curl --with-openssl
$ export PATH=$(brew --prefix curl)/bin:$PATH

IntellJ or Android Studio?

I feel more comfortable using IntelliJ to analyze AOSP codebase and debug framework code. Android Studio is more app-oriented and sometimes does not work as expected when abused with this hack.