闲叙

自从上一次在双体系 Kali 上下载编译 AOSP 成功却倒在了 AndroidStudio 的导入的路上后,心里一直对此念念不忘,如鲠在喉,究竟过错信息提示说仅仅倒在了 JDK 的版别上(提示说要 JDK 11 的版别,本地装的是 JDK 1.8),虽然我换了对应的 JDK 版别也无济于事( ╯□╰ )。刚好近日有些空闲,便借此机会折腾了一番,折腾了两天,试了 WSLUbuntu 虚拟机等计划,这儿记载一下整个进程及遇到一些问题吧(终究出产运用仍是双体系 Kali 经过屏蔽体系 Java 转而运用 AOSP 自带的 Java 环境即可编译成功)。

通用 Debian 体系下载编译过程

切换到 root 用户

这一步是为了防止因体系而导致的用户权限问题,例如 Kali 很多指令的履行需求 root 权限;

su

然后输入暗码,假如没有设置果 root 暗码,则履行

sudo passwd root

键入暗码,当然,把当时用户加入 root 用户组也不是不能够,这些 Linux 根本指令就不再复述了。

下载 repo 文件并装备 repo 环境

这儿 repo 文件是 repo 指令履行的根底,咱们需求将其下载下来并添加到环境变量里,以便利咱们运用;因为墙的存在,谷歌官方的一些资源咱们访问不到,这儿咱们选择运用国内清华的源;

清华大学 AOSP 镜像站:mirrors.tuna.tsinghua.edu.cn/help/AOSP/
中科大 AOSP 镜像站:mirrors.ustc.edu.cn/help/aosp.h…

// 装置 curl 东西
apt install curl
// 装置 git
apt install git
// 进入 root 用户目录,要是想换其他用户目录,自行切换即可 cd /home/XXX
cd ~
// 创立 repo 所在目录
mkdir bin
// 下载 repo
curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo -o repo
// 赋予履行权限
chmod +x repo
// 将当时目录添加至 PATH ,要是嫌费事能够直接添加到 .bashrc 文件中
PATH=~/bin:$PATH
// repo的运转进程中会测验访问官方的git源更新自己,这儿运用tuna的镜像源进行更新
// 修正 ~/.bashrc 并在文件末尾添加如下内容然后 source ~/.bashrc
// export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo'

创立 AOSP 作业目录并同步源码

// 回到用户目录
cd ~
// 创立作业目录,当然你想放哪儿都行
mkdir AOSP
// 进入作业目录
cd AOSP
// 初始化库房,你也能够选择同步对应的版别
repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest
// 开始同步
repo sync

装置必要依靠

sudoapt-getinstalllibx11-dev:i386libreadline6-dev:i386libgl1-mesa-devg+multilib\
sudoapt-getinstall-ygitflexbisongperfbuild-essentiallibncurses5-dev:i386\
sudoapt-getinstalltofrodospython-markdownlibxml2-utilsxsltproczlib1g-dev:i386\
sudoapt-getinstalldpkg-devlibsdl1.2-devlibesd0-dev\
sudoapt-getinstallgit-coregnupgflexbisongperfbuild-essential\
sudoapt-getinstallzipcurlzlib1g-devgcc-multilibg+multilib\
sudoapt-getinstalllibc6-dev-i386\
sudoapt-getinstalllib32ncurses5-devx11proto-core-devlibx11-dev\
sudoapt-getinstalllibgl1-mesa-devlibxml2-utilsxsltprocunzipm4\
sudoapt-getinstalllib32z-devccache\
sudoapt-getinstalllibssl-devlibncurses5
sudo apt install libncurses5

编译代码

这儿不细讲各个指令的含义,如有需求能够检查官网或许其他材料进行了解

cd ~/AOSP
// 设置编译所需环境变量
. build/envsteup.sh
// 检查哪些版别能够编译,这儿根据自己的情况选择
lunch
// 开始编译,最多运用 16 中心
make -j16

参阅编译耗时

因为运用的虚拟机且资源没有配满,还运用的是机械硬盘,所以编译耗时5小时8分,运用的装备如下

PC 装备
    CPU AMD 1700 
    内存 32G
    磁盘 希捷酷鱼3T
Hyper-V 虚拟机设置
    体系 Ubuntu 21.10
    CPU 14中心
    内存 动态内存最大 20G
    磁盘 1T 

AOSP 折腾日记

AndroidStudio 导入体系源码

生成导入文件

// 编译模块
mmm development/tools/idegen

成功后如下

