ubuntu 11.10(32位系统)下编译android源码

本文介绍在ubuntu 11.10系统下编译android 2.3.3源码,编译之前请确定上两篇文章(http://www.cnblogs.com/dwayne/archive/2011/11/16/2250732.htmlhttp://www.cnblogs.com/dwayne/archive/2011/11/11/2245383.html)中所需的准备工作已经成功完成。编译完成生成系统镜像文件,并在模拟器中运行。

准备工作完成后,开始编译工作。下载下来的源码有5G多,如果按照我之前写的获取源码的话,源码目录为~/Android/source

一、环境设置

wayne@wayne-pc:~/Android/source$ source build/envsetup.sh 
including device/htc/passion/vendorsetup.sh
including device/samsung/crespo/vendorsetup.sh
wayne@wayne-pc:~/Android/source$ lunch full-eng

在lunch时,如果提示permission denied权限不够的话,需要在源码根目录下执行,赋予目录下所有文件权限

wayne@wayne-pc:~/Android/source$ sudo chmod -R 777 *

这时候会lunch指令会打印出如下所示文段:

============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=2.3.3
TARGET_PRODUCT=full
TARGET_BUILD_VARIANT=eng
TARGET_SIMULATOR=false
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=arm
HOST_ARCH=x86
HOST_OS=linux
HOST_BUILD_TYPE=release
BUILD_ID=GRI40
============================================

一、开始编译

编译过程可能会出现许多错误而中止,在此wayne将会把所有遇到的问题以及解决方法一一贴出来,以供以后参考。

1.Q:

wayne@wayne-pc:~/Android/source$ make -j2
============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=2.3.3
TARGET_PRODUCT=full
TARGET_BUILD_VARIANT=eng
TARGET_SIMULATOR=false
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=arm
HOST_ARCH=x86
HOST_OS=linux
HOST_BUILD_TYPE=release
BUILD_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.mk
external/clearsilver/java-jni/Android.mk
external/clearsilver/util/Android.mk
external/clearsilver/cs/Android.mk

将其中的

LOCAL_CFLAGS += -m64
LOCAL_LDFLAGS += -m64

修改为

LOCAL_CFLAGS += -m32
LOCAL_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 directory
make: *** [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 errors
make: *** [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.img
Install system fs image: out/target/product/generic/system.img
Installed 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/generic
ANDROID_PRODUCT_OUT_BIN=~/Android/source/out/host/linux-x86/bin
export 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

加载上我们所编译出来的系统文件,终于出现了期待已久的模拟器:

ubuntu 11.10(32位系统)下编译android源码

到这里,源码编译就完成了,接下来就可以进行自己的改动测试了。依然,欢迎交流指正By wayne!

上一篇:Intel Optane P4800X评测(3):Windows绑核优化篇


下一篇:25 个精彩的 HTML 5 教程