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

android 源码的下载和编译

2016-03-20 08:30 387 查看
最近因为工作需要,需要下载一份android 源码在自己的ubuntu 笔记本上使用。于是就想下载一份android6.0.1的代码,编译一下,已做浏览代码和调试用。

由于android 的网站在国内被墙,只能从国内镜像网站下载源码,我选择了清华的镜像网站:

安装git:

sudo apt-get install git

下载repo 工具

mkdir ~/bin
PATH=~/bin:$PATH
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo

创建目录:

mkdir WORKING_DIRECTORY
cd WORKING_DIRECTORY

配置git
git config -global user.name "your name"
git config -global user.email "yuremail“


初始化仓库:

repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest # 或 repo init -u git://aosp.tuna.tsinghua.edu.cn/aosp/platform/manifest

## 如果提示无法连接到 gerrit.googlesource.com,可以编辑 ~/bin/repo,把 REPO_URL 一行替换成下面的:
REPO_URL = 'https://gerrit-google.tuna.tsinghua.edu.cn/git-repo'


查看自己的cpu 内核数,以提高repo sync 和下面编译的速度:

cat /proc/cpuinfo
一般是最大的cpu 内核乘以2;

sync 代码:

repo sync -c -j8


-c 只会sync 当前使用的分支代码;

编译:

根据使用的ubuntu 的版本不一样,我使用的ubuntu15.10,需要安装一下jdk8,0,bison:

//在android 根目录下:
source build/envsetup.sh
lunch 11
make -j4
就可以等待大概两三各小时,就会编译成功

如果机器不是特别强壮,机器内存不大,编译会出现很多错误,比如jack 出错的。由于google 在M中使用了ninja 编译,据说可以提高一些编译速度。

如果是内存溢出,可以考虑在/prebuilds/sdk/tools/linux-x86/jack-admin 在start-server的启动中,添加一个-Xmx2560m 启动参数。make -j1 编译。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  android ASOP