2012年7月5日 星期四

How to build Android under ubuntu 12.04 LTS 64bit version


Installing required packages (Ubuntu 12.04)

Building on Ubuntu 12.04 is currently only experimentally supported and is not guaranteed to work on branches other than master.
$ sudo apt-get install git-core gnupg flex bison gperf build-essential \
  zip curl libc6-dev libncurses5-dev:i386 x11proto-core-dev \
  libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-glx:i386 \
  libgl1-mesa-dev g++-multilib mingw32 openjdk-6-jdk tofrodos \
  python-markdown libxml2-utils xsltproc zlib1g-dev:i386
$ sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so

Then you need to do below change:
Simply change build/core/combo/HOST_linux-x86.mk line 61:

    -HOST_GLOBAL_CFLAGS += -D_FORTIFY_SOURCE=0
    +HOST_GLOBAL_CFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0

His commit message is as follows:

    HOST_linux-x86: Avoid doubly define macro _FORTIFY_SOURCE
    While building Android with latest host gcc,
    it causes the following build error:

    Install: out/host/linux-x86/bin/mkbootimg
    host C++: obbtool <= frameworks/base/tools/obbtool/Main.cpp
    :0:0: error: "_FORTIFY_SOURCE" redefined [-Werror]
    :0:0: note: this is the location of the previous definition
    cc1plus: all warnings being treated as errors

    In order to make build system happy, this patch does unset macro
    _FORTIFY_SOURCE and then define it in host cflags.

If there have below error log:

Host OS:
Linux 3.0.0-12-generic #20-Ubuntu SMP x86_64 GNU/Linux
gcc (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1

Compiling Android from git (master) stops with error:

android_repo/external/llvm/lib/Support/Threading.cpp:96: undefined reference to `pthread_create'
android_repo/external/llvm/lib/Support/Threading.cpp:91: undefined reference to `pthread_attr_setstacksize'
android_repo/external/llvm/lib/Support/Threading.cpp:100: undefined reference to `pthread_join'
out/host/linux-x86/obj/STATIC_LIBRARIES/libLLVMSupport_intermediates/libLLVMSupport.a(Mutex.o): In function `MutexImpl':
android_repo/external/llvm/lib/Support/Mutex.cpp:69: undefined reference to `pthread_mutexattr_init'
android_repo/external/llvm/lib/Support/Mutex.cpp:75: undefined reference to `pthread_mutexattr_settype'
android_repo/external/llvm/lib/Support/Mutex.cpp:80: undefined reference to `pthread_mutexattr_setpshared'
android_repo/external/llvm/lib/Support/Mutex.cpp:89: undefined reference to `pthread_mutexattr_destroy'
out/host/linux-x86/obj/STATIC_LIBRARIES/libLLVMSupport_intermediates/libLLVMSupport.a(Mutex.o): In function `llvm::sys::MutexImpl::tryacquire()':
android_repo/external/llvm/lib/Support/Mutex.cpp:143: undefined reference to `pthread_mutex_trylock'
collect2: ld returned 1 exit status

Solution:


Add "LOCAL_LDLIBS := -lpthread -ldl" in external/llvm/llvm-host-build.mk
Have Fun!!

沒有留言: