您的位置:首页 > 移动开发 > Android开发

ubuntu10.10编译Android源码

2012-05-31 23:21 405 查看
说明:

为了方便下载Android 源码, google提供了一个叫repo的脚本。android源码分为一百多个模块,最新的froyo代码到目前为止,有158个模块。采用这个脚本,可以分模块的同步源码。这个脚本除了可以下载源码,还可以提交自己的代码到google的服务器上,只要有权限。实际上,android的源代码是使用 git 管理的,这个脚本里面主要就是对git命令的封装。因此,我们需要把repo脚本下下来,然后运行。

1. 下载源码

mkdir android_src

cd android_src

curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo >./repo

chmod a+x repo

打开https://android.googlesource.com/new-password打开,申请结果拷贝到~/.netrc

sudo ./repo init -u https://android.googlesource.com/a/platform/manifest -b android-2.2_r1

输入用户名和邮箱

-b 后面是分支,不写-b参数默认master

* [new branch] android-1.6_r1

* [new branch] android-1.6_r1.1

* [new branch] android-1.6_r1.2

* [new branch] android-1.6_r1.4

* [new branch] android-1.6_r1.5

* [new branch] android-1.6_r2

* [new branch] android-2.0.1_r1

* [new branch] android-2.0_r1

* [new branch] android-2.1_r1

* [new branch] android-2.1_r2

* [new branch] android-2.2.1_r1

* [new branch] android-2.2.1_r2

* [new branch] android-2.2.2_r1

* [new branch] android-2.2.3_r2

* [new branch] android-2.2_r1

* [new branch] android-2.2_r1.3

* [new branch] android-2.3.1_r1

* [new branch] android-2.3.3_r1

* [new branch] android-2.3.3_r1.1

* [new branch] android-2.3.4_r1

* [new branch] android-2.3.5_r1

* [new branch] android-2.3.6_r1

* [new branch] android-2.3.7_r1

* [new branch] android-2.3_r1

* [new branch] android-4.0.1_r1

* [new branch] android-4.0.1_r1.1

* [new branch] android-4.0.1_r1.2

* [new branch] android-4.0.2_r1

* [new branch] android-4.0.3_r1

* [new branch] android-4.0.3_r1.1

* [new branch] android-4.0.4_r1

* [new branch] android-4.0.4_r1.1

* [new branch] android-4.0.4_r1.2

* [new branch] android-cts-2.2_r8

* [new branch] android-cts-2.3_r10

* [new branch] android-cts-2.3_r11

* [new branch] android-cts-2.3_r12

* [new branch] android-cts-4.0.3_r1

* [new branch] android-cts-4.0_r1

sudo ./repo sync //同步代码树,次过程比较长,公司网速快,约3小时

2. 配置linux编译环境 & compile

1). 依赖包

sudo apt-get install git-core curl

sudo apt-get install gnupg flex bison gperf build-essential zip zlib1g-dev gcc-multilib g++-multilib libsdl-dev libesd0-dev libwxgtk2.6-dev

sudo apt-get install valgrind

sudo apt-get install libc6-dev lib32ncurses5-dev ia32-libs x11proto-core-dev libx11-dev lib32readline5-dev lib32z-dev

sudo apt-get install libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown

sudo apt-get install libxml2-utils xsltproc

sudo ln -s /usr/lib32/mesa/libGL.so.1 /usr/lib32/mesa/libGL.so

2)由于android源码编译要求为4.3,而系统默认gcc版本为4.4,那你的编译可能会失败的!我的系统是ubuntu 10.10,默认的gcc版本为4.4,gcc-4.4太严格,不能将const char* 转为char*.那么怎样从gcc-4.4降到gcc- 4.3呢?

a)、安装gcc-4.3

$ sudo apt-get install gcc-4.3 g++-4.3

b)、修gcc相关链接

$ cd /usr/bin

sudo ln -snf gcc-4.3 gcc

sudo ln -snf g++-4.3 g++

sudo ln -snf cpp-4.3 cpp

3)android2.2要求用SUN JDK5

修改/etc/profile注销重新登录后生效

4)编译android

make -j 2 (双核)

大约两个小时,出现以下信息时结束

target Non-prelinked: sensors.trout (out/target/product/generic/symbols/system/lib/sensors.trout.so)

target Strip: sensors.trout (out/target/product/generic/obj/lib/sensors.trout.so)

Generated: (out/target/product/generic/android-info.txt)

Target system fs image: out/target/product/generic/obj/PACKAGING/systemimage_unopt_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

3. 编译sdk(可选)

上述make没有编译sdk和linux内核(给我们与编译好内核了./prebuilt/android-arm/kernel/kernel-qemu)

make sdk

编译过程中可能会遇到的问题。

问题一:找不到bios.bin和vgabios-cirrus.bin文件

couldn't locate source file: usr/share/pc-bios/bios.bin

couldn't locate source file: usr/share/pc-bios/vgabios-cirrus.bin

注意,这里的usr/share目录指的是~/Android/out/host/linux-x86目录下的usr/share目录,修改办法是复制~/Android/prebuilt/common下的pc-bios文件夹到~/Android/out/host/linux-x86/usr/share即可:

USER-NAME@MACHINE-NAME:~/Android$ cp ~/Android/prebuilt/common/pc-bios ~/Android/out/host/linux-x86/usr/share

问题二:找不到ddmlib-tests.jar、 ninepath-tests.jar 、common-tests.jar 和sdkuilib-tests.jar文件

在~/Android/out/host/linux-x86/framework这个目录下,可以找到以下几个文件common.jar、ddmlib.jar、ninepatch.jar、sdkuilib.jar这四个文件,然后将它们分别复制一份,并重命名,命名的原则很简单,就是在原有的名字后面跟上-tests即可。

4. 安装编译好的Android镜像到模拟器上。

1) 环境变量

export PATH=$PATH:~/android_src/out/host/linux-x86/bin

export ANDROID_PRODUCT_OUT=~/android_src/out/target/product/generic

其中,~/Android/out/host/linux-x86/bin有我们要执行的emulator命令,而~/Android/out/target/product/generic是Android镜像存放目录,下面执行emulator命令时会用到。

2)运行模拟器

emulator

直接敲上面的命令即可。模拟器运行需要四个文件,分别是Linux Kernel镜像zImage和Android镜像文件system.img、userdata.img和ramdisk.img。执行emulator命令时,如果不带任何参数,则Linux Kernel镜像默认使用~/Android/prebuilt/android-arm/kernel目录下的kernel-qemu文件,而Android镜像文件则默认使用ANDROID_PRODUCT_OUT目录下的system.img、userdata.img和ramdisk.img,也就是我们刚刚编译出来的镜像问题。

*当然,我们也可以以指定的镜像文件来运行模拟器,即运行emulator时,即:

emulator -kernel ./prebuilt/android-arm/kernel/kernel-qemu -sysdir ./out/target/product/generic -system system.img -data userdata.img -ramdisk ramdisk.img

*我们也可自己编译linux内核
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: