编译LineageOS模拟器镜像,导出到AndroidStudio

版权归作者所有,如有转发,请注明文章出处:https://cyrus-studio.github.io/blog/

源码下载

LineageOS官网:https://lineageos.org/
LineageOS源码 github 地址:https://github.com/LineageOS/android
LineageOS源码国内镜像地址:https://mirrors.tuna.tsinghua.edu.cn/help/lineageOS/

源码大概需要150GB的硬盘空间,编译完成差不多300G
截图.png

1. 配置git

git config --global user.email "you@example.com"
git config --global user.name "Your Name"

2. 安装 repo

mkdir ~/bin
PATH=~/bin:$PATH
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo

3. 安装 Git LFS

sudo apt install git-lfs
git lfs install

4. 设置REPO_URL

找到 repo 所在路径

which repo

编辑 repo

nano /home/cyrus/bin/repo

截图.png
可以看到repo会优先取环境变量中的REPO_URL,否则默认使用googlesource

Ctrl +X 退出nano

通过下面的命令设置 REPO_URL 环境变量,设置为清华大学镜像源,解决国内访问不了 googlesource 问题

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

5. 下载源码

创建目录

mkdir lineageos

进入到 lineageos 目录

cd lineageos

如果可正常访问 github,使用下面的命令初始化 repo

repo init -u https://github.com/LineageOS/android.git -b lineage-21.0 --git-lfs

否则,使用清华大学镜像初始化 repo,并修改 default.xml

repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/lineageOS/LineageOS/android.git -b lineage-21.0 --git-lfs

打开 .repo/manifests/default.xml,将

  <remote  name="github"fetch=".."review="review.lineageos.org" />

改成

<remote  name="github"fetch="https://github.com/" /><remote  name="lineage"fetch="https://mirrors.tuna.tsinghua.edu.cn/git/lineageOS/"review="review.lineageos.org" />

<remote  name="aosp"fetch="https://android.googlesource.com" >

改成

<remote  name="aosp"fetch="https://mirrors.tuna.tsinghua.edu.cn/git/AOSP">

将 remote=“github”

 <default revision="..."remote="github">

改成 remote=“lineage”

<default revision="..."remote="lineage">

或者直接修改 .gitconfig,把访问 LineageOS 仓库的 url 替换为使用清华大学镜像源

cat >> ~/.gitconfig <<EOF[url "https://mirrors.tuna.tsinghua.edu.cn/git/git-repo"]
insteadof = https://gerrit.googlesource.com/git-repo
[url "https://mirrors.tuna.tsinghua.edu.cn/git/lineageOS/"]
insteadof = https://review.lineageos.org/
[url "https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/"]
insteadof = https://android.googlesource.com/
[url "https://mirrors.tuna.tsinghua.edu.cn/git/lineageOS/LineageOS/"]
insteadof = https://github.com/LineageOS/
EOF

最后,同步源码

repo sync

6. 解决同步不完整问题

error: Unable to fully sync the tree
error: Checking out local projects failed.
Failing repos:
android
device/generic/goldfish
device/generic/mini-emulator-x86
external/ImageMagick
build/blueprint
Try re-running with "-j1 --fail-fast" to exit at the first error.
================================================================================
Repo command failed due to the following `SyncError` errors:
Cannot initialize work tree for LineageOS/android
Cannot initialize work tree for device/generic/goldfish
Cannot initialize work tree for device/generic/mini-emulator-x86
Cannot initialize work tree for LineageOS/android_external_ImageMagick
Cannot initialize work tree for platform/build/blueprint

尝试使用单线程同步,减少同步过程中的冲突。

repo sync -j1 --fail-fast

这会在第一个错误发生时终止同步,以便更容易定位和解决问题。

或者,清理工作树,手动删除有问题的项目并重新同步

rm -rf .repo/projects/device/generic/goldfish.git
rm -rf .repo/projects/device/generic/mini-emulator-x86.git
rm -rf .repo/projects/external/ImageMagick.git
rm -rf .repo/projects/build/blueprint.git
repo sync

设置缓存

创建缓存目录

mkdir -p /mnt/case_sensitive/ccache

把缓存配置添加到环境变量配置文件.bashrc结尾

