Building Eclair on Snow Leopard

Please refer to this page for issues and solutions related to building Froyo on Snow Leopard.

This is a step wise guide on building Eclair on Snow Leopard. The intention of writing this post is to have a single information source for building Eclair on Snow Leopard. In the procedure, that I have listed down, I am not using the patch which allows android to use Java 1.6. If you want to use Java 1.6 please refer to this link.

Before starting on this, I would like to thank Shivanand P.B., Mithun Kamath, Tomas Isdal, Vijayashree, Vinay Betagiri and Bharat Pawar for all the help they have provided me in building Android.

So I will note down all the steps involved in building Eclair on Snow leopard. You can refer android get source page for information. I have referred it for few of the steps involved in building android.

Step 1
Create a new partition that is a case-sensitive partition if you’re using a case-insensitive primary partition. You can refer to this for more info.

Step 2
You would also have to install Xcode 3.2 and 10.4 SDK. Xcode can be found in the installation disc. It can also be downloaded from Apple developers connection. Refer the attached image.

Xcode installation Option

Step 3
Install Macports. There are two ways of doing so.
i. Download the source from this link and untar the file. Run the following commands
./configure
make
sudo make install

My preferred method is to download the DMG from here. I used MacPorts-1.8.2-10.6-SnowLeopard.dmg from the the list.

Step 4
Make sure that /opt/local/bin is in your path before /usr/bin. by running
$ echo $PATH
If you don’t see /opt/local/bin, edit $HOME/.bash_profile and add the line
export PATH=/opt/local/bin:$PATH
(or the equivalent for other shells) after any other PATH-related lines. To verify that your path is now correct, open a new terminal and run echo $PATH again.

Step 5
Ask MacPorts to update itself:
sudo port selfupdate

Step 6
Get the following packages from port:
POSIXLY_CORRECT=1 sudo port install libsdl git-core gnupg

NOTE: Restart the terminal

Step 7
To build android we need bison version 2.3. To check the version Type “bison –version” in the terminal, if the version is not 2.3, download bison version 2.3 from here. Macport installs bison 2.4.1 so you would have to do it manually. If you have a newer version of bison, you should remove it(port uninstall bison) and re-install bison 2.3.

NOTE: Restart the terminal

Step 8
Set an appropriate per-process file descriptor limit. To do this, add the following lines to your .bash_profile file:
# set the number of open files to be 1024
ulimit -S -n 1024

Step 9
Now check out the Eclair Source code to the case-sensitive partition created in step 1, please refer android get source page for more information

Step 10
Snow leopard doesn’t have Java 1.5 since it supports Java 1.6. It’s times to play with the frameworks. We would have to install Java 1.5. If you are using Leopard(10.5) you can skip this step, since Leopard has Java 1.5.

You would have to do the following steps on the terminal.

curl -o java.1.5.0-leopard.tar.gz http://www.cs.washington.edu/homes/isdal/snow_leopard_workaround/java.1.5.0-leopard.tar.gz
tar -xvzf java.1.5.0-leopard.tar.gz
sudo mv 1.5.0 /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0-leopard
cd /System/Library/Frameworks/JavaVM.framework/Versions/
sudo rm 1.5.0
sudo ln -s 1.5.0-leopard 1.5.0

Step 11
We have to set Java preferences. You can either manually open “Java Preferences.app” or use terminal and type

open /Applications/Utilities/Java\ Preferences.app

Change the preference to as shown in the image below. You can drag and drop different Java version to change the preference.

Setting Java Preferences

NOTE: Restart the terminal

Step 12
Change the gcc alias. This is needed by Qemu.

sudo rm /usr/bin/gcc
sudo ln -s /usr/bin/gcc-4.0 /usr/bin/gcc

NOTE: Restart the terminal

Building the source and resolving errors

Build the source.

make -j2

You would get following error.

host C: emulator <= external/qemu/distrib/zlib-1.2.3/gzio.c
In file included from external/qemu/distrib/zlib-1.2.3/gzio.c: 601 : In file included from external /qemu/distrib / zlib-1.2.3/gzio.c: 601:
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/stdarg.h: 4 : 25 : error: stdarg.h: No such file or directory / Developer/SDKs/MacOSX10.4u.sdk/usr/include/stdarg.h: 4: 25: error: stdarg.h: No such file or directory
make: *** [ out/host/darwin-x86/obj/EXECUTABLES/emulator_intermediates/distrib/zlib-1.2.3/gzio.o ] make: *** [out/host/darwin-x86/obj/EXECUTABLES/emulator_intermediates/distrib/zlib-1.2.3/gzio.o] 1 error

To fix this error go to “external/qemu/” and open Makefile.Android file and edit the following line

MY_CC := $(HOST_CC)

to

MY_CC := gcc

try building again.

