玩转Android Framework:使用Android Cuttlefish

本文将介绍Android Cuttlefish的安装和使用。

系统版本: Ubuntu 22.04 lts

AOSP分支: android-14.0.0_r28

什么是Android Cuttlefish?

简单的来说,Android Cuttlefish是一种可以托管在云端的Android模拟器。

这是Android Cuttlefish的官方文档:

source.android.com/docs/setup/...

为什么需要Android Cuttlefish

在实际开发中,我们的代码实际编译过程可能是发生在远程的服务器,那么当编译完成的时候,如果我们想看到我们的编译之后的系统的实际运行效果,可能就需要将编译好的image下载到本地刷进实机或模拟器,才能查看效果等。

那么问题来了,我们可不可以把模拟器运行在云端,直接通过浏览器就能看到我们的编译好的系统的运行效果呢?

Android Cuttlefish就是在这个基础上诞生的。

安装Android Cuttlefish

下面我们就来介绍怎样安装Android Cuttlefish,我的为ubuntu 22.04 lts

第一步 检查虚拟化支持

运行

bash 复制代码
grep -c -w "vmx\|svm" /proc/cpuinfo

如果返回值大于0,那么进行下一步。

第二步 安装依赖

bash 复制代码
sudo apt install -y git devscripts config-package-dev debhelper-compat curl

第三步 下载源码

Cuttlefish的源码在:

github.com/google/andr...

在我们的工作目录运行:

bash 复制代码
git clone https://github.com/google/android-cuttlefish.git

下载完成之后进入cuttlefish目录:

bash 复制代码
cd android-cuttlefish

第四步 确认Go语言版本支持

确定系统Go语言版本:

bash 复制代码
go version

如果没有安装Go或者版本小于1.15,那么请安装或升级到最新版的Go:

go.dev/doc/install

第五步 修改脚本

由于国内访问不了国外的Go库,所以我们需要设置代理,打开/android-cuttlefish/frontend/src/goutil,删除export GOPROXY="proxy.golang.org|proxy.golang.org|direct"这一行:

增加如下两行代码:

bash 复制代码
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,direct

第六步 编译deb包

android-cuttlefish目录运行:

bash 复制代码
for dir in base frontend; do
  cd $dir
  debuild -i -us -uc -b -d
  cd ..
done

等待一段时间,如果编译成功,那么在根目录应该就可以看到以下的这些deb文件:

关于这些deb包有什么区别,github上有详细的解释:

实际上我们只需要baseuser就可以了。

第七步 安装deb包

bash 复制代码
sudo apt install ./cuttlefish-base_*.deb ./cuttlefish-user_*.deb

安装成功以后,就可以开始编译我们的AOSP并运行Android Cuttlefish了。

编译AOSP并运行Android Cuttlefish

bash 复制代码
. build/envsetup.sh
lunch aosp_cf_x86_64_phone-userdebug
make

注意,这里我们的lunch目标是aosp_cf_x86_64_phone-userdebug

等待编译完成之后执行:

bash 复制代码
launch_cvd

如果运行报kvm相关的错误,运行以下指令:

bash 复制代码
sudo usermod -aG kvm,cvdnetwork,render 你的用户名

之后重启:

bash 复制代码
sudo reboot

重启完成之后再执行:

bash 复制代码
. build/envsetup.sh
lunch aosp_cf_x86_64_phone-userdebug
launch_cvd

Android Cuttlefish运行成功之后,浏览器访问https://localhost:8443/,无视浏览器不安全提醒,然后就能看到如下画面:

然后启用我们的设备,就可以看到我们的模拟器了:

相关推荐
液态不合群35 分钟前
【面试题】MySQL 中 count(*)、count(1) 和 count(字段名) 有什么区别?
android·数据库·mysql
雪球Snowball2 小时前
【Android关键流程】资源加载
android
2501_915918412 小时前
常见 iOS 抓包工具的使用,从代理抓包、设备抓包到数据流抓包
android·ios·小程序·https·uni-app·iphone·webview
墨月白4 小时前
[QT]QProcess的相关使用
android·开发语言·qt
enbug4 小时前
编译安卓内核:以坚果R1、魔趣MK100(Android 10)系统为例
android·linux
、BeYourself4 小时前
应用专属文件与应用偏好设置(SharedPreferences)
android
2501_948120155 小时前
基于模糊数学的风险评估模型
android
MengFly_5 小时前
Compose 脚手架 Scaffold 完全指南
android·java·数据库
·云扬·6 小时前
MySQL Binlog三种记录格式详解
android·数据库·mysql
月明泉清6 小时前
Android中对于点击事件的深度梳理(二)
android