1. 编译环境配置
参考来源: http://source.android.com/source/initializing.html 或是网上google。
usb部分我是这么配置的:
执行lsusb 差看当前链接到系统的usb设备:
$lsusb
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 002: ID 093a:2510 Pixart Imaging, Inc. Optical Mouse
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 003: ID 0bb4:0c87 High Tech Computer Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
新增或编辑/etc/udev/init.d/51-android.rules 配置:
$sudo touch /etc/udev/init.d/51-android.rules
$sudo gedit /etc/udev/init.d/51-android.rules
增加如下内容(我的手机是htc的, 所以找到High Tech Computer Corp 的idVendor,其他的类似):
SUBSYSTEM=="usb|usb_device", SYSFS{idVendor}=="0bb4", MODE="0666"
重启udev:
$sudo service udev restart
关闭adb:
$ ./adb kill-server
列出设备:
$ ./adb devices
java部分我是自己从网上下载,然后手动安装的,没有按照google的文档来安装的,这个也可以google的到。
2. 下载gingerbread代码:
参考来源: http://source.android.com/source/downloading.html
下载repo:
$ mkdir ~/bin
$ PATH=~/bin:$PATH
$ curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo
$ chmod a+x ~/bin/repo
创建工作目录:
$ mkdir WORKING_DIRECTORY
$ cd WORKING_DIRECTORY
初始化 repo:
$ repo init -u https://android.googlesource.com/platform/manifest -b gingerbread
同步源代码:
$ repo sync
这个阶段时间比较久,网速不行的,就等着痛苦吧,如果失败,从新执行 repo sync
3. 编译&执行:
说实话,这个阶段的痛苦程度仅次于下载源代码。
初始化编译环境:
$ source build/envsetup.sh
或
$ . build/envsetup.sh
$ lunch full-eng
google也给出了这个参数的具体意义,详情请参考 “参考来源”。
编译:
$ make
google也给出了 make -jn 其中n表示n个线程来编译,本人经验,最好别用。
接下来就是长时间的等待,如果机器好的话,半个小时左右就可以编译ok了。
编译成功后,会有如下提示:
Target system fs image: out/target/product/generic/obj/PACKAGING/systemimage_intermediates/system.img
Install system fs image: out/target/product/generic/system.img
Target ram disk: out/target/product/generic/ramdisk.img
Target userdata fs image: out/target/product/generic/userdata.img
Installed file list: out/target/product/generic/installed-files.txt
运行模拟器:
$ ./out/host/linux-x86/bin/emulator -partition-size 256 -kernel prebuilt/android-arm/kernel/kernel-qemu-armv7 -sysdir ~/android/google/gingerbread/out/target/product/generic -system ~/android/google/gingerbread/out/target/product/generic/system.img -data ~/android/google/gingerbread/out/target/product/generic/userdata.img -ramdisk ~/android/google/gingerbread/out/target/product/generic/ramdisk.img -debug-init
其中具体路径根据具体的工作目录而变动即可。
下过如下:
当然事情不会有那么顺利
编译后运行结果其实是这样的:
下面介绍下如何处理:
参考来源:http://source.android.com/source/known-issues.html
官方给出的解释是由于模拟器太旧了,真是搞不懂,都找到原因了,为什么还不再主干上修改正呢?
如下操作:
$ repo forall external/qemu -c git checkout aosp/tools_r12
$ make
$ ./out/host/linux-x86/bin/emulator -partition-size 256 -kernel prebuilt/android-arm/kernel/kernel-qemu-armv7 -sysdir ~/android/google/gingerbread/out/target/product/generic -system ~/android/google/gingerbread/out/target/product/generic/system.img -data ~/android/google/gingerbread/out/target/product/generic/userdata.img -ramdisk ~/android/google/gingerbread/out/target/product/generic/ramdisk.img -debug-init
奇怪问题1:
在 repo forall external/qemu -c git checkout aosp/tools_r12 后出现:
build/core/base_rules.mk:162: *** sdk/monkeyrunner/etc:
MODULE.HOST.EXECUTABLES.monkeyrunner already defined by development/
tools/monkeyrunner/etc. Stop.
解决方法:
$repo forall external/qemu -c git checkout aosp/tools_r12
$rm -rf out
$source build/envsetup.sh
$lunch full-eng
$make
奇怪问题2:
即使 repo forall external/qemu -c git checkout aosp/tools_r12 也做了, make也成功了,还是黑屏。
查看下你用的kernel -kernel prebuilt/android-arm/kernel/kernel-qemu-armv7 是不是这个,我之前用的是
自己编译的kernel,怎么折腾都是黑屏,搞不懂啊。但是为用官方发布的emulator是可以跑的。
下面是管法emulator的版本:
$ emulator -version
Android emulator version 16.0 (build_id ICS_MR0-234950)
Copyright (C) 2006-2011 The Android Open Source Project and many others.
This program is a derivative of the QEMU CPU emulator (www.qemu.org).
This software is licensed under the terms of the GNU General Public
License version 2, as published by the Free Software Foundation, and
may be copied, distributed, and modified under those terms.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
下面是我自己编译的版本:
$ ./out/host/linux-x86/bin/emulator -version
Android emulator version 7.0 (build_id GINGERBREAD-eng.yuchengliu.20120224.102831)
Copyright (C) 2006-2011 The Android Open Source Project and many others.
This program is a derivative of the QEMU CPU emulator (www.qemu.org).
This software is licensed under the terms of the GNU General Public
License version 2, as published by the Free Software Foundation, and
may be copied, distributed, and modified under those terms.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
一个是16 一个是7 差的太多了吧,真是TMD的啊!