Ubuntu18.04下载编译Android10源码

一、下载Ubuntu18.04

下载地址:

  1. xUbuntu:https://xubuntu.org/
  2. Ubuntu:https://ubuntu.com/download

安装时分配了4核、10g运行内存、250g存储空间。

二、下载安卓10源码

  1. 换阿里源:
备份/etc/apt/sources.list
#备份
cp /etc/apt/sources.list /etc/apt/sources.list.bak

在/etc/apt/sources.list文件前面添加如下条目
#添加阿里源
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

最后执行如下命令更新源
##更新
sudo apt-get update
sudo apt-get upgrade
  1. 安装git
sudo apt-get install git
git config –global user.email "[email protected]"
git config –global user.name "test"
  1. 下载repo工具
mkdir ~/bin
PATH=~/bin:$PATH
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo

如果是墙内,提示无法连接到 gerrit.googlesource.com,可以编辑 ~/bin/repo,修改REPO_URL:

REPO_URL = 'https://gerrit-googlesource.lug.ustc.edu.cn/git-repo'

Ubuntu18.04下载编译Android10源码_第1张图片

  1. 新建一个文件夹放Android源码
mkdir android
cd android
  1. 下载
repo init -u git://mirrors.ustc.edu.cn/aosp/platform/manifest -b android-10.0.0_r9

具体的版本列表可以到其镜像网站下查看:http://mirrors.ustc.edu.cn/aosp/platform/manifest.git/refs/heads

同步源码树:repo sync
如果中途中断也可以再执行repo sync。

三、编译

  1. 配置java8
sudo apt-get install openjdk-8-jdk
sudo apt-get install openjdk-8-jre

可输入java -version查看openjdk version。

  1. 配置依赖库
sudo apt-get install libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-dev g++-multilib
sudo apt-get install -y git flex bison gperf build-essential libncurses5-dev:i386
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 libgl1-mesa-dev libxml2-utils xsltproc unzip m4
sudo apt-get install lib32z-dev ccache
sudo apt-get install libssl-dev
  1. 在android目录下执行
source build/envsetup.sh
lunch aosp_x86_64-eng
make update-api -j2
make -j2

这里因为电脑配置太差,用“-j2”最多只能开两个线程时,才编译成功。

四、碰到的问题

  1. 第一次进入root要先设置管理员密码
sudo passwd root
  1. 创建文件夹不能在root下
  2. 虚拟机关机后开不了机,选择自动检测,有弹窗点击否
    Ubuntu18.04下载编译Android10源码_第2张图片
  3. Android编译问题分析
    设置RAM>4GB。
  4. out of memory:
    JVM分配9800M时编译编译成功
export JACK_SERVER_VM_ARGUMENTS="-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx9800m"
  1. fatal: read error: Connection reset by peer
    按照https://blog.csdn.net/dddxxxx/article/details/52355939教程,断开网络重新连接网络,接着下载。

  2. emulator: command not found

source build/envsetup.sh  
lunch sdk-eng
emulator
  1. 无法安装libesd0-dev
    ubuntu18.04无法安装libesd0-dev【学习笔记】

你可能感兴趣的:(Ubuntu18.04下载编译Android10源码)