Mac Catalina + Ubuntu 20.04 编译 Android 10 源码注意事项

2,807 阅读2分钟

硬件配置

i59400f (完全够用就是慢点)

32g (目测16g够用)

1T m.2 (果断固态)

软件环境

MacOS Catalina 15.4(host操作系统)

Parallels 15.1(虚拟机)

下载地址:自己在网上找版本吧,有版权问题,不方便透露

Ubuntu Desktop 20.04 (虚拟机操作系统)

下载地址:ubuntu.com/download/de…

注意:虚拟机设置,cpu6核,内存16g,硬盘256g

官方文档

编译环境搭建及repo下载设置,请参考官方文档 ,本文主要解决一些可能碰到的问题

source.android.com/setup

Ubuntu Desktop 20.04的编译环境搭建,按官方Ubuntu 14.04的搭建文档即可,唯一不同的是将apt-get改成apt

这里我还是列出来吧。。

安装相关库

sudo apt install git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z-dev libgl1-mesa-dev libxml2-utils xsltproc unzip

踩到的坑,请提前安装此库,Ubuntu 20中没有,应该是64位操作系统的原因

sudo apt-get install libncurses5

repo安装注意事项

有两个版本的repo供下载,一个是python2,一个是python3,注意选符合你当前环境的

源码版本

注意:不要编译master分支,其中代码可能存在编译错误

本次编译的分支为 android-10.0.0_r33

初始化命令

repo init -u https://android.googlesource.com/platform/manifest -b android-10.0.0_r33
repo sync

error while loading shared libraries: libncurses.so.5

sudo apt-get install libncurses5

解决方案来自:stackoverflow.com/questions/1…


FAILED: out/target/product/generic_x86/system-qemu.img

FAILED: out/target/product/generic_x86/system-qemu.img
/bin/bash -c "(export SGDISK=out/host/linux-x86/bin/sgdisk SIMG2IMG=out/host/linux-x86/bin/simg2img;      device/generic/goldfish/tools/mk_combined_img.py -i out/target/product/generic_x86/system-qemu-config.txt -o out/target/product/generic_x86/system-qemu.img)"
  File "device/generic/goldfish/tools/mk_combined_img.py", line 48
    print "'%s' cannot be converted to int" % (line[2])
          ^
SyntaxError: invalid syntax
14:03:41 ninja failed with: exit status 1

#### failed to build some targets (02:05:48 (hh:mm:ss)) ####

此问题因为我默认设置python指向了python3,导致运行python代码时出错,解决方案是将/usr/bin/python中的连接重新指向python2,然后再次编译即可


下面是我编译master分支出现的问题,果断放弃编译master

fatal error: linux/netfilter/xt_DSCP.h: No such file or directory

//方法一,新建文件连接
cd external/iptables/extensions/include/linux/netfilter
ln -s xt_dscp.h xt_DSCP.h

//如果还报错的话请使用方法二

//方法二,修改头文件引用

文件位置:
AOSP/external/iptables/include/linux/netfilter_ipv4/ipt_ECN.h

修改方法:
include <linux/netfilter/xt_DSCP.h>
改为
include <linux/netfilter/xt_dscp.h>

解决方案来自:groups.google.com/forum/#!top…