【Android车载系列】第5章 AOSP开发环境配置

1 硬件支持

建议空闲内存16G以上,同时硬盘400G以上
内存不够可以使用 Linux 的交换分区

2 VMware Workstation安装

https://download3.vmware.com/software/wkst/file/VMware-workstation-full-16.1.1-17801498.exe

2.1 Ubuntu镜像

http://mirrors.aliyun.com/ubuntu-releases/16.04/ubuntu-16.04.7-desktop-amd64.iso

2.2 Linux 的交换分区

2.2.1 Linux 的交换分区(swap)

  或者叫内存置换空间(swap space),是磁盘上的一块区域,可以是一个分区,也可以是一个文件,或者是他们的组合。交换分区的作用是,当系统物理内存吃紧时,Linux 会将内存中不常访问的数据保存到 swap 上,这样系统就有更多的物理内存为各个进程服务,而当系统需要访问 swap 上存储的内容时,再将 swap 上的数据加载到内存中,也就是常说的 swap out 和 swap in。

2.2.2 查看空间大小

  可以提供free -m命令查看虚拟内存与交换空间大小或者 swapon -s

2.2.3 配置交换空间

1.停用交换文件

sudo swapoff /swapfile

2.删除文件

sudo rm /swapfile

3.新建swap空间,以20G为例

sudo fallocate -l 20G /swapfile
设置文件权限
sudo chmod 600 /swapfile
挂载
sudo mkswap /swapfile
激活启用
sudo swapon /swapfile

4.接着把交换信息写入系统配置,不然Ubuntu重启后以上配置swap空间工作得重新做。

打开配置文件
sudo vim /etc/fstab
在最后一行插入
/swapfile swap swap defaults 0 0

2.2.4 交换空间未使用

1.系统只有当虚拟内存不足才会启动Swap,比如系统默认内存只有6000KB时才会启用交换空间,但是此时系统可能已经卡死,无法启动swap,所以需要更改设置。

2.终端输入命令:

sudo vim /etc/sysctl.conf

3.在最后面添加如下语句(按i进入编辑模式,光标移到最后,插入语句)
vm.min_free_kbytes=1500000 #大致1.5G
保存退出(按ESC退出编辑模式,输入:wq保存退出)然后重启开机

以上配置的意思是,当系统内存不足1.5G时就启用交换空间,这是因为我分配给Ubuntu的内存为8G。而如果你虚拟机分配的内存是4G,那建议不要设置1.5G就启用交换空间,可以调小一些,比如调整为1G:
vm.min_free_kbytes=1000000

3 工具软件安装

3.1 安装git:

sudo apt install git

3.2 安装依赖工具

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

3.3 下载与安装Python3

3.3.1 打开下载目录

 cd Downloads

3.3.2 下载

wget https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tgz

3.3.3 解压Python3

tar xvf Python-3.7.1.tgz

3.3.4 编译与安装Python3

./configure     或指定路径  ./configure --prefix=/usr/local/python3.7

sudo make install

3.4 软件版本管理工具

3.4.1 配置update-alternatives

sudo update-alternatives --install  /usr/bin/python python /usr/bin/python2.7 2
sudo update-alternatives --install  /usr/bin/python python /usr/local/bin/python3.7  3

3.4.2 选择Python版本

sudo update-alternatives --config python

4 AOSP源码下载

4.1 AOSP官方地址

https://source.android.google.cn/setup/build/downloading

4.2 中科大镜像

https://mirrors.ustc.edu.cn/help/aosp.html   

4.2.1 执行下面命令

mkdir ~/bin
PATH=~/bin:$PATH
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
mkdir WORKING_DIRECTORY
cd WORKING_DIRECTORY

下载:repo init -u git://mirrors.ustc.edu.cn/aosp/platform/manifest -b android-12.1.0_r27

安卓版本列表: https://source.android.google.cn/docs/setup/about/build-numbers?hl=zh-cn#source-code-tags-and-builds

4.2.1.1 权限问题

执行:chmod 755 /home/jett/bin/repo

4.2.1.2 连接问题

如果提示无法连接到 gerrit.googlesource.com,可以编辑 ~/bin/repo,把 REPO_URL 一行替换成下面的: REPO_URL = ‘https://gerrit-googlesource.proxy.ustclug.org/git-repo’

4.2.1.3 SSL证书校验

如果提示无法进行SSL证书校验,执行:
git config --global http.sslverify false
git config --global https.sslverify false

4.2.1.4 git身份

如果出现git身份不存在:
git config --global user.email “[email protected]
git config --global user.name jett

4.2.2 执行:repo sync

4.2.2.1 同步过程

一段等待,大概十小时以上
在这里插入图片描述

4.2.2.2 错误处理

error: Unable to fully sync the tree.
error: Downloading network changes failed.
Try re-running with “-j1 --fail-fast” to exit at the first error.

处理方法:
repo sync -j1 --fail-fast

4.2.3 下载成功

repo sync has finished successfully.

4.3 清华镜像

https://mirrors.tuna.tsinghua.edu.cn/help/AOSP/

5 编译 AOSP 代码

5.1 build

. build/envsetup.sh

5.2 lunch

lunch aosp_x86_64-eng(问题:模拟器镜像无法生成)
lunch sdk_x86_64 手机
lunch sdk_car_x86_64-userdebug 车载课程中选择的lunch sdk_x86_64 用于使用模拟器
在这里插入图片描述
在这里插入图片描述

5.3 make

在这里插入图片描述
编译完成(4个小时左右)
在这里插入图片描述

5.3.1 常见问题

5.3.1.1 磁盘空间不足

在这里插入图片描述
df -h 查看磁盘使用情况
在这里插入图片描述

5.3.1.2 内存不足问题

设置好交换空间一般就没问题了

5.4 emulator

5.4.1 打开模拟器

5.4.1.1 虚拟机嵌套虚拟机问题

在这里插入图片描述

windows下安装vmware里边嵌套kvm提示kvm不可用解决办法:
步骤:虚拟机-设置-处理器-勾选虚拟化Intel-确认

5.4.1.2 模拟器镜像无法生成

在这里插入图片描述

lunch sdk_x86_64
Lunch menu路径build/make/target/product/AndroidProducts.mk

5.4.1.3 编译后的模拟器路径

out/target/product/emulator_x86_64

5.4.2 日志查看

adb shell

logcat -c 
logcat
logcat -s TAG

查找文件
find -name 文件名
查找文件内容:方法调用
grep "文件内容" ./ -rn

打印调用栈
Log.i("jett","oncreate",new Exception());

6 android studio安装与源码导入

6.1 安装jdk

sudo apt install openjdk-9-jre-headless

在这里插入图片描述

6.2 安装as

6.2.1 下载

https://developer.android.google.cn/studio

android-studio-2022.1.1.21-linux.tar.gz

6.2.2 回到源码目录

执行
make idegen -j4

sudo development/tools/idegen/idegen.sh
	生成文件android.iml  &  android.ipr

6.2.3 导入源码前建议

AS的bin目录下,修改studio64.vmoptions增加内存

6.3 AS启动与源码导入

6.3.1 先进入bin目录

cd bin

6.3.2 执行

./studio.sh

6.3.3 AS下File->open->android.ipr

可导入android.iml中标记的全部源码

猜你喜欢

转载自blog.csdn.net/u010687761/article/details/129783993