当前位置: 首页 > news >正文

Ubuntu20.4编译AOSP源码实践

Ubuntu20.4编译AOSP源码实践

本文记录使用Ubuntu20.4编译AOSP的过程以及一些错误解决,使用的编译的分支为 android-8.1.0_r38

参考清华大学开源软件站构建代码仓库,本文采用repo同步的方式进行构建,构建的操作系统是Ubuntu20.4

一.Ubuntu虚拟机配置

主要关注内存和磁盘大小,本文中我分配了8G内存和200G的磁盘空间

二.依赖库安装

需要安装java环境、官方给定的环境依赖,ubuntu20.4自带python环境,如果没有需自行安装,用到的命令如下

# 环境安装
echo "更新apt-get"
sudo apt-get update
echo "安装jdk8"
yes | sudo apt-get install openjdk-8-jdk
echo "安装python2"
yes | sudo apt-get install python
echo "安装curl"
yes | sudo apt-get install curl
echo "安装git"
yes | sudo apt-get install git
echo "安装依赖"
yes |  sudo apt-get 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 ccache libgl1-mesa-dev libxml2-utils xsltproc unzip
echo "设置git账户"
git config --global user.email "Cubeeeeee@qq.com"
git config --global user.name "Cubeeeeee"

三.AOSP源代码同步

使用清华源同步,代码如下

# 源代码同步
echo "需要将脚本放到工作目录下执行"
mkdir -p ~/bin
PATH=~/bin:$PATHsudo curl -k https://mirrors.tuna.tsinghua.edu.cn/git/git-repo > ~/bin/repo
sudo chmod a+x ~/bin/repo
cd ~/bin/aosp
export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo'
# 如需其他分支 修改此处
yes | repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest -b android-8.1.0_r38
echo "开始同步AOSP源码"
repo sync

同步成功后如下图

image.png

如果同步失败请移步下文错误解决汇总

四.源码编译

涉及到的命令如下,如果出错可以参考下文错误解决

cd ~/bin/aosp
# 如果内存够大可以考虑设置缓存
# prebuilts/misc/linux-x86/ccache/ccache -M 50G 
# 根据自己内存大小调整  默认用6g
export JACK_SERVER_VM_ARGUMENTS="-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx6g"
make clobber
source build/envsetup.sh
# 版本根据需要修改
# lunch 24
lunch
# 线程数根据处理器数量修改
make -j4

五.错误解决

1.Curl下载Repo报SSL Error

添加-k参数,忽略https证书错误 即修改为

sudo curl -k https://mirrors.tuna.tsinghua.edu.cn/git/git-repo > ~/bin/repo

2.同步源码出错,git报CA证书错误

server certificate verification failed. CAfile: none CRLfile: none

禁用git的ssl校验即可

git config --global http.sslverify false
git config --global https.sslverify false

3.同步源码出错,无法连接到 https://android.googlesource.com/

未正确配置环境变量,检查~/.bashrc,正确配置如下图

image.png

或者在同一终端执行

export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo'

4.同步源码出错,python相关错误

修改python优先级,默认使用python3

sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 100
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 150

5.编译报错Jack server(35). Try ‘jack-diagnose’

详细报错内容如下:

[ 10% 538/4980] Ensuring Jack server is installed and started
FAILED: setup-jack-server 
/bin/bash -c "(prebuilts/sdk/tools/jack-admin install-server prebuilts/sdk/tools/jack-launcher.jar prebuilts/sdk/tools/jack-server-4.11.ALPHA.jar  2>&1 || (exit 0) ) && (JACK_SERVER_VM_ARGUMENTS=\"-Dfile.encoding=UTF-8 -XX:+TieredCompilation\" prebuilts/sdk/tools/jack-admin start-server 2>&1 || exit 0 ) && (prebuilts/sdk/tools/jack-admin update server prebuilts/sdk/tools/jack-server-4.11.ALPHA.jar 4.11.ALPHA 2>&1 || exit 0 ) && (prebuilts/sdk/tools/jack-admin update jack prebuilts/sdk/tools/jacks/jack-4.32.CANDIDATE.jar 4.32.CANDIDATE || exit 47 )"
Jack server already installed in "/home/user/.jack-server"
Communication error with Jack server (35), try 'jack-diagnose' or see Jack server log
SSL error when connecting to the Jack server. Try 'jack-diagnose'
SSL error when connecting to the Jack server. Try 'jack-diagnose'
[ 10% 541/4980] build out/target/product/rk3399_mid/obj/ETC/precompiled_sepolicy_intermediates/precompiled_sepolicy
ninja: build stopped: subcommand failed.
22:32:18 ninja failed with: exit status 1#### failed to build some targets (01:11 (mm:ss)) ####Build android failed!

解决方案为修改/etc/java-8-openjdk/security/java.security文件,取消TLSv1, TLSv1.1 禁用,修改后内容如下

image.png

6.编译报错,Python相关错误

错误内容

system/core/libsysutils/EventLogTags.logtags system/core/logcat/event.logtags system/core/logd/event.logtags system/core/storaged/EventLogTags.log
tags”
File “build/tools/merge-event-log-tags.py”, line 51
except getopt.GetoptError, err:
^
SyntaxError: invalid syntax
[ 0% 6/89331] Ensuring Jack server is installed and started
Jack server already installed in “/root/.jack-server”
Server is already running
ninja: build stopped: subcommand failed.

错误原因是编译时需要使用python2.7(源码同步时使用python3.8),只需修改python优先级,优先使用python2.7即可

sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 150
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 100

7.编译报错Jack server(52). Try ‘jack-diagnose’

错误示例

