一、Android源码的下载
1.1 创建源码路径
mkdir aosp
cd aosp
1.2 repo下载
sudo apt-get install git-core curl
git config --global user.email '邮箱'
git config --global user.name '名字'
mkdir ~/bin
PATH=~/bin:$PATH
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
执行init
repo init -u android.googlesource.com/platform/ma…
这样下载的是master的代码,如果要指定某个版本,可以通过
repo init -u aosp.tuna.tsinghua.edu.cn/platform/ma… -b android-4.4.4_r1
如果提示无法连接到 gerrit.googlesource.com,可以编辑 ~/bin/repo,把 REPO_URL 一行替换成 REPO_URL = 'mirrors.tuna.tsinghua.edu.cn/git/git-rep…'
然后下载通过
repo sync
1.3 脚本下载
新建目录 aosp,cd到目录下
然后 通过 git克隆以下镜像,这会在目录下创建manifest目录 git clone android.googlesource.com/platform/ma… //没有梯子使用清华源 git clone aosp.tuna.tsinghua.edu.cn/platform/ma…
cd到manifest目录中,通过git branch -a查看分支版本 找到想要下载的分支版本进行下载,如 git checkout android-6.0.1_r79
最后通过以下python脚本进行下载
import xml.dom.minidom
import os
from subprocess import call
# 1. 修改为源码要保存的路径
rootdir = "D:/android_source_code/Android_6_0_1"
# 2. 设置 git 安装的路径
git = "C:/Develop/Git/bin/git.exe"
# 3. 修改为第一步中 manifest 中 default.xml 保存的路径
dom = xml.dom.minidom.parse("D:/android_source_code/manifest/default.xml")
root = dom.documentElement
#prefix = git + " clone https://android.googlesource.com/"
# 4. 没有梯子使用清华源下载
prefix = git + " clone https://aosp.tuna.tsinghua.edu.cn/"
suffix = ".git"
if not os.path.exists(rootdir):
os.mkdir(rootdir)
for node in root.getElementsByTagName("project"):
os.chdir(rootdir)
d = node.getAttribute("path")
last = d.rfind("/")
if last != -1:
d = rootdir + "/" + d[:last]
if not os.path.exists(d):
os.makedirs(d)
os.chdir(d)
cmd = prefix + node.getAttribute("name") + suffix
call(cmd)
二、编译环境的配置
2.1 JDK的配置
编译KK(android4.4)需要jdk的版本是1.6,注意这里的jdk为oracle,不能是openjdk,
sudo mkdir /usr/local/jdk #jdk的安装路径
sudo cp /home/youlor/Downloads/jdk-6u45-linux-x64.bin /usr/local/jdk
#其中/home/youlor/Downloads/jdk-6u45-linux-x64.bin为jdk1.60_45的二进制文件所在路径
cd /usr/local/jdk
sudo chmod +x jdk-6u45-linux-x64.bin
sudo ./jdk-6u45-linux-x64.bin
#安装成功后,配置环境变量
sudo gedit /etc/profile #打开配置文件将下面4行加入到末尾并保存退出
export JAVA_HOME=/usr/local/jdk/jdk1.6.0_45
export JRE_HOME=/usr/local/jdk/jdk1.6.0_45/jre
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$JAVA_HOME:$PATH
2.2 make降级
在ubuntu16.04上的make版本默认是4.1,但编译kk需要的版本为3.81或者3.82,所以需要下载安装make-3.82
tar -xjvf make-3.81.tar.bz2
./configure
make
sudo make install
最后通过make -v查看,安装完成后需要重新登录。
2.3 编译源码
source build/envsetup.sh
luanch aosp_arm64-eng
make -j4
三、下载kernel
3.1 kernel下载
lisc@lisc-ubuntu:/home/aosp/android-4.4$ mkdir kernel
lisc@lisc-ubuntu:/home/aosp/android-4.4$ cd kernel
lisc@lisc-ubuntu:/home/aosp/android-4.4/kernel$ git clone https://aosp.tuna.tsinghua.edu.cn/kernel/goldfish.git
lisc@lisc-ubuntu:/home/aosp/android-4.4/kernel$ git branch -a
lisc@lisc-ubuntu:/home/aosp/android-4.4/kernel/goldfish$ git checkout -b android-goldfish-3.4 remotes/origin/android-goldfish-3.4
3.2 Kernel 编译
3.2.1 编译环境配置
lisc@lisc-ubuntu:/home/aosp/android-4.4/kernel/goldfish$ export ARCH=arm
lisc@lisc-ubuntu:/home/aosp/android-4.4/kernel/goldfish$ export SUBARCH=arm
lisc@lisc-ubuntu:/home/aosp/android-4.4/kernel/goldfish$ export CROSS_COMPILE=arm-eabi-
将交叉编译工具设置到PATH中
lisc@lisc-ubuntu:/home/aosp/android-4.4/kernel/goldfishPATH:/home/aosp/android-4.4/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.6/bin
3.2.2 编译
lisc@lisc-ubuntu:/home/aosp/android-4.4/kernel/goldfish$ make goldfish_armv7_defconfig
HOSTCC scripts/basic/fixdep
HOSTCC scripts/kconfig/conf.o
SHIPPED scripts/kconfig/zconf.tab.c
SHIPPED scripts/kconfig/zconf.lex.c
SHIPPED scripts/kconfig/zconf.hash.c
HOSTCC scripts/kconfig/zconf.tab.o
HOSTLD scripts/kconfig/conf
#
# configuration written to .config
#
lisc@lisc-ubuntu:/home/aosp/android-4.4/kernel/goldfish$ make
完!