Building Android on Snow Leopard

In a break from writing about my life, I thought I’d give some Android developers out there a hand with a problem. Google don’t yet support the building of Android on OS 10.6 (Snow Leopard), but I managed to get it working. To do this, you’ll need to do four things:

  1. Install Rosetta
  2. Install JDK 1.5
  3. Install OS 10.4 support for XCode
  4. Change some gcc headers

First, install Rosetta from your Snow Leopard installation DVD. This allows you to run flex from the command line. Without this, a file in libwebcore won’t be generated correctly and you’ll get an error about a missing lex() symbol.

Second, install JDK 1.5. I found a guide online to do this. Instead of using update 4 as mentioned in the article, download the 1.5 JDK update 5 from…. Update: after doing this, change the current SDK version by using the Java Preferences utility in Applications->Utilities.

Third, download the XCode 3 package from Apple and install support for building for the OS 10.4 target.

Finally, you need to add symlinks from some OS 10.4 gcc includes to the 10.6 ones. This is fairly easy to figure out when building, but the ones I changed were all in /Developer/SDKs/MacOSX10.4u.sdk/usr/include and are as follows:

  • emmintrin.h -> /Developer/SDKs/MacOSX10.6.sdk/usr/lib/gcc/i686-apple-darwin10/4.2.1/include/emmintrin.h
  • float.h -> /Developer/SDKs/MacOSX10.6.sdk/usr/lib/gcc/i686-apple-darwin10/4.2.1/include/float.h
  • mm_malloc.h -> /Developer/SDKs/MacOSX10.6.sdk/usr/lib/gcc/i686-apple-darwin10/4.2.1/include/mm_malloc.h
  • mmintrin.h -> /Developer/SDKs/MacOSX10.6.sdk/usr/lib/gcc/i686-apple-darwin10/4.2.1/include/mmintrin.h
  • stdarg.h -> /Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/stdarg.h
  • xmmintrin.h -> /Developer/SDKs/MacOSX10.6.sdk/usr/lib/gcc/i686-apple-darwin10/4.2.1/include/xmmintrin.h

If you are building Android, then I am fairly certain I don’t need to tell you how to make symlinks.


Update: in order to build the kernel, you’ll need to grab a copy of the elf.h header from Linux and copy it to /usr/local/include on your Mac. Comment out the #include <features.h>, otherwise you’ll get a compilation error.

Also, the following patches may be required on a 64 bit system:

11 Replies to “Building Android on Snow Leopard”

  1. Thanks so much for this great writeup. I have encountered a couple more errors in the process.

    1) The JDK5 installer from Apple would not work, it says that a newer package is already present. Is there other way to get the files from the package other then “launching” it?

    2) I started build with JDK5 from leopard instead and I am hitting the wall on some libs being compiled as 64bit (default architecture on SL) and not being found by other parts of the build process (specifically Could not load ‘clearsilver-jni’). Have you encountered this?

  2. @Jan (replying to myself)

    1) yes, there is a tool but generaly available JDK5 from leopard is enough

    2) you just have to se 64bit JDK5 as default JDK in Java Prefferences

    3) one more compilation issue I had was related to endians in yaffs2. this can be fixed by adding a default else branch to #ifdef HAVE_BIG_ENDIAN in mkyaffs2image.c

  3. PLEASE! PLEASE! PLEASE! help me.
    I have been trying everything I can find and did all the steps you guys listed here a few times but I keep getting the same error that I can NOT get around. Please if you have ANY idea what it is can you help me? I have tried changing my JDK to 6 (32 bit), JDK 6 (64 bit), JDK 5(32 bit), JDK 5 (64 bit) none of them seem to help. This is what I always get:

    I have done the steps here and installed 1.5 in its own dir:

    drwxr-xr-x 9 root wheel 306 Feb 14 2009 1.5.0
    drwxr-xr-x 3 root wheel 102 Jul 20 17:35 1.3.1
    lrwxr-xr-x 1 root wheel 5 Dec 13 13:30 1.3 -> 1.3.1
    lrwxr-xr-x 1 root wheel 5 Dec 13 13:30 1.6 -> 1.6.0
    drwxr-xr-x 8 root wheel 272 Dec 16 10:45 1.6.0
    lrwxr-xr-x 1 root wheel 1 Dec 17 13:36 Current -> A
    drwxr-xr-x 9 root wheel 306 Dec 17 13:38 A
    lrwxr-xr-x 1 root wheel 1 Dec 17 13:49 CurrentJDK -> A
    lrwxr-xr-x 1 root wheel 5 Dec 22 00:01 1.5 -> 1.5.0

    build/core/ warning: overriding commands for target `out/target/product/generic/obj/include/libpv/getactualaacconfig.h’
    build/core/ warning: ignoring old commands for target `out/target/product/generic/obj/include/libpv/getactualaacconfig.h’
    /bin/bash: line 0: cd: development/tools/layoutopt/app/src/resources: No such file or directory
    host C: libclearsilver-jni <= external/clearsilver/java-jni/j_neo_util.c
    external/clearsilver/java-jni/j_neo_util.c:2:17: error: jni.h: No such file or directory
    In file included from external/clearsilver/java-jni/j_neo_util.c:3:
    out/host/darwin-x86/obj/SHARED_LIBRARIES/libclearsilver-jni_intermediates/org_clearsilver_HDF.h:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘jlong’
    out/host/darwin-x86/obj/SHARED_LIBRARIES/libclearsilver-jni_intermediates/org_clearsilver_HDF.h:23: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’
    out/host/darwin-x86/obj/SHARED_LIBRARIES/libclearsilver-jni_intermediates/org_clearsilver_HDF.h:31: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘jboolean’
    out/host/darwin-x86/obj/SHARED_LIBRARIES/libclearsilver-jni_intermediates/org_clearsilver_HDF.h:39: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘jboolean’
    external/clearsilver/java-jni/j_neo_util.c:431: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘jlong’
    external/clearsilver/java-jni/j_neo_util.c:440: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘jstring’
    external/clearsilver/java-jni/j_neo_util.c:453: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘jstring’
    external/clearsilver/java-jni/j_neo_util.c:466: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’
    make: *** [out/host/darwin-x86/obj/SHARED_LIBRARIES/libclearsilver-jni_intermediates/j_neo_util.o] Error 1

    Thank you in advance for ANY help you can provide.

  4. I think it’s impossible to make andorid project under SnowLeopard currently. the main reason is that the java vm 1.5 on snow leopard is mix mode which will generate 64bit jni lib, so the android can’t load it . All we have to do is just waiting

  5. @captain: it’s not impossible, because many people can do it, and these are the instructions to do so.

    @Jan: the page has a link to instructions for installing Java 1.5. Right, you can’t install the package directly but you must use the Pacifist tool. I haven’t encountered any other problems.

Leave a Reply

Your email address will not be published.