Android-源码下载编译教程

Ubuntu安装git工具
sudo apt - get install git
git config –global user . email “test@test . com”
git config –global user . name “test”

Ubuntu安装repo
curl https : //storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a + x ~ / bin / repo

下载Android源码
#此过程需要在polipo翻墙环境下进行
#创建source目录
mkdir source
cd source
#构建repo项目目录
repo init - u https : //aosp.tuna.tsinghua.edu.cn/platform/manifest
#下载Android源码
repo syns

改用科大源下载
如果觉得慢,可以使用科大源下载源码,实际速度为你电脑网速。

编译源码前的准备工作
为apt-get添加阿里云源
deb http : //mirrors.aliyun.com/ubuntu/ quantal main restricted universe multiverse
deb http : //mirrors.aliyun.com/ubuntu/ quantal-security main restricted universe multiverse
deb http : //mirrors.aliyun.com/ubuntu/ quantal-updates main restricted universe multiverse
deb http : //mirrors.aliyun.com/ubuntu/ quantal-proposed main restricted universe multiverse
deb http : //mirrors.aliyun.com/ubuntu/ quantal-backports main restricted universe multiverse
deb - src http : //mirrors.aliyun.com/ubuntu/ quantal main restricted universe multiverse
deb - src http : //mirrors.aliyun.com/ubuntu/ quantal-security main restricted universe multiverse
deb - src http : //mirrors.aliyun.com/ubuntu/ quantal-updates main restricted universe multiverse
deb - src http : //mirrors.aliyun.com/ubuntu/ quantal-proposed main restricted universe multiverse
deb - src http : //mirrors.aliyun.com/ubuntu/ quantal-backports main restricted universe multiverse

安装依赖软件
sudo apt - get install - y git flex bison gperf build - essential libncurses5 - dev : i386
sudo apt - get install libx11 - dev : i386 libreadline6 - dev : i386 libgl1 - mesa - devg ++ - multilib
sudo apt - get install tofrodos python - markdownlibxml2 - utilsxsltproc zlib1g - dev : i386
sudo apt - get install dpkg - devlibsdl1 .2 - devlibesd0 - dev
sudo apt - get install git - coregnupg flex bison gperf build - essential
sudo apt - get install zip curl zlib1g - devgcc - multilibg ++ - multilib
sudo apt - get install libc6 - dev - i386
sudo apt - get install lib32ncurses5 - devx11proto - core - devlibx11 - dev
sudo apt - get install lib32z - devccache
sudo apt - get install libgl1 - mesa - devlibxml2 - utilsxsltproc unzip m4

添加 OpenJDK
安装OpenJDK
从Android 6.0开始Android源码的编译需要安装OpenJDK,不能使用Oracle JDK,而且Android 6.0只能使用OpenJDK7
sudo add - apt - repository ppa : openjdk - r / ppa
sudo apt - getupdate
sudo apt - getinstall openjdk - 7 - jdk
添加配置项
export JAVA_HOME = / usr / lib / jvm / java - 7 - openjdk - amd64
exportJRE_HOME = ${ JAVA_HOME } / jre
exportCLASSPATH = . : ${ JAVA_HOME } / lib : ${ JRE_HOME } / lib
exportPATH = ${ JAVA_HOME } / bin : $ PATH

编译代码
添加CCACHE
为.bashrc文件末尾添加:export USE_CCACHE = 1
echo export  USE_CCACHE = 1   >>   ~ / . bashrc

设置高速缓存
为了提高编译效率,设置编译器高速缓存:
prebuilts / misc / linux - x86 / ccache / ccache - M 50G

导入Android环境变量
导入编译Android源码所需的环境变量和其它参数:
source build / envsetup . sh

选择编译类型
lunch
#选择1:aosp_arm - eng

开始编译
开始编译,执行make -j10, 10为同时编译的线程数,一般google推荐这个数字为2倍的cpu个数再加上2,比如4核,就是10。
make - j10

编译成功

编译系统无法运行,于是使用别人提供的系统进行编译( http://blog.csdn.net/fuchaosz/article/details/51487585 ),通过上面描述的方法进行编译,编译成功。

运行Android 系统
将配置环境到导致到上下文中
source build/envsetup.sh
执行lunch
lunch
#编译时选择之前编译的build target(aosp_arm-eng)
配置上下文
export ANDROID_BUILD_TOP= $ANDROID_SOURCE /
export ANDROID_PRODUCT_OUT= $ANDROID_SOURCE /out/target/product/generic/
cd $ANDROID_SOURCE /prebuilts/android-emulator/linux-x86_64
启动模拟器
emulator


问题汇总
问题1
error error  opening 'out / host / darwin - x86 / obj / SHARED_LIBRARIES / libart_intermediates / gc / heap.d':  No   space  left  on  device
fatal  error error   in  backend: IO failure  on  output stream.
ninja: build stopped: subcommand failed.
make:  * * *  [ninja_wrapper]  Error   1
解决方案(分区磁盘小了)
修改磁盘大小 $ sudo hdiutil resize - size < new - size - you - want > g
 ~ / android.dmg.sparseimage

参考



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值