ubuntu 11.10(32位)下android2.2 源码编译

写在最前:用虚拟机装ubuntu,还下载android源码并且编译的,上辈子都是折翼的天使!!

为了编译的更加流畅,强烈要求虚拟机内存要至少1G、任务管理器中虚拟机进程优先级设置为实时

4、源码编译镜像文件

开始正式编译,在源码目录下make即可。

make

我完全不知道跑了个啥,只知道超级卡。完成后产生的out文件夹有3.9G

镜像生成在out/target/product/generic下:android源码编译后得到system.img,ramdisk.img,userdata.img映像文件。其中, ramdisk.imgemulator的文件系统,system.img包括了主要的包、库等文件,userdata.img包括了一些用户数据,emulator加载这3个映像文件后,会把 system userdata分别加载到 ramdisk文件系统中的system userdata目录下。

当然编译是件很痛苦的事情:

错误1

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

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

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

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

解决:

需要进行如下修改即可,将

./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

注释掉,或者将“64”换成“32”

LOCAL_CFLAGS += -m32

LOCAL_LDFLAGS += -m32

然后,将./build/core/main.mk 中的

ifneq (64,$(findstring 64,$(build_arch)))

改为:

ifneq (i686,$(findstring i686,$(build_arch)))

错误2

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

解决:

gedit frameworks/base/libs/utils/Android.mk

Change the line:

LOCAL_CFLAGS += -DLIBUTILS_NATIVE=1 $(TOOL_CFLAGS)

To:

LOCAL_CFLAGS += -DLIBUTILS_NATIVE=1 $(TOOL_CFLAGS) –fpermissive

错误3

 

host Executable: aapt (out/host/linux-x86/obj/EXECUTABLES/aapt_intermediates/aapt)

out/host/linux-x86/obj/STATIC_LIBRARIES/libcutils_intermediates/libcutils.a(threads.o): In function `thread_store_get':

/home/leno/works/android_dev/bin/system/core/libcutils/threads.c:27: undefined reference to `pthread_getspecific'

out/host/linux-x86/obj/STATIC_LIBRARIES/libcutils_intermediates/libcutils.a(threads.o): In function `thread_store_set':

/home/leno/works/android_dev/bin/system/core/libcutils/threads.c:36: undefined reference to `pthread_key_create'

/home/leno/works/android_dev/bin/system/core/libcutils/threads.c:44: undefined reference to `pthread_setspecific'

collect2: ld returned 1 exit status

make: *** [out/host/linux-x86/obj/EXECUTABLES/aapt_intermediates/aapt] 错误 1

解决:

打开 frameworks/base/tools/aapt/Android.mk

然后打开文件Android.mk,编辑下面一行:

ifeq ($(HOST_OS),linux)

#LOCAL_LDLIBS += -lrt       把这行注释掉,改为下面一行。

LOCAL_LDLIBS += -lrt -lpthread

endif

错误4

target Dex: core

#

# An unexpected error has been detected by HotSpot Virtual Machine:

#

#  SIGSEGV (0xb) at pc=0x4003d848, pid=7668, tid=2889534320

#

# Java VM: Java HotSpot(TM) Client VM (1.5.0_22-b03 mixed mode)

# Problematic frame:

# C  [libpthread.so.0+0xa848]  pthread_cond_timedwait+0x168

#

# An error report file with more information is saved as hs_err_pid7668.log

#

# If you would like to submit a bug report, please visit:

#   http://java.sun.com/webapps/bugreport/crash.jsp

#

make: *** [out/target/common/obj/JAVA_LIBRARIES/core_intermediates/classes.dex] 已放弃 (core dumped)

解决:

虚拟机给的内存512太小,给个1G试试。然后在本机里打开任务管理器,找到虚拟机进程,优先级设置为实时。给他最多东西。

错误 5

out/host/linux-x86/obj/STATIC_LIBRARIES/libcutils_intermediates/libcutils.a(threads.o): In function `thread_store_get':

/home/leno/works/android_dev/bin/system/core/libcutils/threads.c:27: undefined reference to `pthread_getspecific'

out/host/linux-x86/obj/STATIC_LIBRARIES/libcutils_intermediates/libcutils.a(threads.o): In function `thread_store_set':

/home/leno/works/android_dev/bin/system/core/libcutils/threads.c:36: undefined reference to `pthread_key_create'

/home/leno/works/android_dev/bin/system/core/libcutils/threads.c:44: undefined reference to `pthread_setspecific'

collect2: ld returned 1 exit status

make: *** [out/host/linux-x86/obj/EXECUTABLES/localize_intermediates/localize] 错误 1

解决:类似问题3

修改./framework/base/tools/localize/Android.mk文件

ifeq ($(HOST_OS),linux)

#LOCAL_LDLIBS += -lrt       把这行注释掉,改为下面一行。

LOCAL_LDLIBS += -lrt -lpthread

endif

 

5、编译SDK

执行$sudo make PRODUCT-sdk-sdk命令,生成对应于该版本源代码的用于生产环境的sdk

编译的SDK版本,实际位置是./out/host/linux-x86/sdk/android-sdk_eng.root_linux-x86

因为它比较常用,我们给它高优先级:

update-alternatives --install /usr/bin/AndroidSDK AndroidSDK ./out/host/linux-x86/sdk/android-sdk_eng.root_linux-x86 255

然后使用update-alternatives --display AndroidSDK查看当前配置情况;

如果要切换配置,使用update-alternatives --config AndroidSDK

配置AndroidSDK环境变量。终端中执行gedit ~/.bashrc

在文件最后添加下面三行:

# set android environment

export ANDROID_SDK_HOME=/usr/bin/AndroidSDK

export PATH=$ANDROID_SDK_HOME/tools:$PATH

保存文件。在终端中执行source ~/.bashrc

 

最近又编译了一次2.2sdk,但是在编译doc时,提示空指针,怎么都搞不定,求解。

最后使用的是jdk1.6编译的2.3的源码。 

6在模拟器中运行编译的镜像

打开终端,执行android脚本:

$android

选择左边第一项Virtual Devices,然后在右边选择New,新建一个AVD

NameAVD的名称,随便取,但只能包含字母和数字以及点、下划线和连字符,这里取名test

Traget:目标SDK版本,这里选自己编译的2.2Android SDK

SD CardSD卡。暂且不填,待需要时再设置。

Skin:皮肤(模拟器屏幕分辨率)。

Hardware:使用默认即可

然后点Create AVD,就创建好了一个AVD。点击Start

可启动模拟器,其运行的是自己编译的镜像。

posted @ 2011-09-08 14:41  欧零  阅读(7229)  评论(8编辑  收藏  举报