Wednesday, September 08, 2010

How to compile Android 2.2 (Froyo) on Mac OS X 10.6 (Snow Leopard).

How to compile Android 2.2 (Froyo) on Mac OS X 10.6 (Snow Leopard).

Once upon a time I needed to do a custom build of Android OS with some changes to the core components for some custom devices.
The instructions how do get the source and do the build can be found on the Android Developers web site:
http://source.android.com/source/download.html
Everything went smooth, I took the latest code and compiled just fine, but.....
.... later I found out that I needed to have my build done based on Android 2.2 (Froyo) branch instead.

The "Froyo" build is not officially supported on the Snow Leopard and it didn't work right out of the box.
So, I had to spend a little bit of time to figure out how to make it work.

Here are the steps I had to go through:
* Follow the steps on http://source.android.com/source/download.html to get the source code and setup your build environment.
* Make sure you have XCode installed with support for Mac OS X 10.4(!) development.
* Install Java 1.5. This one a little bit tricky, since Java for Mac OS maintained by Apple and the older versions are pretty much not available to download. You have to download Java for Mac OS X 10.5 Update 7 http://support.apple.com/downloads/Java_for_Mac_OS_X_10_5_Update_7. Then use for example something like unpgk tool (http://www.timdoug.com/unpkg/) to exract the Java 1.5 from there. Replace the 1.5 and 1.5.0 symbolic links in
/System/Library/Frameworks/JavaVM.framework/Versions with the Java 1.5 from the package.
* I checked the Application->Utilities->Java Preferences as well to make sure the Java 1.5 is the first one in the list, although I'm not sure if it is necessarily. It worked and I didn't bother to try different settings.
* In order to start the build you would go to the root folder of the android source code tree and call "make".
* The first problem I stumbled upon was the problem with /Developer/SDKs/MacOSX10.4u.sdk/usr/include/stdarg.h file it could not be found, while it existed in that directory. I found the solution that worked here: http://code.google.com/p/android/issues/detail?id=5000
Basically just coping the file : cp /Developer/usr/lib/gcc/i686-apple-darwin10/4.0.1/include/stdarg.h /Developer/SDKs/MacOSX10.4u.sdk/usr/include/stdarg.h
allowed me to proceed further.

* The next problem was a error during compilation of google V8 javascript engine. I went ahead deleted the external/v8 folder and took the latest stable version from google repository: "svn checkout http://v8.googlecode.com/svn/trunk/ v8". As long as V8 compiled and run I was fine with this change in my tree.

* The next error that you would get is
host C++: libacc <= system/core/libacc/acc.cpp
system/core/libacc/acc.cpp: In member function ‘bool acc::Compiler::acceptStringLiteral()’:
system/core/libacc/acc.cpp:4611: error: cast from ‘char*’ to ‘int’ loses precision
system/core/libacc/acc.cpp: In member function ‘void acc::Compiler::unary()’:
system/core/libacc/acc.cpp:4691: error: cast from ‘char*’ to ‘int’ loses precision
system/core/libacc/acc.cpp:4697: error: cast from ‘char*’ to ‘int’ loses precision
system/core/libacc/acc.cpp:4785: error: cast from ‘void*’ to ‘int’ loses precision
system/core/libacc/acc.cpp: In member function ‘void acc::Compiler::globalDeclarations()’:
system/core/libacc/acc.cpp:5904: error: cast from ‘void*’ to ‘int’ loses precision
make: *** [out/host/darwin-x86/obj/STATIC_LIBRARIES/libacc_intermediates/acc.o] Error 1

replace cast from int to size_t in these lines


* After all these steps I was able to built the whole tree fine.

The fix for the last problem I found on:
http://wisevishvesh.wordpress.com/2010/04/12/building-eclair-on-snow-leopard/

* And here is some more of useful information I found on that blog:
Creating and Extracting files from System Image
There are two executable that are needed for creating system image and for extracting the files from the system image. mkyaffs2image is for creating and unyaffs is for extracting files. mkyaffs2image is created when Android is built, We have to build unyaffs separately.
The source unyaffs for is available here
Compile the file
gcc -o unyaffs unyaffs.c”


Hope you find this post helpful.

Good Luck!