Compiling Android SDK on Ubuntu 10.10 (Maverick Meerkat)
A lot of time passed since my previous post about Android platform compilation, and the build process has improved a bit since then (for sure it's a less frustrating experience now). Below is the up-to-date recipe for the SDK (master and froyo branches) build on Ubuntu 10.10. Please note, that although the sdk target is my focus (that is, the whole SDK package, including the platform, emulator and all the other tools like adb, ddms, etc.), the recipe is also perfectly useful if you want to build any part of the SDK alone, it's just necessary to use a different make target.
Compiling on Ubuntu 10.10 x86 (32-bit)
My first attempt to compile the master branch on my Ubuntu desktop revealed the following surprising requirement:
Checking build tools versions... build/core/main.mk:72: ************************************************************ build/core/main.mk:73: You are attempting to build on a 32-bit system. build/core/main.mk:74: Only 64-bit build environments are supported beyond froyo/2.2. build/core/main.mk:75: ************************************************************ build/core/main.mk:76: *** stop. Stop.
Indeed, a 64-bit version of Linux is necessary to build the master branch. I'm not sure what is the rationale for this requirement, address space limitation is an unlikely reason, also all the output binaries are 32-bit. The only track of this requirement I was able to find was this topic.
A 32-bit version of Ubuntu is still perfectly useful for building the froyo branch. Use the following command to install all the necessary packages:
codepainters@DroidBuntu32:~$ sudo apt-get install git-core bison g++ zlib1g-dev \
libncurses5-dev flex libx11-dev gperf
It's also necessary to install Java 5 SDK, which is no longer available as a package for Ubuntu 10.10. Fortunately, packages for the 9.04 release work just fine. Download the following files:
- sun-java5-bin_1.5.0-19-0ubuntu0.9.04_i386.deb
- sun-java5-demo_1.5.0-19-0ubuntu0.9.04_i386.deb
- sun-java5-jdk_1.5.0-19-0ubuntu0.9.04_i386.deb
- sun-java5-jre_1.5.0-19-0ubuntu0.9.04_all.deb
Install the packages with the following commands (unixodbc package is the SDK's requirement):
codepainters@DroidBuntu32:~$ sudo apt-get install unixodbc codepainters@DroidBuntu32:~$ sudo dpkg -i sun-java5-bin_1.5.0-19-0ubuntu0.9.04_i386.deb \ sun-java5-jre_1.5.0-19-0ubuntu0.9.04_all.deb \ sun-java5-demo_1.5.0-19-0ubuntu0.9.04_i386.deb \ sun-java5-jdk_1.5.0-19-0ubuntu0.9.04_i386.deb
Now it's necessary to select Java 5 SDK as a default one. Use update-java-alternatives -l to list all JDKs installed, then update-java-alternatives -s to select the right one:
codepainters@DroidBuntu32:~$ update-java-alternatives -l java-1.5.0-sun 53 /usr/lib/jvm/java-1.5.0-sun java-6-openjdk 1061 /usr/lib/jvm/java-6-openjdk codepainters@DroidBuntu32:~$ sudo update-java-alternatives -s java-1.5.0-sun
Alternatively, if you do not want to change the system-wide default, it's enough to set the PATH variable so JDK 1.5.0 is reachable first:
codepainters@DroidBuntu32:~$ export PATH=/usr/lib/jvm/java-1.5.0-sun/bin/:$PATH
Eventually we're ready to start the build. The following command takes about 1 hour on my Core2 Duo 2.4GHz with 2GB of RAM.
codepainters@DroidBuntu32:~$ make -j2 sdk
Compiling on Ubuntu 10.10 AMD64
Even on a 64-bit host, all the SDK binaries are built as 32-bit, thus it's necessary to install a few extra 32-bit libraries and other packages. Execute the following to install all the prerequisites:
codepainters@DroidBuntu32:~$ sudo apt-get install g++ g++-multilib libc6-dev-i386 \
lib32z1-dev lib32stdc++6 lib32ncurses5-dev openjdk-6-jdk bison flex gperf
Note, that OpenJDK 6 works perfectly fine for the master branch. Again, for the froyo branch it is necessary to use JDK 1.5.0. The same procedure can be used as for the 32-bit host, this time using the AMD64 packages:
- sun-java5-bin_1.5.0-19-0ubuntu0.9.04_amd64.deb
- sun-java5-demo_1.5.0-19-0ubuntu0.9.04_amd64.deb
- sun-java5-jdk_1.5.0-19-0ubuntu0.9.04_amd64.deb
- sun-java5-jre_1.5.0-19-0ubuntu0.9.04_all.deb
The rest of this recipe is exactly the same as for the 32-bit host. Remember to switch to Java 6 for the master branch and Java 5 for froyo, either using update-java-alternatives or by setting the PATH variable accordingly.
Windows
Compiling the SDK for Windows is a whole different story, apparently Google cross-compiles all the Windows binaries on Linux using the MinGW toolkit. It's easy to confirm the toolkit used by looking at the strings inside any of the Win32 binaries:
codepainters@DroidBuntu:~$ strings -a dexdump.exe | grep i586 | sort -u /usr/lib/gcc/i586-mingw32msvc/3.4.5/include/stdarg.h /usr/lib/gcc/i586-mingw32msvc/3.4.5/include/stddef.h /usr/lib/gcc/i586-mingw32msvc/4.2.1-sjlj/../../../../i586-mingw32msvc/include /usr/lib/gcc/i586-mingw32msvc/4.2.1-sjlj/../../../../i586-mingw32msvc/include/sys /usr/lib/gcc/i586-mingw32msvc/4.2.1-sjlj/include
Grepping through the build environment leads to development/build/tools/windows_sdk.mk which confirms that the build is performed on a Linux box:
# Makefile to build the Windows SDK under linux. # # This file is included by build/core/Makefile when a PRODUCT-sdk-win_sdk build # is requested. # # Summary of operations: # - create a regular Linux SDK # - build a few Windows tools # - mirror the linux SDK directory and patch it with the Windows tools # # This way we avoid the headache of building a full SDK in MinGW mode, which is # made complicated by the fact the build system does not support cross-compilation.
It is possible to use both 32-bit and 64-bit Ubuntu versions. Beside all the Linux build prerequisites described above, one has to install MinGW toolkit and dos2unix (note that if dos2unix is missing, the build environment incorrectly asks for tofrodos package):
codepainters@DroidBuntu32:~$ sudo apt-get install mingw32 dos2unix
Finally, we can build the Windows SDK with (note the special target - win_sdk):
codepainters@DroidBuntu32:~$ make -j2 win_sdk








November 23rd, 2010 - 22:28
I am using ubuntu 10.10 32 bit and performed the steps mentioned above. Still get the error
anil@anil-HP-EliteBook-8440p:~/android_src$ make -j2 sdk
============================================
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
TARGET_ARCH_VARIANT=armv5te
HOST_ARCH=x86
HOST_OS=linux
HOST_BUILD_TYPE=release
BUILD_ID=OPENMASTER
============================================
Checking build tools versions…
build/core/main.mk:72: ************************************************************
build/core/main.mk:73: You are attempting to build on a 32-bit system.
build/core/main.mk:74: Only 64-bit build environments are supported beyond froyo/2.2.
build/core/main.mk:75: ************************************************************
build/core/main.mk:76: *** stop. Stop.
November 25th, 2010 - 11:00
Well, perhaps I wasn’t clear enough in my post – you do need 64-bit environment to build post-froyo platform. At least officially – you may find build environment patches if you google a bit. There was a discussion recently on one of the android mailing lists about this issue, and it seems that Google switched to 64-bit internally and they just don’t want to support 32-bit environment anymore.
January 14th, 2011 - 07:01
Hi,
Thanks for the post above! Helped with the setup! Now gonna start my build. Gonna look for the patches for the 32-bit
January 22nd, 2011 - 00:33
Excellent this is a beautiful post. Accurate and easy to follow.