You might come across this error

external/yaffs2/yaffs2/utils/mkyaffs2image.c: In function ‘main’:
external/yaffs2/yaffs2/utils/mkyaffs2image.c: 482 : error: ‘convert_endian’ undeclared ( first use in this function ) external/yaffs2/yaffs2/utils/mkyaffs2image.c: 482: error: ‘convert_endian’ undeclared (first use in this function)
make: *** [ out/host/darwin-x86/obj/EXECUTABLES/mkyaffs2image_intermediates/yaffs2/utils/mkyaffs2image.o ]
make: *** [out/host/darwin-x86/obj/EXECUTABLES/mkyaffs2image_intermediates/yaffs2/utils/mkyaffs2image.o] 1 error

To fix this error go to “external/yaffs2/yaffs2/utils/” and open the file “mkyaffs2image.c”

You will find this code

#ifdef HAVE_BIG_ENDIAN
static int convert_endian = 1;
#elif defined(HAVE_LITTLE_ENDIAN)
static int convert_endian = 0;
#endif

replace it with

#ifdef HAVE_BIG_ENDIAN
static int convert_endian = 1;
#elif defined(HAVE_LITTLE_ENDIAN)
static int convert_endian = 0;
#else
static int convert_endian = 0 ;
#endif

try building again. This time you would face the following errors

system/core/libacc/acc.cpp: In member function ‘bool acc::Compiler::acceptStringLiteral()’:
system/core/libacc/acc.cpp:4557: 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:4637: error: cast from ‘char*’ to ‘int’ loses precision
system/core/libacc/acc.cpp:4643: error: cast from ‘char*’ to ‘int’ loses precision
system/core/libacc/acc.cpp:4731: 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:5740: error: cast from ‘void*’ to ‘int’ loses precision

To fix these go to “system/core/libacc/” and open the file “acc.cpp”
go to the line numbers 4557, 4637, 4643, 4731, 5740 and replace the integer type casting i.e (int) to (size_t) in these line.

Now try building again. This time it should build successfully.

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”

Advertisements

19 thoughts on “Building Eclair on Snow Leopard

  1. Pingback: Building Froyo on Snow Leopard « Vishvesh's Blog

    • And skip steps 8, 9 and 13 as well, and please update step 11 as it’s out of date and not pointing to Apple but a third party site.

      Also despite your praise, the build process is still broken if you’re building for an adp device. You are still out of luck without some additional work…

      I’m guessing it may also be broken for SDK if you’re up to date with Apple’s OS updates and the latest SDKs (XCode and Java), let us know if that’s the case.

      I’m basically not advising to do Android source builds on a Mac, but in a Linux VM (and not yet for ADP1 and ADP2)

      • The steps 8,9 and 13 were done on my machine for building Eclair. So I didn’t have to change them again. I will undo the changes and give the build a shot again.

        I have been intending to try out flashing the OS to an ADP, but never gave it a try. I will give it a shot and post the results.

        Back to step 11 : Java issues
        I downloaded the dmg file for Java 1.5 but it didn’t install on my machine, since the dmg file was looking for OS version less than 10.6. That rules out using Apple’s Java releases. I do hope android starts using Java 1.6.

        You are right about the updates, Every time I upgrade my OS or Xcode I have to redo the changes.

        I think Linux is the best place to do android build.

  2. Hi,

    Thank you very much for this info. I was trying to compile for weeks on my Snow Leopard, but always returned to Linux VM to get work done. Now I can complete recovery development with my MacBook.

    Some notes to update your great tutorial.
    1.- To avoid Java 1.5 installation problems, you can use Java 1.6. But “build/core/main.mk” must be modified to check for 1.6 instead of 1.5. Search for “grep ‘[ “]1\.5” into that file and change that “5” with a “6”. You’ll find it repeated two times.

    2.- I had to change “MY_CC := gcc” with “MY_CC := gcc-4.0” to avoid “stdarg.h” error.

    3.- I didn’t need to make “acc.cpp” changes. Maybe that was fixed.

    4.- Rosetta isn’t needed if you substitute AOSP prebuilt flex binary with a link to XCode flex utility. The reason is AOSP flex included binary was compiled for PPC, not Intel.

    All other info worked fine. Thank you again.

    • I am very glad it worked out well for you. 🙂

      1. Java tip is a good one. I will try it someday.

      3. “acc.cpp” changes are needed on 64 bit machines and the issue has been resolved by Google for Froyo at least.

      4. Rosetta is not needed I intend to take it off.

      And thank you very much for the feedback.

  3. I get the following error, and there is no longer those tools with 4.2 sdk

    Please install the 10.4 SDK on this machine at /Developer/SDKs/MacOSX10.4u.sdk
    external/qemu/Makefile.android:65: *** Aborting the build.. Stop.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s