Ubuntu16.04编译Android8.0系统源码

32 篇文章 0 订阅
29 篇文章 16 订阅

##源码下载
源码下载请参考下面链接
清华大学镜像站

##安装openjdk
$ sudo apt-get update
$ sudo apt-get install openjdk-8-jdk
$ sudo apt-get install openjdk-8-jre
##安装编译依赖的库文件
首先需要更新软件源,这里使用阿里源

编辑如下文件:
sudo gedit /etc/apt/sources.list 
末尾添加如下内容
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 update

###安装依赖库文件

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-dev g++-multilib 
sudo apt-get install tofrodos python-markdown libxml2-utils xsltproc zlib1g-dev:i386 
sudo apt-get install dpkg-dev libsdl1.2-dev libesd0-dev
sudo apt-get install git-core gnupg flex bison gperf build-essential  
sudo apt-get install zip curl zlib1g-dev gcc-multilib g++-multilib 
sudo apt-get install libc6-dev-i386 
sudo apt-get install lib32ncurses5-dev x11proto-core-dev libx11-dev 
sudo apt-get install lib32z-dev ccache
sudo apt-get install libgl1-mesa-dev libxml2-utils xsltproc unzip m4

##编译AOSP
source build/envsetup.sh
lunch
make -j8
这里写图片描述

编译完成使用emulator命令启动模拟器效果如下:
这里写图片描述

##直接使用repo下载源码
另外,可以使用开源镜像站提供的第二种方式下载源码

  • 新建 android-8.0.0_r11文件夹用于存放下载的源代码
# 进入android-8.0.0_r11该目录,执行下面命令下载repo文件
curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo -o repo
chmod +x repo
  • repo的运行过程中会尝试访问官方的git源更新自己,如果想使用tuna的镜像源进行更新,可以将如下内容复制到你的~/.bashrc里
export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo/'
  • 下载指定版本的代码
repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b 对应的版本

上面提到的对应的版本可以在Andnroid 版本列表 中查看

  • repo init完成以后,执行repo sync即可,需要注意的是,由于 AOSP 镜像造成CPU/内存负载过重,限制了并发数量,因此建议: sync的时候并发数不宜太高
repo sync -4

##遇到的问题

  • 在编译Android M的时候,需要使用openjdk1.7,从N版本开始,才使用openjdk1.8,编译Android M可能会遇到下面错误:
clang: error: linker command failed with exit code 1 (use -v to see invocation)
build/core/host_shared_library_internal.mk:51: recipe for target 'out/host/linux-x86/obj/lib/libart.so' failed
make: *** [out/host/linux-x86/obj/lib/libart.so] Error 1
make: *** Waiting for unfinished jobs....
  • clang编译器导致的问题,目前可行的修改方法时在art/build/Android.common_build.mk ,中将host 默认编辑器使用clang关掉,找到WITHOUT_HOST_CLANG,关闭clang即可
# Host.
ART_HOST_CLANG := false
ifneq ($(WITHOUT_HOST_CLANG),true)
  # By default, host builds use clang for better warnings.
  ART_HOST_CLANG := false
endif
build/core/host_shared_library_internal.mk:44: recipe for target 'out/host/linux-x86/obj32/lib/libnativehelper.so' failed
make: *** [out/host/linux-x86/obj32/lib/libnativehelper.so] Error 1
make: *** Waiting for unfinished jobs....

clang: error: linker command failed with exit code 1 (use -v to see invocation)
build/core/host_shared_library_internal.mk:44: recipe for target 'out/host/linux-x86/obj32/lib/libc++.so' failed
make: *** [out/host/linux-x86/obj32/lib/libc++.so] Error 1
make: Leaving directory '/home/liuhang/study/android-5.1.1_r38'

clang: error: linker command failed with exit code 1 (use -v to see invocation)
build/core/host_shared_library_internal.mk:44: recipe for target 'out/host/linux-x86/obj32/lib/libc++.so' failed
make: *** [out/host/linux-x86/obj32/lib/libc++.so] Error 1
make: Leaving directory '/home/liuhang/study/android-5.1.1_r38'

上述三个错误,都需要更改/art/build/Android.common_build.mk文件

修改前:
# Host.
ART_HOST_CLANG := false
ifneq ($(WITHOUT_HOST_CLANG),true)
# By default, host builds use clang for better warnings.
ART_HOST_CLANG := true
endif
修改后:
# Host.
ART_HOST_CLANG := false
ifneq ($(WITHOUT_HOST_CLANG),false)
# By default, host builds use clang for better warnings.
ART_HOST_CLANG := true
endif

需要注意的是,可能修改以后还是之前的错误,此时需要先make update-api在执行make操作

  • make时报错。
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [/aosp/out/host/linux-x86/obj/lib/libc++.so] Error 1

解决办法:

cp /usr/bin/ld.gold prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.11-4.6/x86_64-linux/bin/ld

专注技术分享,包括Java,python,AI人工智能,Android分享,不定期更新学习视频,欢迎关注
在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值