root@kaithmy-Virtual-Machine:/home/kaithmy/AOSP# mmm development/tools/idegen/
00:47:44 ************************************************************
00:47:44 You are building on a machine with 5.53GB of RAM
00:47:44
00:47:44 The minimum required amount of free memory is around 16GB,
00:47:44 and even with that, some configurations may not work.
00:47:44
00:47:44 If you run into segfaults or other errors, try reducing your
00:47:44 -j value.
00:47:44 ************************************************************
00:47:46 Build sandboxing disabled due to nsjail error.
build/make/core/soong_config.mk:198: warning: BOARD_PLAT_PUBLIC_SEPOLICY_DIR has been deprecated. Use SYSTEM_EXT_PUBLIC_SEPOLICY_DIRS instead.
build/make/core/soong_config.mk:199: warning: BOARD_PLAT_PRIVATE_SEPOLICY_DIR has been deprecated. Use SYSTEM_EXT_PRIVATE_SEPOLICY_DIRS instead.
============================================
PLATFORM_VERSION_CODENAME=Tiramisu
PLATFORM_VERSION=Tiramisu
TARGET_PRODUCT=aosp_x86_64
TARGET_BUILD_VARIANT=eng
TARGET_BUILD_TYPE=release
TARGET_ARCH=x86_64
TARGET_ARCH_VARIANT=x86_64
TARGET_2ND_ARCH=x86
TARGET_2ND_ARCH_VARIANT=x86_64
HOST_ARCH=x86_64
HOST_2ND_ARCH=x86
HOST_OS=linux
HOST_OS_EXTRA=Linux-5.13.0-22-generic-x86_64-Ubuntu-21.10
HOST_CROSS_OS=windows
HOST_CROSS_ARCH=x86
HOST_CROSS_2ND_ARCH=x86_64
HOST_BUILD_TYPE=release
BUILD_ID=AOSP.MASTER
OUT_DIR=out
PRODUCT_SOONG_NAMESPACES=device/generic/goldfish device/generic/goldfish-opengl hardware/google/camera hardware/google/camera/devices/EmulatedCamera
============================================
[100% 7/7] Install out/host/linux-x86/framework/idegen.jar
#### build completed successfully (07:48 (mm:ss)) ####

成功后的目录下有以下文件

root@kaithmy-Virtual-Machine:/home/kaithmy/AOSP# ls development/tools/idegen/
Android.bp  excluded-paths  idegen.iml  idegen.ipr  idegen.sh  index-gen.sh  intellij-gen.sh  README  src  templates

回到 AOSP 目录,履行

// 运转 idegen.sh 脚本
. development/tools/idegen/idegen.sh 

此刻在 AOSP 目录下会多出来 android.ipr 文件,这是导入源码的关键

# . development/tools/idegen/idegen.sh 
Picked up _JAVA_OPTIONS: -Dawt.useSystemAAFontSettings=on -Dswing.aatext=true
Read excludes: 21ms
Traversed tree: 25996ms

加大 AndroidStudio 的内存

修正 .vmoptions,例如:

// 按需修正
-Xmx10240m
-Xms4096m

AndroidStudio 翻开 android.ipr

翻开 android.ipr 即可导入源码工程,有可能会提示以下过错

The directory XXX(项目名) is registered as a Git root, but no Git repositories were found there. 直接到 File -> Setting -> Version Control 中移除不存在的项目即可,例如我遇到的是 /home,很明显是不存在的 git 项目

鸡肋 WSL

为啥说 WSL 是鸡肋呢?因为 WSL 的体会和真实的 Linux 体会在某些关键问题上差的太多了,不适合咱们这些 Android 开发者,虽然它能满足日常 90% 的需求,但恰恰是别的的 10% 让它成为了不起不弃之的鸡肋。首先是代码同步问题,体现在以下几点,榜首:在进行 repo sync 时,假如要 sync 指定版别的代码,必定有几个模块的代码是 checkout 失利的,具体版别以及一些过错信息一会儿讲;第二:是文件途径巨细写灵敏的问题,默认 WSL 是巨细写不灵敏的,而编译时是需求巨细写灵敏的,这需求前期创立工程文件夹的时分就装备好,假如是创立工程文件夹之后才装备的,那么很不幸,拉取与编译代码时你依然会碰到不少问题;然后是 PowerShellWSL 的回显问题,常常会呈现 bash 内容不回显到 PowerShell 中以及回显很慢的情况,导致常常会认为 bash 指令没有履行完而在一旁烦躁不安;再然后是 bash 指令履行效率低下,一个 . build/envsteup.sh 指令跑满磁盘和多半的 CPU 花了近 5 分钟的时间才履行完,lunch 指令也是一样,这就很让人头疼,便是虚拟机再慢也在 5s 内能履行完 . build/envsteup.sh,而且 WSL 不是还声称比虚拟机性能更强嘛?以下是具体的一些过程

启用 WSL

