读书人

[转]上载并编译Android 2.3源码

发布时间: 2012-09-25 09:55:59 作者: rapoo

[转]下载并编译Android 2.3源码
原文http://www.blogjava.net/TiGERTiAN/archive/2011/01/20/343283.html

前几天下载了Android 2.3.1的源代码并在Ubuntu 10.04(32位)上编译通过。这篇文章简要记录了下载、编译的过程。

关于搭建Android开发环境的文章已经有很多,本文只简要介绍一下,做为备忘。

[ 编译前的准备 ]

这一步安装获取源代码以及编译所需要的软件,使用如下命令:

$ sudo aptitude install git-core gnupg flex bison gperf libsdl-dev libesd0-dev libwxgtk2.6-dev build-essential zip curl libncurses5-dev zlib1g-dev
另外,参考别人编译Android 2.3的经验,安装了下列软件包:

$ sudo apt-get install lib64z1-dev libc6-dev-amd64 g++-multilib lib64stdc++6
虽然Android官方网站上讲不支持Java 6,不过我使用Java 6也可以编译通过,所以在这里Easwy安装的是Java 6。首先去掉/etc/apt/sources.list中这两行的注释,使能Java 6源:

deb http://archive.canonical.com/ubuntu lucid partner
deb-src http://archive.canonical.com/ubuntu lucid partner
然后安装Java 6 JDK:

$ sudo aptitude install sun-java6-jdk
接下来下载repo工具,这是Google提供的一个Python脚本,方便管理多个Git版本库:

$ cd ~
$ mkdir bin
$ curl http://android.git.kernel.org/repo >~/bin/repo
$ chmod a+x ~/bin/repo
记得把repo加到你的路径中,方便以后使用。编辑~/.bashrc,加入下面一行:

PATH=$PATH:~/bin
export PATH
然后用命令. ~/.bashrc,以后就可以直接使用repo命令了。

接下来获取Android 2.3.1的源代码:

$ mkdir mydroid
$ cd mydroid
$ repo init -u git://android.git.kernel.org/platform/manifest.git -b android-2.3.1_r1
$ repo sync
[ 编译Android ]

接下来开始编译:

$ make -j`grep '^processor' /proc/cpuinfo | wc -l`
上面的命令中,-j参数告诉make启动多个并行任务进行编译,在支持多核的CPU上能加快编译速度。如果你知道你CPU是几核的,可以直接把这部分替换成-j2(双核)。

我在编译的过程中遇到下面的错误:

************************************************************

You are attempting to build on a 32-bit system.

Only 64-bit build environments are supported beyond froyo/2.2.

************************************************************

这是因为在Makefile中检测了CPU的字长。我直接把build/core/main.mk中下面的话注释掉:

#ifneq (64,$(findstring 64,$(build_arch)))
#$(warning ************************************************************)
#$(warning You are attempting to build on a 32-bit system.)
#$(warning Only 64-bit build environments are supported beyond froyo/2.2.)
#$(warning ************************************************************)
#$(error stop)
#endif
接下来又遇到下面的错误:

Docs droiddoc: out/target/common/docs/api-stubs

Could not load ‘clearsilver-jni’

java.library.path = out/host/linux-x86/lib

make: *** [out/target/common/docs/api-stubs-timestamp] Error 45

make: *** Waiting for unfinished jobs….

Could not load ‘clearsilver-jni’

java.library.path = out/host/linux-x86/lib

make: *** [out/target/common/docs/doc-comment-check-timestamp] Error 45

这是由于clearsilver在编译时如果检测到使用Java JDK 6,就使用64位编译。要避开此错误,需要修改下面四个文件:

external/clearsilver/cgi/Android.mk
external/clearsilver/java-jni/Android.mk
external/clearsilver/util/Android.mk
external/clearsilver/cs/Android.mk
把这四个Makefile中的下列语句注掉即可:

# This forces a 64-bit build for Java6
# Comment by Easwy
# LOCAL_CFLAGS += -m64
# LOCAL_LDFLAGS += -m64
然后在external/clearsilver目录中执行一下make clean,然后回到项目根目录,继续make即可。

当编译完成时,生成的image文件放在out/target/product/generic目录中。
This is a special variation of mmm which is used to build frameworks/base/core/java.

To sync these changes you must restart the running framework and sync, as with this handy sequence:

$ adb remount
$ adb shell stop
$ adb sync
$ adb shell start

Finally, to debug your changes you can use the DDMS tool to select a process for debug and then attach Eclipse to it. If you have the Eclipse Android Development plugin installed, there is a special DDMS perspective which you can use to choose the process for debug. To attach Eclipse to it, see these instructions:
http://source.android.com/using-eclipse

This document also describes how to use Eclipse for development. Any IDE should work with the proper finagling though. Just note that the IDE won’t really by an integrated environment, the final output of APKs, system.img, and even the generation of R.java files will have to be done by make!

A note about the processes in Android:

system_process houses all things under frameworks/base/services. This includes the PackageManagerService, StatusBarService, etc. It has many, many threads (one for each service, and then one main UI thread), so be wary when debugging.
com.android.acore hosts Launcher (home), Contacts, etc. You can determine the apps/providers that run here by looking forandroid:process="android.process.acore" in the various AndroidManifest.xml files in packages/.
Also remember that the “framework” (under frameworks/base/core/java) is not hosted by any one process. It is a library used by most processes, so to debug code there you can usually use a simple demo app that takes advantage of whatever you changed and debug that app’s process. A useful trick for setting up your debug connection is to call Debug.waitForDebugger() during some startup part of an application or system service. 3 楼 w11h22j33 2011-01-22 Get Android Source Code

读书人网 >Android

热点推荐