Jun 222010
 

My previous post, Compiling Android Source on Mac OS X 10.6 Snow Leopard, is outdated and doesn’t work with the new source code, so I thought I’ll update this for eclair.

Here are the steps.

1. Install XCode, Macports, repo, etc.

I assume everyone knows how to do this. Follow the instructions from the Get Android Source Code page. Just remember to create a new partition that is a case-sensitive partition if you’re using a non case-sensitive primary partition. I’ll start off after you’ve gotten the source from git.

2. Get the following patches.

Since there is only 1 patch to grab, I used repo for this.

Patch 12074 - Change Ic4caeff0: Enable building on java 1.6 without conflicts.

This patch will allow you to use Java 1.6 that comes with Snow Leopard instead of Java 1.5.

[sourcecode language="bash"]
repo download platform/build 12074/5
[/sourcecode]

The rest of the patches seems to have made it into the trunk, so it isn’t required to patch them anymore.

3. Edit the files.

However, there is 1 extra step you need to do in order to get a clean build. I can’t find the patch for this yet, so if anyone knows, please comment the patch number. You have to edit the following file:

[sourcecode language="bash"]
system/core/libacc/acc.cpp
[/sourcecode]

In a gist, change all the (int) to (size_t). Change the following lines:

Line 4557:
[sourcecode langauge="cpp" firstline="4557"]
pGen->leaR0((int) glo, mkpCharPtr, ET_RVALUE);
[/sourcecode]
to
[sourcecode language="cpp" firstline="4557"]
pGen->leaR0((size_t) glo, mkpCharPtr, ET_RVALUE);
[/sourcecode]

Line 4637:
[sourcecode langauge="cpp" firstline="4637"]
pGen->loadFloat((int) glo, mkpFloat);
[/sourcecode]
to
[sourcecode language="cpp" firstline="4637"]
pGen->loadFloat((size_t) glo, mkpFloat);
[/sourcecode]

Line 4643:
[sourcecode langauge="cpp" firstline="4643"]
pGen->loadFloat((int) glo, mkpDouble);
[/sourcecode]
to
[sourcecode language="cpp" firstline="4643"]
pGen->loadFloat((size_t) glo, mkpDouble);
[/sourcecode]

Line 4730-4731:
[sourcecode langauge="cpp" firstline="4730"]
pVI->pForward = (void*) pGen->leaForward(
(int) pVI->pForward, pVal);
[/sourcecode]
to
[sourcecode language="cpp" firstline="4730"]
pVI->pForward = (void*) pGen->leaForward(
(size_t) pVI->pForward, pVal);
[/sourcecode]

Line 5740:
[sourcecode langauge="cpp" firstline="5740"]
pGen->resolveForward((int) name->pForward);
[/sourcecode]
to
[sourcecode language="cpp" firstline="5740"]
pGen->resolveForward((size_t) name->pForward);
[/sourcecode]

4. Build and watch it fly.

[sourcecode language="bash"]
make
[/sourcecode]

Wait for an hour or two for the build to be completed and you’ll have a nice Android 2.1 build in the “out” directory.