这个比较简单,到微软使用商铺查找 WSL 或许 Ubuntu 装置即可

设置 WSL 资源装备

一般用来操控 WSL 占用的资源巨细,这儿需求在 用户目录下创立 .wslconfig 文件并装备,参阅如下:

[wsl2]
processors=16
memory=32GB
swap=16GB

设置文件夹巨细写灵敏

翻开 PowerShell 输入 bash 进入 WSL,输入

// 检查途径信息
mount

检查 case 相关状态,也能够输入 mount | grep case 来检查,假如没有那么默认是 case=off,巨细写不灵敏的,case 选项阐明如下

case=dir case=off case=force
Flag为enable的目录 Case Sensitive Case Sensitive Case Sensitive
Flag为disable的目录 Case Insensitive Case Insensitive Case Sensitive
wsl中创立目录的Flag Enabled Disabled Enabled

能够经过修正或许创立 etc/wsl.conf 来装备它

[automount]
options = "case=dir"

然后重启 wsl 即可,参阅指令(记得用管理员身份)

// 中止 wsl 服务
net stop LxssManager
// 启动 wsl 服务
net start LxssManager

假如要启用 case=force 则需求在 CMDPowerShell 中履行

 reg.exe add HKLM\SYSTEM\CurrentControlSet\Services\lxss /v DrvFsAllowForceCaseSensitivity /t REG_DWORD /d 1

AOSP 折腾日记

AOSP 折腾日记

根底过程

参阅以上 通用 Debian 体系下载编译过程

过错信息一览

root@DESKTOP-EKL3BCN:/mnt/d/AOSP# repo sync
Fetching: 100% (1052/1052), done in 39m39.075s
Garbage collecting: 100% (1052/1052), done in 1m1.527s
info: A new version of repo is available
warning: repo is not tracking a remote branch, so it will not receive updates
info: Restarting repo with latest version
Fetching: 100% (1051/1051), done in 30m41.590s
Garbage collecting: 95% [4 jobs] (1008/1051) finished platform/prebuilts/gcc/darwin-x86/aarch64/aarch64-linux-android-4.Garbage collecting: 100% (1051/1051), done in 40.764s
error: Cannot link file build/bazel/bazel.BUILD to /mnt/d/AOSP/BUILD
fatal: Unable to create '/mnt/d/AOSP/cts/.git/index.lock': File exists.
Another git process seems to be running in this repository, e.g.
an editor opened by 'git commit'. Please make sure all processes
are terminated then try again. If it still fails, a git process
may have crashed in this repository earlier:
remove the file manually to continue.
error: cts/: platform/cts checkout 41d9f299c73b5af190ebfb5d19c48a27c10cc371
error: Cannot checkout platform/cts
fatal: Unable to create '/mnt/d/AOSP/external/apache-http/.git/index.lock': File exists.
Another git process seems to be running in this repository, e.g.
an editor opened by 'git commit'. Please make sure all processes
are terminated then try again. If it still fails, a git process
may have crashed in this repository earlier:
remove the file manually to continue.
error: external/apache-http/: platform/external/apache-http checkout e0456b661323d7c463e8d2aca7349716506dbf7d
error: Cannot checkout platform/external/apache-http
fatal: Unable to create '/mnt/d/AOSP/device/google/coral-sepolicy/.git/index.lock': File exists.
Another git process seems to be running in this repository, e.g.
an editor opened by 'git commit'. Please make sure all processes
are terminated then try again. If it still fails, a git process
may have crashed in this repository earlier:
remove the file manually to continue.
error: device/google/coral-sepolicy/: device/google/coral-sepolicy checkout 62e763db9e8e79c201946660653feab3fec3ed33
error: Cannot checkout device/google/coral-sepolicy
fatal: Unable to create '/mnt/d/AOSP/external/ImageMagick/.git/index.lock': File exists.
Another git process seems to be running in this repository, e.g.
an editor opened by 'git commit'. Please make sure all processes
are terminated then try again. If it still fails, a git process
may have crashed in this repository earlier:
remove the file manually to continue.
error: external/ImageMagick/: platform/external/ImageMagick checkout 60105dc3c4d636694f8c9a7efb39e28507cef107
error: Cannot checkout platform/external/ImageMagick
Checking out: 15% (160/1051) platform/external/google-fonts/arbutus-slabfatal: Unable to create '/mnt/d/AOSP/external/jcommander/.git/index.lock': File exists.
Another git process seems to be running in this repository, e.g.
an editor opened by 'git commit'. Please make sure all processes
are terminated then try again. If it still fails, a git process
may have crashed in this repository earlier:
remove the file manually to continue.
error: external/jcommander/: platform/external/jcommander checkout 83574919c917acc984c225f68f4dcf2a9faff1d6
error: Cannot checkout platform/external/jcommander
Checking out: 19% (202/1051) platform/external/cros/system_apifatal: Unable to create '/mnt/d/AOSP/external/mockftpserver/.git/index.lock': File exists.
Another git process seems to be running in this repository, e.g.
an editor opened by 'git commit'. Please make sure all processes
are terminated then try again. If it still fails, a git process
may have crashed in this repository earlier:
remove the file manually to continue.
error: external/mockftpserver/: platform/external/mockftpserver checkout bd7824e19c697a07d694ba6acdc1be19f138e51e
error: Cannot checkout platform/external/mockftpserver
Checking out: 21% (224/1051) platform/external/easymockfatal: Unable to create '/mnt/d/AOSP/external/libtextclassifier/.git/index.lock': File exists.
Another git process seems to be running in this repository, e.g.
an editor opened by 'git commit'. Please make sure all processes
are terminated then try again. If it still fails, a git process
may have crashed in this repository earlier:
remove the file manually to continue.
error: external/libtextclassifier/: platform/external/libtextclassifier checkout 9b94a0c59dd0102f67def5e732ce535ad2ee35ca
error: Cannot checkout platform/external/libtextclassifier
Checking out: 27% (288/1051) platform/external/libnetfilter_conntrackfatal: Unable to create '/mnt/d/AOSP/external/perfetto/.git/index.lock': File exists.
Another git process seems to be running in this repository, e.g.
an editor opened by 'git commit'. Please make sure all processes
are terminated then try again. If it still fails, a git process
may have crashed in this repository earlier:
remove the file manually to continue.
error: external/perfetto/: platform/external/perfetto checkout fca2f3ae3cb81e3ece194ce2a089bb5c6c4a7d7c
error: Cannot checkout platform/external/perfetto
Checking out: 100% (1051/1051), done in 27m30.281s
error: Unable to fully sync the tree.
error: Checking out local projects failed.
Failing repos:
external/ImageMagick
device/google/coral-sepolicy
cts
external/apache-http
external/jcommander
external/mockftpserver
external/perfetto
external/libtextclassifier
Try re-running with "-j1 --fail-fast" to exit at the first error.
root@DESKTOP-EKL3BCN:/mnt/d/AOSP#