cat >> ~/.bashrc <<EOF
# 使用缓存
export USE_CCACHE=1
# ccache文件路径
export CCACHE_EXEC=/usr/bin/ccache
# 设置缓存目录
export CCACHE_DIR=/mnt/case_sensitive/ccache
EOF

执行下面命令使配置生效

source ~/.bashrc

设置最大缓存空间为 50GB

ccache -M 50G

启用 ccache 的压缩功能,可以减少缓存文件所占用的磁盘空间

ccache -o compression=true

开始编译

# 初始化编译环境
source build/envsetup.sh# 设置构建目标
breakfast sdk_phone_x86_64 eng# 开始编译
mka

breakfast 是 LineageOS 构建系统中的一个命令,用于设置构建环境。它会下载并配置设备相关的源代码和依赖项。

sdk_phone_x86_64 指目标设备的代码名称。在这个例子中,它代表一个用于 Android 模拟器的 x86_64 架构的虚拟手机设备。

具体参考:https://wiki.lineageos.org/emulator
截图.png

在构建 LineageOS 时,eng 和 userdebug 是两种不同的构建类型,它们主要在调试功能和安全性方面有所区别

eng:

  • 适用于开发者调试使用。

  • 含有完全无优化的调试功能,允许广泛的日志记录、调试器连接和各种测试。

  • 安全性较低,没有启用某些生产环境中的安全措施。

userdebug:

  • 适用于调试接近生产环境的构建。

  • 含有用户构建的所有功能,但保留了一些调试工具,安全性高于 eng 构建。

  • 更加接近最终用户使用的环境,同时仍然允许调试。

总之,eng 更适合深入的开发调试,而 userdebug 适合在接近生产环境的条件下进行调试。

解决编译报错

__1. exit status 137 __

[ 55% 50817/91235] //packages/apps/HTMLViewer:HTMLViewer r8
Warning: The rule `-checkdiscard interface kotlin.coroutines.jvm.internal.DebugMetadata` matches a class not in the program.
18:03:04 ninja may be stuck, check /mnt/case_sensitive/lineageos/out/soong.log for list of running processes.
18:03:04 ninja may be stuck, check /mnt/case_sensitive/lineageos/out/soong.log for list of running processes.                        
18:03:04 ninja failed with: exit status 137                                                                                          
#### failed to build some targets (02:14:44 (hh:mm:ss)) #### 

exit status 137 通常表示进程因内存不足被系统杀死。可以使用 htop 或 free -h 命令检查内存使用情况。
如果内存不足,可以尝试增加虚拟机的内存,或在本地机器上添加交换分区。

# 创建一个新的16G交换文件
sudo fallocate -l 16G /mnt/case_sensitive/swapfile# 将交换文件的权限设置为600,以确保只有root用户可以读取和写入该文件。
sudo chmod 600 /mnt/case_sensitive/swapfile# 将交换文件格式化为swap格式
sudo mkswap /mnt/case_sensitive/swapfile# 启用新的交换文件
sudo swapon /mnt/case_sensitive/swapfile# 使用 swapon --show 或 free -h 命令验证新的交换文件是否已正确启用。
swapon --show
# 或
free -h

为了确保 /mnt/case_sensitive/swapfile 在重启后仍然有效,将其添加到/etc/fstab文件中

echo '/mnt/case_sensitive/swapfile swap swap sw 0 0
' | sudo tee -a /etc/fstab

2. Read-only file system: '/home/*/.repo.gitconfig.json’_

这个错误表明在编译过程中尝试写入一个只读文件,报错如下

OSError: [Errno 30] Read-only file system: '/home/cyrus/.repo_.gitconfig.json'
\nWrite to a read-only file system detected. Possible fixes include
1\. Generate file directly to out/ which is ReadWrite, #recommend solution
2\. BUILD_BROKEN_SRC_DIR_RW_ALLOWLIST := <my/path/1> <my/path/2> #discouraged, subset of source tree will be RW
3\. BUILD_BROKEN_SRC_DIR_IS_WRITABLE := true #highly discouraged, entire source tree will be RW
19:26:39 ninja failed with: exit status 1

给 .repo_.gitconfig.json 文件添加写入权限,再重新编译