Related posts:

  1. Compiling Android Source on Mac OS X 10.6 Snow Leopard
  2. Installing Go Language on Mac OS X
  3. Singularity Source Code Released to CodePlex
  4. Release of Microsoft Source Analysis for C#
  5. Xtreme Programming and Open Source Software Development
  • Pingback: Compiling Android Source on Mac OS X 10.6 Snow Leopard @ JustinLee.sg

  • Hong

    Is there a tutorial for compiling Android 2.2 on Win3.1?

    • http://www.justinlee.sg Justin Lee

      You’re joking right? :) If you can provide me with both 2.2 source and Win3.1 machine, then I can get it running for you.

  • Andrew

    Hey Justin,

    Since 2.2 source dropped this week, have you been playing around with it at all? I’ve been working on it on Snow Leopard but am blocked trying to get v8 (which is new to Froyo) to compile. Let me know if this is something you’re taking a crack at as well, maybe we can collaborate =)

    Andrew

  • Tony

    I am in the same boat. Attempting to get froyo to build on SL. I have made good progress, but am now stuck with:
    /usr/bin/ranlib: archive member: out/host/darwin-x86/obj/STATIC_LIBRARIES/libhost_intermediates/libhost.a(CopyFile.o) cputype (16777223) does not match previous archive members cputype (7) (all members must match)
    /usr/bin/ranlib: archive library: out/host/darwin-x86/obj/STATIC_LIBRARIES/libhost_intermediates/libhost.a will be fat and ar(1) will not be able to operate on it
    ar: internal ranlib command failed

    Have you guys seen this?

  • Tony

    I figured that error out. v8 needs a 32bit compiler, and I was using gcc_select to swap to gcc-4.0. That was my fail. All I had to do was export CC=gcc-4.0 and export CXX=g++-4.0.

    Also make sure that you use java 1.5. You may get an error about JavaVM not found. I just copied the JavaVM folder from 1.6.0/JavaVM to the 1.5.0 and it worked.

    Good Luck

  • Tony

    Sorry, correction I copied the JavaVM binary from the A folder to my 1.5.0 folder

  • http://www.justinlee.sg Justin Lee

    Interesting. I haven’t tried compiling the Android Froyo 2.2 yet, but I’ll look into it when I have the time. It sounds like it’ll take some time to figure out a completely clean build for it.

    Froyo 2.2 is a different beast altogether with so many changes. Will try to figure out how to compile it.

  • Tony

    In all honesty, once you get those 2 issues tied down its not bad. I am compiling for the Motorola Droid using a device/vendor overlay created by Koushik Dutta. I was suprised how easy it was, based on all the patches previous versions needed.

  • BitVenom

    Tony, you said you ‘I figured that error out.’ in regards to the mismatched cpu-type… Oddly I am also getting that error, and while I have already setup things to not use 64-bit and the proper java, neither is helping. I wonder what you did to resolve it yourself?

  • Tony

    BitVenom, I was using gcc_select to swap to the 32bit compiler. Using that it switches the linker, ld, ar etc. It basically replaces all the symlinks.
    I swapped back to gcc-4.2 using gcc_select, so all the symlinks etc were correct. Then all i did was export CC=gcc-4.0 and export CXX=g++-4.0. (Koush clued me in on that)

    After that I did make clean, and started over with a make -j4, and it worked.

  • Tony

    Btw Justin, both your posts about compiling android on Mac OSX were a huge help to me. Thank you for putting forth the effort.

  • Jairo Martin

    So tony where you able to build 2.2, I was also failing in the v8 part. I just stub out building v8 and still have more issues.

  • Tony

    Jairo I did get successful builds of 2.2. Just exporting CC and CXX like above allowed v8 to build.

    I have just recently come into more issues though with recent code updates. This time its in external/qemu, which is funny since we had patches before to fix the emulator build issue.

  • charan

    I am getting the error on compiling packages
    Could not load ‘clearsilver-jni’
    java.library.path = out/host/darwin-x86/lib
    make: *** [out/target/common/docs/api-stubs-timestamp] Error 45
    make: *** Waiting for unfinished jobs….

    I tried changing java versions between 1.5 n 1.6 n between 32bit n 64bit and did a make clean everytime, same error

  • Pingback: [Android][URL][筆記] 在10.6上編譯AndroidOS source code

  • http://wisevishvesh.wordpress.com vishvesh

    Hi Charan,
    I have got similar errors. I solve it by reinstalling java on my machine. Try downloading and installing the latest version of java from the apple website and do the steps 11 and 12 prescribed in my blog

    Link to my blog.

    http://wisevishvesh.wordpress.com/2010/04/12/building-eclair-on-snow-leopard/

    Hopefully it should solve your problem.

  • Joe

    FYI, the “Java 1.6″ patch:
    https://review.source.android.com/#change,12074
    has been abandoned, as it will now only build with 1.6, and will no longer build with 1.5. So that step should not be necessary anymore.

  • http://www.s3solutions.nl Vincent

    I have this when I try to make the current git tree:

    MacBook-Pro:mydroid vincent$ make
    ============================================
    PLATFORM_VERSION_CODENAME=AOSP
    PLATFORM_VERSION=AOSP
    TARGET_PRODUCT=generic
    TARGET_BUILD_VARIANT=eng
    TARGET_SIMULATOR=
    TARGET_BUILD_TYPE=release
    TARGET_BUILD_APPS=
    TARGET_ARCH=arm
    HOST_ARCH=x86
    HOST_OS=darwin
    HOST_BUILD_TYPE=release
    BUILD_ID=OPENMASTER
    ============================================
    make(70937) malloc: *** error for object 0x104e6d858: incorrect checksum for freed object – object was probably modified after being freed.
    *** set a breakpoint in malloc_error_break to debug
    Abort trap

    Does anyone know why this happens?