在x86的机器上编译使用Andorid

来源:互联网 发布:联合国工作 知乎 编辑:程序博客网 时间:2024/05/15 12:20

在x86的机器上编译使用Andorid
转自:http://www.cnbeta.com/articles/118504.htm

在X86的机器上编译安装android,做一个简单快速的上网本.我的编译环境为VMwave+ubuntu10.04,编译时对内存占用很大,建议多分一点儿,我分了1.5G.参考网站:
android-x86官方网站:http://www.android-x86.org/
Google OS实验室:http://blog.livedoor.jp/moonlight_aska/

一、编译环境配置:

1、安装必要组件
$ sudo apt-get update
$ sudo apt-get -y install git-core gnupg sun-java6-jdk flex bisongperf libsdl-dev libesd0-dev libwxgtk2.6-dev build-essential zipcurl libncurses5-dev zlib1g-dev valgrind

2、安装repo
$ cd ~
$ mkdir bin
$ curl http://android.git.kernel.org/repo> ~/bin/repo
$ chmod a+x ~/bin/repo
$ export PATH=$PATH:~/bin


二、获取android-x86源代码
$ mkdir android2.1
$ cd android2.1
$ repo init -u git://git.android-x86.org/platform/manifest.git -beclair-x86
$ repo sync

-b eclair-x86为制定版本,这里采用的是2.1-eclair来编译的

注:对于下载的时间,个人认为凌晨12点以后到中午12点之间速度较快。

三、开始编译,一般机器采用eeepc的模式编译。
$ cd android2.1
$ make iso_img TARGET_PRODUCT=eeepc

iso_img为打包为ISO镜像,如果想打包为USB镜像的话可以采用:
$ cd android2.1
$ make usb_img TARGET_PRODUCT=eeepc

错误修正:在编译的过程中碰到了几处错误,修改方法如下:

错误1、错误提示:
host Executable: aapt(out/host/linux-x86/obj/EXECUTABLES/aapt_intermediates/aapt)
/usr/bin/ld:out/host/linux-x86/obj/STATIC_LIBRARIES/libcutils_intermediates/libcutils.a(threads.o):in function thread_store_set:system/core/libcutils/threads.c:36:error: undefined reference to 'pthread_key_create'
/usr/bin/ld:out/host/linux-x86/obj/STATIC_LIBRARIES/libcutils_intermediates/libcutils.a(threads.o):in function thread_store_set:system/core/libcutils/threads.c:44:error: undefined reference to 'pthread_setspecific'
/usr/bin/ld:out/host/linux-x86/obj/STATIC_LIBRARIES/libcutils_intermediates/libcutils.a(threads.o):in function thread_store_get:system/core/libcutils/threads.c:27:error: undefined reference to 'pthread_getspecific'
collect2: ld returned 1 exit status
make: ***[out/host/linux-x86/obj/EXECUTABLES/aapt_intermediates/aapt] 错误1

解决方法:修改./framework/base/tools/aapt/Android.mk文件
LOCAL_LDLIBS := -lz
ifeq ($(HOST_OS),linux)
-LOCAL_LDLIBS += -lrt
+LOCAL_LDLIBS += -lrt -lpthread
endif
ifeq ($(HOST_OS),windows)

错误2、错误提示:
host C++: acc <=system/core/libacc/tests/main.cpp
host C++: libacc <= system/core/libacc/acc.cpp
host SharedLib: libacc (out/host/linux-x86/obj/lib/libacc.so)
host Executable: acc(out/host/linux-x86/obj/EXECUTABLES/acc_intermediates/acc)
/usr/bin/ld:out/host/linux-x86/obj/EXECUTABLES/acc_intermediates/main.o: infunction symbolLookup(void*, charconst*):system/core/libacc/tests/main.cpp:41: error: undefinedreference to 'dlsym'
collect2: ld returned 1 exit status
make: ***[out/host/linux-x86/obj/EXECUTABLES/acc_intermediates/acc] 错误 1

解决方法:修改./system/core/libacc/tests/Android.mk文件
LOCAL_SHARED_LIBRARIES :=
libacc
+LOCAL_LDLIBS := -ldl
#LOCAL_MODULE_TAGS := tests
LOCAL_SHARED_LIBRARIES :=
libacc
+LOCAL_LDLIBS := -ldl
LOCAL_CFLAGS := -O0 -g
LOCAL_SHARED_LIBRARIES :=
libacc
+LOCAL_LDLIBS := -ldl
LOCAL_MODULE_TAGS := tests
LOCAL_SHARED_LIBRARIES :=
libacc
+LOCAL_LDLIBS := -ldl
LOCAL_CFLAGS := -O0 -g

