2021年11月12日

2022ubuntu完美搭建ASOP源码编译环境(国内镜像)2–开始编译

作者 huruwo

编译步骤

接上篇的下载asop完成 开始搭建编译环境

1.下载open jdk
2.编译链
3.开始编译
4.下载手机驱动

1.安装open jdk

sudo apt install openjdk-8-jdk-headless

测试验证

java -version
openjdk version "1.8.0_292"
OpenJDK Runtime Environment (build 1.8.0_292-8u292-b10-0ubuntu1~18.04-b10)
OpenJDK 64-Bit Server VM (build 25.292-b10, mixed mode)

2.安装编译链工具


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

一路下来 ok就行

3.开始编译

同步编译配置

source build/envsetup.sh
source build/envsetup.sh
including device/asus/fugu/vendorsetup.sh
including device/generic/car/car-arm64/vendorsetup.sh
including device/generic/car/car-armv7-a-neon/vendorsetup.sh
including device/generic/car/car-x86_64/vendorsetup.sh
including device/generic/car/car-x86/vendorsetup.sh
including device/generic/mini-emulator-arm64/vendorsetup.sh
including device/generic/mini-emulator-armv7-a-neon/vendorsetup.sh
including device/generic/mini-emulator-mips64/vendorsetup.sh
including device/generic/mini-emulator-mips/vendorsetup.sh
including device/generic/mini-emulator-x86_64/vendorsetup.sh
including device/generic/mini-emulator-x86/vendorsetup.sh
including device/google/dragon/vendorsetup.sh
including device/google/marlin/vendorsetup.sh
including device/huawei/angler/vendorsetup.sh
including device/lge/bullhead/vendorsetup.sh
including device/linaro/hikey/vendorsetup.sh
including sdk/bash_completion/adb.bash

选择编译分支

输入

lunch

查看分支信息

You're building on Linux

Lunch menu... pick a combo:
     1. aosp_arm-eng
     2. aosp_arm64-eng
     3. aosp_mips-eng
     4. aosp_mips64-eng
     5. aosp_x86-eng
     6. aosp_x86_64-eng
     7. full_fugu-userdebug
     8. aosp_fugu-userdebug
     9. car_emu_arm64-userdebug
     10. car_emu_arm-userdebug
     11. car_emu_x86_64-userdebug
     12. car_emu_x86-userdebug
     13. mini_emulator_arm64-userdebug
     14. m_e_arm-userdebug
     15. m_e_mips64-eng
     16. m_e_mips-userdebug
     17. mini_emulator_x86_64-userdebug
     18. mini_emulator_x86-userdebug
     19. aosp_dragon-userdebug
     20. aosp_dragon-eng
     21. aosp_marlin-userdebug
     22. aosp_marlin_svelte-userdebug
     23. aosp_sailfish-userdebug
     24. aosp_angler-userdebug
     25. aosp_bullhead-userdebug
     26. aosp_bullhead_svelte-userdebug
     27. hikey-userdebug

Which would you like? [aosp_arm-eng]

23 是我的pixel 选择23就行

4.导入手机驱动文件(pixel为例)

去这个地址

https://developers.google.com/android/drivers

找到谷歌亲儿子相关的驱动文件

如果是其他手机 需要厂商配置

找到 pixel的8.0系统驱动

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-4reRiznJ-1636427320963)(en-resource://database/1270:1)]

你可能会发现有好几个 pixel的8.0驱动

不要紧 我们来看小的版本号

已知我们下载的是

android-8.0.0_r2这个版本的源码

跑到这个地址研究一下版本

https://source.android.com/setup/build-numbers#source-code-tags-and-builds

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Dvdnltkc-1636427320965)(en-resource://database/1272:1)]

OPR6.170623.011 R2就是这个

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-DmTXTjHL-1636427320967)(en-resource://database/1274:1)]

https://dl.google.com/dl/android/aosp/google_devices-sailfish-opr6.170623.011-b8458495.tgz

https://dl.google.com/dl/android/aosp/qcom-sailfish-opr6.170623.011-929e7f2e.tgz

把这两个文件下载下来 复制到根目录下

都解压出来 并把里面的两个sh文件拖到根目录下

再执行命令

./extract-google_devices-sailfish.sh 
./extract-qcom-sailfish.sh

自行编译出驱动

5.make

做完前面的 可以开始执行编译操作了

make 即可 可以加参数 比如

make -j8 表示多少线程 一般等于核心数就行

开始等待

各种错误

错误主要集中在make步骤 大部分是缺少东西

1.recipe for target 'run_soong_ui' failed

这个是最常见的错误 但是这个错误不是单独测错误

这个地方是抛出错误的地方

所以真正的错误在上面一点点。
大多数时候我们搜到的是

新增 export LC_ALL=C

但是其实要分情况

02:24:06 ninja failed with: exit status 1
build/core/main.mk:21: recipe for target 'run_soong_ui' failed
make: *** [run_soong_ui] Error 1

解决办法

在make之前执行下面操作

export LC_ALL=C
如果不行

vim .bashrc
\# 在文件中添加
#aosp setup
export PATH=~/bin:$PATH
export USE_CCACHE=1
export LC_ALL=C
#保存文件后,执行下面一行
source .bashrc

2.bin/bash: prebuilts/misc/linux-x86/bison/bison: No such file or directory

真正的错误找出来

/bin/bash -c "prebuilts/misc/linux-x86/bison/bison -d -v --defines=out/host/linux-x86/obj/EXECUTABLES/checkpolicy_intermediates/policy_parse.h -o out/host/linux-x86/obj/EXECUTABLES/checkpolicy_intermediates/policy_parse.c external/selinux/checkpolicy/policy_parse.y"
/bin/bash: prebuilts/misc/linux-x86/bison/bison: No such file or directory

[  0% 8/82254] host C: fc_sort <= system/sepolicy/tools/fc_sort/fc_sort.c
ninja: build stopped: subcommand failed.
07:13:21 ninja failed with: exit status 1
build/core/main.mk:21: recipe for target 'run_soong_ui' failed
make: *** [run_soong_ui] Error 1

真正的错误

/bin/bash: prebuilts/misc/linux-x86/bison/bison: No such file or directory

解决


sudo apt-get install bison

sudo apt-get install  lib32readline6-dev #可能找不到

sudo apt-get install lib32readline-gplv2-dev # 替代

sudo apt-get install g++-multilib gcc-multilib lib32ncurses5-dev lib32readline-gplv2-dev lib32z1-dev

这里就是建立链接

3.Jack server failed to (re)start, try 'jack-diagnose' or see Jack server log

open jdk 禁用了

TLSv1, TLSv1.1

我们修改配置打开它

sudo gedit /etc/java-8-openjdk/security/java.security

修改前

jdk.tls.disabledAlgorithms=SSLv3, TLSv1, TLSv1.1, RC4, DES, MD5withRSA, \
    DH keySize < 1024, EC keySize < 224, 3DES_EDE_CBC, anon, NULL, \
    include jdk.disabled.namedCurves

禁用了 TLSv1, TLSv1.1

删掉这两个即可

jdk.tls.disabledAlgorithms=SSLv3, RC4, DES, MD5withRSA, \
    DH keySize < 1024, EC keySize < 224, 3DES_EDE_CBC, anon, NULL, \
    include jdk.disabled.namedCurves

然后小小的重启一下就行

4./bin/bash: xmllint: command not found

少东西了 安装上去

sudo apt-get install libxml2-utils