第四章:源代码的下载和编译
上一章讲解了Git的使用,这章主要讲解运用Git下载源代码和编译,Android源代码包含了很多东西,但主要了解我们自己所需要使用的就可以,那如何下载和编译Android源代码和Linux内核源代码?
下载、编译和测试Android源代码有以下几个步骤:
(1)配置Android源代码下载环境:
# mkdir ~/bin
# PATH=~/bin:$PATH \创建用于存放脚本文件的目录
# curl http://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~bin/repo
# chmod a+x ~/bin/repo \下载repo脚本文件
# mkdir android_source
#cd android_source \创建用于存放Android源代码的目录
# repo init -u https://android.googlesource.com/platform/mainfest \初始化
# repo sync \开始下载Android源代码
(2)Android源代码目录分别存放了Android源代码的不同子项目
(3)下载Android源代码中的一部分两种方法:
1、 # repo sync platform/bootable/recovery \ repo sync命令
2、 #git clone http://android.googlesource.com/<project name> \git clone命令
(4)编译Android源代码
# source build/envsetup.sh \初始化编译环境
# lunch full-eng \选择目标
# make
# make -j4 \编译Android源代码
(5)out目录结构分析
(6)将自己的APK作为Android内置程序发布
(7)用模拟器测试system.img文件
下载和编译Linux内核源代码
1、下载Linux内核源代码
# git clone https://android.googlesource.com/kernel/common.git
# git branch -a
# git checkout -b android-3.0 remotes/origin/android-3.0
# git clone https://android.googlesource.com/kernel/goldfish.git
# git checkout -b android-goldfish-2.6.29 remotes/origin/android-goldfish-2.6.29
2、Linux内核源代码的目录结构
3、安装Android内核的编译环境
安装交叉编译器
准备工作:
将arm-linux-gcc-4.3.2.tgz文件和arm-none-linux-gnueabi-arm-2008q3-72-for-linux.tar.bz2文件复制到工作目录
# tar zxvf arm-linux-gcc-4.3.2.tgz -C /
# tar jxvf arm-none-linux-gnueabi-arm-2008q3-72-for-linux.tar.bz2 -C/ \解压编译器:
# ls /usr/local/arm –l \验证交叉编译器是否安装成功:
# apt-get install libncurses5 –dev \安装libncurses5
#export PATH=/root/comppilers/arm-none-linux-gnueabi/bin:$PATH \配置和编译Linux内核