错误3、错误提示:
host Executable: localize(out/host/linux-x86/obj/EXECUTABLES/localize_intermediates/localize)
/usr/bin/ld:out/host/linux-x86/obj/STATIC_LIBRARIES/libcutils_intermediates/libcutils.a(threads.o):in function thread_store_set:system/core/libcutils/threads.c:36:error: undefined reference to 'pthread_key_create'
/usr/bin/ld:out/host/linux-x86/obj/STATIC_LIBRARIES/libcutils_intermediates/libcutils.a(threads.o):in function thread_store_set:system/core/libcutils/threads.c:44:error: undefined reference to 'pthread_setspecific'
/usr/bin/ld:out/host/linux-x86/obj/STATIC_LIBRARIES/libcutils_intermediates/libcutils.a(threads.o):in function thread_store_get:system/core/libcutils/threads.c:27:error: undefined reference to 'pthread_getspecific'
collect2: ld returned 1 exit status
make: ***[out/host/linux-x86/obj/EXECUTABLES/localize_intermediates/localize]错误 1

解决方法:修改./framework/base/tools/localize/Android.mk文件
libcutils
ifeq ($(HOST_OS),linux)
-LOCAL_LDLIBS += -lrt
+LOCAL_LDLIBS += -lrt -lpthread
endif

编译成功后,可在out/target/product/eeepc/eeepc.iso找到ISO镜像,用虚拟机载入该镜像即可。

已知不完善的地方,gapps安装后会FC,电子市场FC

键位绑定:

鼠标左键:点击
鼠标中键:menu
鼠标右键/键盘ESC:返回
键盘Home键:home键


================================================
补充:
1. 下载的过程比较痛苦,因为下载速度很慢,而且容易断网。后来发现凌晨到上午这段时间比较快。虽然断网现象仍在,但速度快了很多。

2. 上面的变异并没有遇到错误,可能是改正过来了吧。

3. 在本机上实验generic_x86

Choose a target
You need to choose a target for the x86 device you want touse/test. We provides several targets for different branches:

donut-x86
eeepc: for ASUS EeePC family
q1u: for Samsung Q1U
s5: for Viliv S5

eclair-x86
generic_x86: for generic x86 PC/notebook
eeepc: for ASUS EeePC family only
q1u: for Samsung Q1U
s5: for Viliv S5

froyo-x86
generic_x86: for generic x86 PC/notebook
eeepc: for ASUS EeePC family only
vm: for virtual machine (virtual box, qemu, vmware)

Actually, for historical reason, you have to use eeepc for ageneric x86 PC, notebook or netbook before (includes) donut-x86branch. Since eclair-x86 branch, eeepc is changed to serve ASUSEeePC family only. Do not use it if you are not using anEeePC.
In short, if you don't know how to choose, use eeepc for donut-x86branch, and use generic_x86 for eclair-x86 or later branches.

If the computer you build on has more then one processor orcore, you can take advantage of multiprocessing (or make jobs) byadding -jX to the beginning of your make command:
$ make -jX usb_img TARGET_PRODUCT=eeepc

Replace X by the number of processors you have. For example, ifyou have a quad core CPU, replace X with 4:
$ make -j4 usb_img TARGET_PRODUCT=eeepc

根据上面的提示,eclair-x86以后版本都可以使用generic_x86作为TARGET_PRODUCT,但是从哪个网站上看见说这个iso只能用于虚拟机,没有验证过,所以不知道真假。
make iso_img TARGET_PRODUCT=generic_x86

遇见错误及解决:
target StaticLib: libwebcore(out/target/product/sapphire-open/obj/STATIC_LIBRARIES/libwebcore_intermediates/libwebcore.a)
make: execvp: /bin/bash: Argument list too long(中文的错误信息是"参数列项目过长")
make: ***[out/target/product/sapphire-open/obj/STATIC_LIBRARIES/libwebcore_intermediates/libwebcore.a]
解决:
cd external/webkit
git cherry-pick 18342a41ab72e2c21931afaaab6f1b9bdbedb9fa
信息提示:
root@ubuntu:~/work/android-x86-21/external/webkit#git cherry-pick 18342a41ab72e2c21931afaaab6f1b9bdbedb9fa
Finished one cherry-pick.
[detached HEAD f0d0424] Fix spurious build breaks.
Author: Patrick Scott <phanna@android.com>
Committer: root <root@ubuntu.(none)>
Your name and email address were configured automaticallybased
on your username and hostname. Please check that they areaccurate.
You can suppress this message by setting them explicitly:

    gitconfig --global user.name "Your Name"
    git config--global user.email you@example.com

If the identity used for this commit is wrong, you can fix itwith:

    gitcommit --amend --author='Your Name<you@example.com>'

2 files changed, 28 insertions(+), 14 deletions(-)


继续编译,没再遇到问题,最后信息:
Total translation table size: 4495
Total rockridge attributes bytes: 1372
Total directory bytes: 3158
Path table size(bytes): 26
Done with: TheFile(s)                            Block(s)   254033
Writing:   EndingPadblock                        Start Block 254067
Done with: EndingPadblock                        Block(s)   150
Max brk space used 0
254217 extents written (496 MB)

在out/target/product/generic_x86/目录下生成genetic_x86.iso,及initrd.img/install.img/ramdisk.img/system.img等镜像文件。

0 0