仅从过错信息看如同删了 xxx.lock 文件就能够,但是当删了所有出错的 xxx.lock 文件从新 sync 时仍是会有模块呈现这样的过错信息,这儿查找了一下,说是文件途径巨细写的问题,后面也装备了文件途径巨细写仍是会呈现这样的问题,估量是文件夹创立时没有装备的原因吧,为了防止从头 sync 的费事,就直接改变计划为虚拟机了,放弃了从 Windows 上直接导入源码的便利性仍是挺惋惜的,看个人取舍吧。

SMB: www.jianshu.com/p/39bbc3631…

Hyper-V 虚拟机

虚拟机是除了双体系外的一个不错的选择,一切都很接近物理机,几乎没有啥兼容性的问题

根底过程

参阅以上 通用 Debian 体系下载编译过程

宿主与虚拟机互通

有些依靠装置指令手打很费事,能够粘贴最好,都说运用 linux-vm-tools 这儿我没有试成功过,这儿贴个参阅衔接,这儿我运用的 ssh 计划,PowerShell 自带 ssh 客户端,而 Ubuntu 则需求给他装置,经过指令 sudo apt install openssh-server 装置,之后经过 PowerShellssh 衔接即可,这样能够直接经过 ssh 装置依靠。

结语

想了想,想说的有点多,就先不说了吧,不过有一点必须得说,那便是:CSDN 真厌恶!未登录都不让仿制了,各种厌恶用户的操作,怪不得用户都流向其他平台了,不尊重用户用户是会用脚投票的!给大家个 Tips,能够在手机浏览器中进行仿制后经过其他软件如 QQ 发送至电脑后运用;

参阅

  1. blog.csdn.net/learnframew…
  2. blog.csdn.net/ding1145536…
  3. blog.csdn.net/gs344937933…
  4. www.cnblogs.com/caoxinyu/p/…
  5. blog.csdn.net/qq_23327993…
  6. 权限 www.sohu.com/a/315996924…
  7. blog.csdn.net/qq_37207639…
  8. 多版别操控 zhuanlan.zhihu.com/p/20797436
  9. 多版别操控www.jianshu.com/p/7315f8b10… todo : sudo update-alternatives –set java /usr/local/jdk1.8.0_281/bin/java sudo update-alternatives –set javac /usr/local/jdk1.8.0_281/bin/javac sudo update-alternatives –set javaws /usr/local/jdk1.8.0_281/bin/javaws