cyrus@cyrus-studio:/mnt/case_sensitive/lineageos$ chmod a+w ~/.repo_.gitconfig.json
cyrus@cyrus-studio:/mnt/case_sensitive/lineageos$ ls -alh /home/cyrus/.repo_.gitconfig.json
-rw-rw-rw- 1 cyrus cyrus 442 Aug 30 21:41 /home/cyrus/.repo_.gitconfig.json

发现还是不行,使用 nano 命令编辑 .repo_.gitconfig.json 随便修改一下保存,再编辑改回来,再重新编译,可以了。

nano /home/cyrus/.repo_.gitconfig.json

编译完成

image.png

启动模拟器

执行 emulator 命令启动模拟器

启动失败,报错如下

INFO    | Storing crashdata in: /tmp/android-cyrus/emu-crash-34.2.7.db, detection is enabled for process: 1799459
INFO    | Android emulator version 34.2.7.0 (build_id 11381971) (CL:N/A)
INFO    | Storing crashdata in: /tmp/android-cyrus/emu-crash-34.2.7.db, detection is enabled for process: 1799459
INFO    | Duplicate loglines will be removed, if you wish to see each individual line launch with the -log-nofilter flag.
INFO    | Changing default hw.initialOrientation to portrait
ProbeKVM: This user doesn't have permissions to use KVM (/dev/kvm).
The KVM line in /etc/group is: [kvm:x:109:]If the current user has KVM permissions,
the KVM line in /etc/group should end with ":" followed by your username.If we see LINE_NOT_FOUND, the kvm group may need to be created along with permissions:sudo groupadd -r kvm# Then ensure /lib/udev/rules.d/50-udev-default.rules contains something like:# KERNEL=="kvm", GROUP="kvm", MODE="0660"# and then run:sudo gpasswd -a $USER kvmIf we see kvm:... but no username at the end, running the following command may allow KVM access:sudo gpasswd -a $USER kvmYou may need to log out and back in for changes to take effect.ERROR   | x86_64 emulation currently requires hardware acceleration!
CPU acceleration status: This user doesn't have permissions to use KVM (/dev/kvm).
The KVM line in /etc/group is: [kvm:x:109:]If the current user has KVM permissions,
the KVM line in /etc/group should end with ":" followed by your username.If we see LINE_NOT_FOUND, the kvm gr
More info on configuring VM acceleration on Linux:
https://developer.android.com/studio/run/emulator-acceleration#vm-linux
General information on acceleration: https://developer.android.com/studio/run/emulator-acceleration.

这个错误是因为 QEMU 启用硬件加速( KVM)失败了。

确认 /dev/kvm 的权限是否正确。你可以通过以下命令检查

$ ls -l /dev/kvm
crw-rw---- 1 cyrus kvm 10, 232 Aug 31 21:01 /dev/kvm

输出应该类似于 crw-rw---- 1 YourUserName kvm 10, 232 date /dev/kvm,其中
kvm 是该设备的组。

如果权限设置不正确,你可以尝试以下命令修复

sudo apt install qemu-kvm
sudo adduser $USER kvm
sudo chown $USER:kvm /dev/kvm
sudo chmod 660 /dev/kvm

最后重新执行 emulator 启动模拟器
image.png

导出用于 Android Studio/AVD

将构建的镜像导出为 Android Studio/AVD 可使用的格式,通过以下命令

LineageOS 20 及以下版本

mka sdk_addon

构建完成后在 out/host/linux-x86/sdk_addon 目录,会生成一个 ZIP 文件(文件名以 -img.zip 结尾),其中包含在外部运行模拟器镜像所需的所有文件。

LineageOS 21 及以上版本

mka emu_img_zip

构建完成后在 out/target/product/ 目录,会生成一个 ZIP 文件 sdk-repo-linux-system-images.zip,其中包含在外部运行模拟器镜像所需的所有文件。
image.png

将 zip 文件解压到 android sdk 的 system-images 目录下,解压路径如下

system-images/android-<sdk version>/<tag>/<arch>  (其中 <tag> 是 default/google_apis/google_apis_playstore 中的一个)

image.png

在 Android Studio 的【Device Manager】【Create Virtual Device】中创建虚拟设备并选择 LineageOS 镜像
image.png

最终在Android Studio下运行效果如下
image.png