[ 76% 69866/91547] Building with Jack:...k_intermediates/with-local/classes.dex
FAILED: out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/with-local/classes.dex 
/bin/bash out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/with-local/classes.dex.rsp
Communication error with Jack server (52). Try 'jack-diagnose'
[ 76% 69869/91547] //art/compiler:liba...izing/code_generator_x86_64.cc [linux]
ninja: build stopped: subcommand failed.
06:32:11 ninja failed with: exit status 105:16:52.810: INFO: com.android.jack.server.JackHttpServer: Jack 1.3-rc7 'Douarn' (445000 d7be3910514558d6715ce455ce0861ae2f56925a by N/A) available in ./jack/jack-1635487485073-0.jar
05:16:52.811: INFO: com.android.jack.server.JackHttpServer: Starting service connection server on /127.0.0.1:18076

解决方案是设置 JACK_JAR环境变量,在同一终端执行export命令或者写入~/.bashrc即可解决,

如果仍未解决可以尝试同时修改

$HOME/.jack-settings和$HOME/.jack-server/config.properties

中的端口号(比如都改为8386/8387)

8.编译报错 Aborted (core dumped)

错误内容如下

flex-2.5.39: loadlocale.c:130: _nl_intern_locale_data: Assertioncnt < (sizeof (_nl_value_type_LC_TIME) / sizeof (_nl_value_type_LC_TIME[0]))' failed. Aborted (core dumped)

执行

export LC_ALL=C

去除本地化设置

9.编译报错缺少libncurses.so.5

缺少依赖

sudo apt-get install libncurses* 

六.脚本整合

为了便于使用,我将上述过程整理成了几个自动化脚本文件,在Ubuntu20.4下可以自动进行环境配置、源码同步、源码编译

envinstall.sh 环境安装

# 环境安装
echo "更新apt-get"
sudo apt-get update
echo "安装jdk8"
yes | sudo apt-get install openjdk-8-jdk
echo "安装curl"
yes | sudo apt-get install curl
echo "安装git"
yes | sudo apt-get install curl
echo "安装依赖"
yes |  sudo apt-get 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 ccache libgl1-mesa-dev libxml2-utils xsltproc unzip
echo "设置git账户"
git config --global user.email "Cubeeeeee@qq.com"
git config --global user.name "Cubeeeeee"
# 修改java配置文件 否则jack会报 35错误
sudo cp /etc/java-8-openjdk/security/java.security /etc/java-8-openjdk/security/java.security.bak
sudo rm /etc/java-8-openjdk/security/java.security
sudo cp java.security /etc/java-8-openjdk/security/java.security

repo.sh 拉取代码

# 源代码同步
echo "需要将脚本放到工作目录下执行"
mkdir ~/bin
temp=$(pwd) | PATH=$temp:$PATH
# 同步源码时使用python3
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 100
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 150
sudo curl -k https://mirrors.tuna.tsinghua.edu.cn/git/git-repo > ~/bin/repo
sudo chmod a+x ~/bin/repo
export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo'
# 如需其他分支 修改此处
yes | repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest -b android-8.1.0_r38
echo "开始同步AOSP源码"
repo sync

compile.sh 编译

# 编译时使用python2
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 150
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 100
echo "正在清理"
make clobber
source ./build/envsetup.sh
# 版本根据需要修改
echo "选择编译版本"
lunch 24
# lunch
# 线程数根据处理器数量修改
echo "开始全量编译"
make -j4
http://www.lryc.cn/news/579535.html

相关文章:

  • 开源 C# .net mvc 开发(六)发送邮件、定时以及CMD编程
  • XILINX Ultrascale+ Kintex系列FPGA的架构
  • 支持向量机(SVM)分类
  • ReactNative【实战系列教程】我的小红书 3 -- 自定义底栏Tab导航(含图片选择 expo-image-picker 的使用)
  • GPT-2论文阅读:Language Models are Unsupervised Multitask Learners
  • Mac电脑 触摸板增强工具 BetterTouchTool
  • 探秘展销编辑器:相较于传统展销的卓越优势与甄选指南​
  • Redis实现哨兵模式
  • MCP协议打破数据孤岛
  • 在Ubuntu24上安装ollama
  • VsCode 配置 C/C++ 开发环境
  • 【第三章:神经网络原理详解与Pytorch入门】01.神经网络算法理论详解与实践-(3)神经网络中的前向传播、反向传播的原理与实现
  • JavaScript的初步学习
  • 2021/7 N2 jlpt 词汇
  • npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree
  • Apache POI 详解 - Java 操作 Excel/Word/PPT
  • docker-compose一键部署全栈项目。springboot后端,react前端
  • 如何将信息从 iPhone 同步到Mac(完整步骤和示意图)
  • mac 电脑安装Homebrew来安装npm与node成功后,安装nvm的流程
  • MySQL 8.0 OCP 1Z0-908 题目解析(19)
  • 标准测试测试数据STDF学习笔记
  • MediaCrawler:强大的自媒体平台爬虫工具
  • Spring Boot 多 ActiveMQ 通道配置与多连接消息发送实战(含完整示例与踩坑记录)
  • Ubuntu 24.04 LTS 服务器配置:安装 JDK、Nginx、Redis。
  • 一体机电脑为何热度持续上升?消费者更看重哪些功能?
  • 关于系统无法找到 arm-linux-gcc 命令,这表明你的环境中尚未安装 ARM 交叉编译工具链。以下是详细的解决方案:(DIY机器人工房)
  • 牛客:HJ16 购物单【01背包】【华为机考】
  • 封装 获取paramsByKey 方法
  • 毕业设计(启智模块化机器人的组装与K5的使用
  • 使用Visual Studio 2022创建CUDA编程项目