Compiling Android master on Mac OS X Lion with Xcode 4

[Update: The patches have been merged into the AOSP master branch, so as of the 22nd of December AOSP master should compile on OS X 10.7 with Xcode 4 straight from checkout]

My company has worked on some Android firmware projects in the past, but, due to the closed source nature of Honeycomb, that work pretty much dried up. Recently though Google released Android 4.0 to the masses and we’ve had a few enquiries about firmware work again, so I thought I’d see what the current state of building Android was for our default machine configuration.

The first problem I hit was the Android build system wasn’t compatible with Mac OS X 10.7 (Lion) and Xcode 4 (The Xcode version available for Lion), so I decided to use a bit of spare time to seeing if it could be fixed.

The following are the steps I found necessary to allow the build to complete on the current master branch (the android-4.0.3_r1 branch has some additional issues which I haven’t resolved yet, so please don’t assume this will work for that branch as well);

1) Install Xcode from the Mac App Store (this gave me Xcode version 4.2).

2) Install version 2.0.3 of MacPorts using the DMG installer image for Lion which is available from the MacPorts site. During the installation process you’ll be asked to install Java if you don’t already have it installed, select the install option.

3) Follow the Android build environment setup instructions skipping the instructions on installing Xcode & MacPorts (because you’ve already done that)

[Note: The instructions on the Android site indicate a reversion of the version of Make may be required, but the configuration I was left with straight after installing Xcode & MacPorts gave me make 3.81 by default, so you probably won’t need to revert the make version either. I also noticed that my Lion installation didn’t require the ulimit modification due to it already being unlimited.]

4) Apply the following patches I created for three different projects in the source tree to fix build issues;

build project;

diff --git a/core/combo/ b/core/combo/
index 544a29e..407c74f 100644
--- a/core/combo/
+++ b/core/combo/
@@ -53,7 +53,11 @@ HOST_JNILIB_SUFFIX := .jnilib

        -include $(call select-android-config-h,darwin-x86)
+ifneq ($(filter 10.7.%, $(build_mac_version)),)



development project;

diff --git a/tools/emulator/opengl/tests/translator_tests/GLES_CM/ b/tools/emulator/opengl/tests/translator_tests/GLES_CM/
index deb11b6..a73f6b8 100644
--- a/tools/emulator/opengl/tests/translator_tests/GLES_CM/
+++ b/tools/emulator/opengl/tests/translator_tests/GLES_CM/
@@ -8,6 +8,15 @@ LOCAL_SDL_CONFIG ?= prebuilt/$(PREBUILT)/sdl/bin/sdl-config
 LOCAL_SDL_CFLAGS := $(shell $(LOCAL_SDL_CONFIG) --cflags)
 LOCAL_SDL_LDLIBS := $(filter-out %.a %.lib,$(shell $(LOCAL_SDL_CONFIG) --static-libs))

+ifeq ($(HOST_OS),darwin)
+  DARWIN_VERSION := $(strip $(shell sw_vers -productVersion))
+  ifneq ($(filter 10.7 10.7.%,$(DARWIN_VERSION)),)
+    # Lion needs to be forced to link dylib to avoid problems
+    # with the dynamic function lookups in SDL 1.2
+    LOCAL_SDL_LDLIBS += /usr/lib/dylib1.o
+  endif

diff --git a/tools/emulator/opengl/tests/translator_tests/GLES_V2/ b/tools/emulator/opengl/tests/translator_tests/GLES_V2/
index ae0064f..efbe6bd 100644
--- a/tools/emulator/opengl/tests/translator_tests/GLES_V2/
+++ b/tools/emulator/opengl/tests/translator_tests/GLES_V2/
@@ -17,6 +17,12 @@ LOCAL_LDLIBS += $(LOCAL_SDL_LDLIBS)

 ifeq ($(HOST_OS),darwin)