参考:
https://wiki.lineageos.org/emulator

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/pingmian/52823.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

编写一个每次随机生成 10个 0(包括) 到 100 之间的随机正整数。

编写一个每次随机生成 10个 0&#xff08;包括&#xff09; 到 100 之间的随机正整数。 package cn.itcast.example;import java.util.Iterator; import java.util.Random; public class example {public static void main (String[] arge) {System.out.println("Math.ra…

QNN:基于QNN+example重构之后的yolov8det部署

QNN是高通发布的神经网络推理引擎&#xff0c;是SNPE的升级版&#xff0c;其主要功能是&#xff1a; 完成从Pytorch/TensorFlow/Keras/Onnx等神经网络框架到高通计算平台的模型转换&#xff1b; 完成模型的低比特量化&#xff08;int8&#xff09;&#xff0c;使其能够运行在高…

超长二进制利用Integer转换

1.Integer缺点 目前测试Integer只能一次性转4*7位二进制数&#xff0c;也就是7位16进制&#xff0c;故进行改进 2.改进 操作&#xff1a;每四位二进制一转换&#xff0c;以免到上限报错 注解格式&#xff1a;序号&#xff08;代码顺序&#xff09;解释 public class Main {…

《PCI Express体系结构导读》随记 —— 第II篇 第7章 PCIe总线的数据链路层与物理层(2)

接前一篇文章&#xff1a;《PCI Express体系结构导读》随记 —— 第II篇 第7章 PCIe总线的数据链路层与物理层&#xff08;1&#xff09; 7.1 数据链路层的组成结构 数据链路层使用ACK/NAK协议发送和接收TLP&#xff0c;由发送部件和接收部件组成。其中&#xff0c;发送部件由…

Springboot里集成Mybatis-plus、ClickHouse

&#x1f339;作者主页&#xff1a;青花锁 &#x1f339;简介&#xff1a;Java领域优质创作者&#x1f3c6;、Java微服务架构公号作者&#x1f604; &#x1f339;简历模板、学习资料、面试题库、技术互助 &#x1f339;文末获取联系方式 &#x1f4dd; Springboot里集成Mybati…

基于Java+SpringBoot+Vue的汽车销售网站

基于JavaSpringBootVue的汽车销售网站 前言 ✌全网粉丝20W,csdn特邀作者、博客专家、CSDN[新星计划]导师、java领域优质创作者,博客之星、掘金/华为云/阿里云/InfoQ等平台优质作者、专注于Java技术领域和毕业项目实战✌ &#x1f345; 某信 gzh 搜索【智能编程小助手】获取项…

【大模型】llama系列模型基础

前言&#xff1a;llama基于transformer架构&#xff0c;与GPT相似&#xff0c;只用了transformer的解码器部分。本文主要是关于llama&#xff0c;llama2和llama3的结构解读。 目录 1. llama1.1 整体结构1.2 RoPE1.3 SwiGLU 激活函数 2. llama22.2 GQA架构2.3 RLHF 3. llama3参考…

Springboot中使用Elasticsearch(部署+使用+讲解 最完整)

目录 引言 一、docker中安装Elasticsearch 1、创建es专有的网络 2、开放端口 3、在es-net网络上安装es和kibana 4、可能出现的问题 5、测试 6、安装IK分词器 7、测试IK分词器 二、结合业务实战 1、准备依赖 2、配置yml 3、读取yml配置 4、准备es配置类 5、编写测…

Leetcode面试经典150题-136.只出现一次的数字

解法都在代码里&#xff0c;不懂就留言或者私信 这个题不知道为啥会考&#xff0c;过于简单了&#xff0c;我解题写注释用了两分钟不到&#xff0c;5行代码。。。 class Solution {public int singleNumber(int[] nums) {/**这个题目确实时间的题&#xff0c;根据位运算法则我…

斗破C++编程入门系列之十九:C++程序设计必知:多文件结构和编译预处理命令(九星斗者)

斗破C目录&#xff1a; 斗破C编程入门系列之前言&#xff08;斗之气三段&#xff09; 斗破C编程入门系列之二&#xff1a;Qt的使用介绍&#xff08;斗之气三段&#xff09; 斗破C编程入门系列之三&#xff1a;数据结构&#xff08;斗之气三段&#xff09; 斗破C编程入门系列之…

