ubuntu12.04编译android源码
要编译源码,只需在项目根目录下执行make
即可。
在32位系统上编译会报错
You are attempting to build on a 32-bit system.
Only 64-bit build environments are supported beyond froyo/2.2.
因为主线上android代码是默认在64位机器上编译的,所以需要修改.mk文件中的编译选项,首先是build/core/main.mk文件。
将
ifeq ($(BUILD_OS),linux)
build_arch := $(shell uname -m)
ifneq (64,$(findstring 64,$(build_arch)))
改成:
ifeq ($(BUILD_OS),linux)
build_arch := $(shell uname -m)
ifneq (i686,$(findstring i686,$(build_arch)))
除此之外,还需要将external/clearsilver/cgi/Android.mk、external/clearsilver/cs/Android.mk、external/clearsilver/java-jni/Android.mk、external/clerasilver/util/Android.mk这四个文件中的
# This forces a 64-bit build for Java6
LOCAL_CFLAGS += -m64
LOCAL_LDFLAGS += -m64
改成:
# This forces a 64-bit build for Java6
LOCAL_CFLAGS += -m32
LOCAL_LDFLAGS += -m32
即可。
编译需要使用gcc4.4版本,太高的gcc版本可能会在编译时报错。
sudo apt-get install gcc-4.4
sudo apt-get install g++-4.4
cd /usr/bin
sudo mv gcc gcc.bak
sudo ln -s gcc-4.4 gcc
/usr/bin$ sudo mv g++ g++.bak
/usr/bin$sudo ln -s g++-4.4 g++
修改完这些以后编译,在编译中还可能出现一个问题
host C++: libutils <= frameworks/base/libs/utils/RefBase.cpp
frameworks/base/libs/utils/RefBase.cpp: In member function ‘void android::RefBase::weakref_type::trackMe(bool, bool)’:
frameworks/base/libs/utils/RefBase.cpp:483:67: error: passing ‘const android::RefBase::weakref_impl’ as ‘this’ argument of ‘void android::RefBase::weakref_impl::trackMe(bool, bool)’ discards qualifiers [-fpermissive]
make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/libutils_intermediates/RefBase.o] 错误 1
这个问题可以通过修改frameworks/base/libs/utils/Android.mk中的
LOCAL_CFLAGS += -DLIBUTILS_NATIVE=1 $(TOOL_CFLAGS)
改成
LOCAL_CFLAGS += -DLIBUTILS_NATIVE=1 $(TOOL_CFLAGS) –fpermissive
最后再执行make
即可。