Wednesday, May 02, 2012

Bulding AOSP on Ubuntu 12.04

Update (July, 11, 2012):
Just built the Android 4.1.1 (Jelly Bean) branch from AOSP on Ubuntu 12 with no problems whatsoever. This makes this post no longer relevant.
Many thanks for that to Android development team.

//************************************************************************


I just started to play with Ubuntu 12.04 and stumbled on few issues while building Android source tree (AOSP master branch).

Here are few things that might be useful to know in order get AOSP building:

1. First, follow the instructions here http://source.android.com/source/initializing.html to install all the dependencies and set everything up.

2. Then install Sun JDK6, here is the link to the latest download at the moment:
http://www.oracle.com/technetwork/java/javase/downloads/jdk-6u32-downloads-1594644.html

After downloading it, execute these commands:

$ chmod u+x jdk-6u32-linux-x64.bin
$ ./jdk-6u32-linux-x64.bin
$ sudo mv jdk1.6.0_32 /usr/lib/jvm/
$ sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.6.0_32/bin/java" 1
$ sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.6.0_32/bin/javac" 1

then switch to this version of java with:
$ sudo update-alternatives --config java
and
$ sudo update-alternatives --config javac

You can probably get away with OpenJDK6 (disable the java version check in the build/core/main.mk). I remember I had a problem compiling one of the CTS tests and fixing that required some java code modifications.

3. The failure while building qtools build can be fixed with changing
common_cflags := -O0 -g 
to
common_cflags := -O0 -g -Wwrite-strings -fpermissive
in the sdks/emulator/qtools/Android.mk

4. The failure with OpenGL libraries linking can be fixed with 
sudo ln -s /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1 /usr/lib/libGL.so

5. The failure while building obbtool, can be fixed in the  
build/core/combo/HOST_linux-x86.mk file by changing the following line
HOST_GLOBAL_CFLAGS += -D_FORTIFY_SOURCE=0
to
HOST_GLOBAL_CFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0

6. The failure with:
make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/libMesa_intermediates/src/glsl/linker.o] Error 1
can be fixed with adding the 
#include <stddef.h>
at the top of the external/mesa3d/src/glsl/linker.cpp file.

7. The failure external/oprofile/libpp/format_output.h:94:22: error: reference ‘counts’ cannot be declared ‘mutable’ [-fpermissive]
can be fixed by changing the external/oprofile/libpp/format_output.h file
mutable counts_t & counts;
to 
counts_t & counts;

8. The failure external/gtest/src/../include/gtest/internal/gtest-param-util.h:122:11: error: ‘ptrdiff_t’ does not name a type
can be fixed by adding 
#include <cstddef>
into the external/gtest/src/../include/gtest/internal/gtest-param-util.h file. 

9. The failure /external/llvm/lib/Support/Mutex.cpp:143: undefined reference to `pthread_mutex_trylock'
collect2: ld returned 1 exit status
make: *** [out/host/linux-x86/obj/EXECUTABLES/test-librsloader_intermediates/test-librsloader] Error 1
can be fixed by adding 
LOCAL_LDLIBS := -lpthread -ldl 
into external/llvm/llvm-host-build.mk file.

10. For the failure frameworks/compile/slang/slang_rs_export_foreach.cpp:249:23: error: variable ‘ParamName’ set but not used [-Werror=unused-but-set-variable]
I just commented out that line since the ParamName is not used anyways.

This might not be the best solution, but it builds and leaves me some time to improve it if I need it.

Hope this saves you a bit of time.

6 comments:

Robgas said...

Hi Alex,
I have solved my problem with java uninstalling openjdk ( apt-get remove openjdk*) and setting

export ANDROID_JAVA_HOME=/usr/lib/jvm/jdk1.6.0_3
export PATH=$PATH:/usr/lib/jvm/jdk1.6.0_32/bin.

Alex said...

@Robgas: Yeah that would work too, though the steps I provided above allow you to keep openjdk and switch back and forth easily between different jdks any time as needed.

vidtrim said...

Very good guide. Thanks!

daljeet said...

Thanks Alex for putting this Blog.
It helped me to Compile my code on Ubuntu10.10.

mehdi said...

I am having one additional error:
external/clang/lib/Driver/Tools.cpp:1069:41: error: ‘OPT_fdwarf_directory_asm’ is not a member of ‘clang::driver::options’

How can I fix this?

Thanks

Mehdi

Alex said...

@mehdi: what tag or branch you are trying to build?