原文网址:http://www.cnblogs.com/dwayne/archive/2011/11/16/2251734.html
本文介绍在ubuntu 11.10系统下编译android 2.3.3源码,编译之前请确定上两篇文章(http://www.cnblogs.com/dwayne/archive/2011/11/16/2250732.html和http://www.cnblogs.com/dwayne/archive/2011/11/11/2245383.html)中所需的准备工作已经成功完成。编译完成生成系统镜像文件,并在模拟器中运行。
准备工作完成后,开始编译工作。下载下来的源码有5G多,如果按照我之前写的获取源码的话,源码目录为~/Android/source
一、环境设置
[email protected]:~/Android/source$ source build/envsetup.sh including device/htc/passion/vendorsetup.shincluding device/samsung/crespo/vendorsetup.sh[email protected]:~/Android/source$ lunch full-eng
在lunch时,如果提示permission denied权限不够的话,需要在源码根目录下执行,赋予目录下所有文件权限
[email protected]:~/Android/source$ sudo chmod -R 777 *
这时候会lunch指令会打印出如下所示文段:
============================================PLATFORM_VERSION_CODENAME=RELPLATFORM_VERSION=2.3.3TARGET_PRODUCT=fullTARGET_BUILD_VARIANT=engTARGET_SIMULATOR=falseTARGET_BUILD_TYPE=releaseTARGET_BUILD_APPS=TARGET_ARCH=armHOST_ARCH=x86HOST_OS=linuxHOST_BUILD_TYPE=releaseBUILD_ID=GRI40============================================
一、开始编译
编译过程可能会出现许多错误而中止,在此wayne将会把所有遇到的问题以及解决方法一一贴出来,以供以后参考。
1.Q:
[email protected]:~/Android/source$ make -j2============================================PLATFORM_VERSION_CODENAME=RELPLATFORM_VERSION=2.3.3TARGET_PRODUCT=fullTARGET_BUILD_VARIANT=engTARGET_SIMULATOR=falseTARGET_BUILD_TYPE=releaseTARGET_BUILD_APPS=TARGET_ARCH=armHOST_ARCH=x86HOST_OS=linuxHOST_BUILD_TYPE=releaseBUILD_ID=GRI40============================================Checking build tools versions...build/core/main.mk:76: ************************************************************build/core/main.mk:77: You are attempting to build on a 32-bit system.build/core/main.mk:78: Only 64-bit build environments are supported beyond froyo/2.2.build/core/main.mk:79: ************************************************************build/core/main.mk:80: *** stop。 停止。
解决方法:cd到源码根目录,执行:
$ gedit build/core/main.mk
找到
ifneq (64,$(findstring 64,$(build_arch)))
将其修改为
ifneq (i686,$(findstring i686,$(build_arch)))
然后依次修改以下四个make文件:
external/clearsilver/cgi/Android.mkexternal/clearsilver/java-jni/Android.mkexternal/clearsilver/util/Android.mkexternal/clearsilver/cs/Android.mk
将其中的
LOCAL_CFLAGS += -m64LOCAL_LDFLAGS += -m64
修改为
LOCAL_CFLAGS += -m32LOCAL_LDFLAGS += -m32
2.Q:
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] Error 1
解决方法:
$ gedit frameworks/base/libs/utils/Android.mk
修改以下语句
LOCAL_CFLAGS += -DLIBUTILS_NATIVE=1 $(TOOL_CFLAGS)
为
LOCAL_CFLAGS += -DLIBUTILS_NATIVE=1 $(TOOL_CFLAGS) –fpermissive
3.Q:
arm-eabi-gcc: error trying to exec ‘cc1‘: execvp: No such file or directorymake: *** [out/target/product/generic/obj/lib/crtbegin_dynamic.o] Error 1
如果之前的依赖包都已经安装成功的话,此处应该是交叉编译工具权限的问题。这个问题只要在文章开头lunch时执行了赋予权限命令,就应该不会遇到了。
4.Q:
<command-line>:0:0: error: "_FORTIFY_SOURCE" redefined [-Werror] <built-in>:0:0: note: this is the location of the previous definition cc1plus: all warnings being treated as errorsmake: *** [out/host/linux-x86/obj/EXECUTABLES/obbtool_intermediates/Main.o] Error 1
此处编译错误是由于ubuntu 11.10采用了GCC4.6.1导致的。
解决方法:
修改源码目录下/build/core/combo/HOST_linux-x86.mk文件:
将以下语句
HOST_GLOBAL_CFLAGS += -D_FORTIFY_SOURCE=0
修改为
HOST_GLOBAL_CFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0
编译时还有可能出现类似的错误,根据错误提示的关键词比如g++错误、jre错误等,都是些细节问题,比较好解决。
经过两小时左右的等待后,终于顺利完成。编译成功后会生成system.img等镜像文件,下面是编译完成提示:
Target system fs image: out/target/product/generic/obj/PACKAGING/systemimage_intermediates/system.imgInstall system fs image: out/target/product/generic/system.imgInstalled file list: out/target/product/generic/installed-files.txt
三、启动所编译的系统
编译完之后会在out/target/product/generic目录下生成system.img ramdisk.img userdata.img三个镜像文件。
在启动模拟器之前,需要先为模拟器系统设置环境变量,执行gedit ~/.bashrc,新增环境变量如下:
export ANDROID_PRODUCT_OUT=~/Android/source/out/target/product/genericANDROID_PRODUCT_OUT_BIN=~/Android/source/out/host/linux-x86/binexport PATH=${PATH}:${ANDROID_PRODUCT_OUT_BIN}:${ANDROID_PRODUCT_OUT};
最后,同步这些变化并启动模拟器:
$ source ~/.bashrc$ cd ~/Android/source/out/target/product/generic$ emulator -system system.img -data userdata.img -ramdisk ramdisk.img