ctfshow之web55~web57(无字母的rce)

目录 web55 思路一&#xff1a; 思路二&#xff1a; web56 web57 本系列主要针对无字母rce或无字母无数字rce 声明&#xff1a;本章内容是引荐几位师傅的博客&#xff0c;然后根据自己的理解编写而成。 web55 if(isset($_GET[c])){$c$_GET[c];if(!preg_match("/\…

乐凡三防:工业界的硬核产品——重新定义三防平板的极限

在工业4.0的浪潮中&#xff0c;科技与制造业的深度融合催生了一系列高性能、高耐用的智能产品。乐凡三防平板&#xff0c;作为工业界的新宠&#xff0c;正以其卓越的防护性能和强大的功能&#xff0c;重新定义了三防平板的极限&#xff0c;成为硬核科技的代表。 硬核防护&#…

GD32F4xx---RTC初始化设置及闹钟方式实现秒中断讲解

GD32F4xx—RTC初始化设置及闹钟方式实现秒中断讲解 1、下载链接:源码工程 一、概述 GD32F4x的RTC例程网上资源较少,详细阅读用户手册后做出如下配置。RTC模块提供了一个包含日期(年/月/日)和时间(时/分/秒/亚秒)的日历功能。除亚秒用二进制码显示外,时间和日期都以BC…

大连网站建设手机网页页面设计

在现代社会&#xff0c;随着智能手机的普及&#xff0c;越来越多的用户选择通过手机访问网站&#xff0c;这使得移动端网页设计的重要性日益凸显。大连作为一个经济和文化中心&#xff0c;网站建设行业也在不断发展。针对大连的网站建设&#xff0c;手机网页页面设计需要特别注…

内存管理篇-16二级页表工作原理

1.修正上节课的转换图 上节课的页表的一级页表其实并不完全正确&#xff0c;一般虚拟页帧和物理页帧号不会都占用实际字段&#xff0c;这样毕竟很浪费内存。 2.再分析一下页表的开销情况&#xff1a; 一级页表&#xff1a;以4KB物理页为映射单位&#xff0c;每个进程4MB的虚…

动态读取nacos中修改的项目配置文件

本项目用的还是springboot项目&#xff0c;咱们直接上代码 一&#xff1a;首先看下nacos中需要动态获取的属性 二&#xff1a;把需要动态读取的配置类中的属性整理一个实体类 mport lombok.Data; import org.springframework.boot.context.properties.ConfigurationPropert…

Python酷库之旅-第三方库Pandas(114)

目录 一、用法精讲 501、pandas.DataFrame.mode方法 501-1、语法 501-2、参数 501-3、功能 501-4、返回值 501-5、说明 501-6、用法 501-6-1、数据准备 501-6-2、代码示例 501-6-3、结果输出 502、pandas.DataFrame.pct_change方法 502-1、语法 502-2、参数 502…

Django 第十一课 -- ORM - 多表实例

目录 一. 前言 二. 创建模型 三. 插入数据 四. ORM - 添加数据 4.1. 一对多(外键 ForeignKey) 4.2. 多对多(ManyToManyField)&#xff1a;在第三张关系表中新增数据 4.3. 关联管理器(对象调用) 五. ORM 查询 5.1. 一对多 5.2. 一对一 5.3. 多对多 六. 基于双下划线…

SprinBoot+Vue实验室考勤管理小程序的设计与实现

目录 1 项目介绍2 项目截图3 核心代码3.1 Controller3.2 Service3.3 Dao3.4 application.yml3.5 SpringbootApplication3.5 Vue3.6 uniapp代码 4 数据库表设计5 文档参考6 计算机毕设选题推荐7 源码获取 1 项目介绍 博主个人介绍&#xff1a;CSDN认证博客专家&#xff0c;CSDN平…

【机器学习】数据预处理-特征工程与特征选择

目录 一、特征工程 二、数据变换 1.变换 2.归一化 三、数据清洗 1.异常数据 2.数据清洗 四、特征选择 1.Filter过滤法 2.Wrapper包裹法 ... 3.Embedded嵌入法 ... 五、降维算法 1.SVD 2.PCA 一、特征工程 特征工程就是从原始数据提取特征的过程&#xff0c;这些…