+DARWIN_VERSION := $(strip $(shell sw_vers -productVersion))
+ifneq ($(filter 10.7 10.7.%,$(DARWIN_VERSION)),)
+  # Lion needs to be forced to link dylib to avoid problems
+  # with the dynamic function lookups in SDL 1.2
+  LOCAL_LDLIBS += /usr/lib/dylib1.o
 $(call emugl-import,libMac_view)


external/qemu project;

diff --git a/ b/
index e58f984..d638640 100644
--- a/
+++ b/
@@ -74,8 +74,8 @@ ifeq ($(HOST_OS),darwin)
     ifneq ($(filter 10.1 10.2 10.3 10.1.% 10.2.% 10.3.% 10.4 10.4.%,$(DARWIN_VERSION)),)
         $(error Building the Android emulator requires OS X 10.5 or above)
-    ifeq ($(filter 10.5 10.5.%,$(DARWIN_VERSION)),)
-        # We are on Snow Leopard or above
+    ifneq ($(filter 10.6 10.6.%,$(DARWIN_VERSION)),)
+        # We are on Snow Leopard
         LEOPARD_SDK := /Developer/SDKs/MacOSX10.5.sdk
         ifeq ($(strip $(wildcard $(LEOPARD_SDK))),)
             $(info  Please install the 10.5 SDK on this machine at $(LEOPARD_SDK))
@@ -191,6 +191,11 @@ endif

 ifeq ($(HOST_OS),darwin)
   QEMU_SYSTEM_LDLIBS += -Wl,-framework,Cocoa,-framework,QTKit,-framework,CoreVideo
+  ifneq ($(filter 10.7 10.7.%,$(DARWIN_VERSION)),)
+    # Lion needs to be forced to link dylib to avoid problems
+    # with the dynamic function lookups in SDL 1.2
+    QEMU_SYSTEM_LDLIBS += /usr/lib/dylib1.o
+  endif

 include $(LOCAL_PATH)/Makefile.common


5) Follow the build instructions and watch the build complete :).

This process should be enough to get you a working environment to build for devices and has allowed me to build a fully functioning version of the master branch (as of 20th December 2011) for my Galaxy Nexus using the full_maguro-userdebug lunch target.

There are still some some runtime issues with some of the host scripts which are produced during a build. The main issue seems to be with auto-detection of their environment and not finding the 64bit variants of some libraries (e.g. the android script fails saying it doesn’t have any x86_64 SWT libraries available), but that’s a problem for another day….

If you have any questions about building the Android source code please use the android-building Google group to discuss them so that others can either help out or see how to resolve similar issues.

9 thoughts on “Compiling Android master on Mac OS X Lion with Xcode 4

Add yours

  1. Any problems getting openldap to compile? I’ve been trying to get a compile environment setup for a few days now and can’t seem to get openldap to compile for gnupg. Only issue I’ve had so far =/

  2. For those of us who had already made the modifications from but used the previous method of installing the MacOSX10.5.mkpkg and then making sure the files were located in /Developer/SDKs with a commented qemu/, this process will fail.
    You removed support for 10.5 completely by replacing the current 10.5+ with 10.6+, instead of simply adding support for 10.6+

    1. I believe you’ve misread the previous patch. The patch changed the check from assuming everything that wasn’t 10.5 was 10.6 to explicitly checking if the OS version was 10.6. Nothing was removed which would have affected 10.5 builds.

      1. It did check for 10.6, correct, but it also only checked up to 10.4 and then 10.6. Also, when using features such as this not only causes build problems, but actually leads to rather substantial system corruption (LOCAL_LDLIBS += /usr/lib/dylib1.o) which may have been the underlying issue causing the problem.

        1. The altered rule started off by checking for 10.6 and above (as documented by the comment), my patch changed it from looking for a version which wasn’t 10.5 and assuming it was 10.6 to explicitly looking for 10.6, so the rule didn’t check for 10.5 in the first place. If you’ve hit a problem it’s worth submitting a patch to the AOSP gerrit and posting on the android-building google group.

Leave a Reply

Your email address will not be published. Required fields are marked *

Proudly powered by WordPress | Theme: Baskerville 2 by Anders Noren.

Up ↑