玩转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/,无视浏览器不安全提醒,然后就能看到如下画面:

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

相关推荐
_龙小鱼_28 分钟前
Kotlin扩展简化Android动画开发
android·开发语言·kotlin
奔跑吧 android1 小时前
【android bluetooth 协议分析 01】【HCI 层介绍 6】【WriteLeHostSupport命令介绍】
android·bluetooth·bt·gd·aosp13·writelehostsup·hcicmd
uwvwko1 小时前
ctfshow——web入门254~258
android·前端·web·ctf·反序列化
顾子茵2 小时前
c++从入门到精通(六)--特殊工具与技术-完结篇
android·开发语言·c++
初遇你时动了情2 小时前
flutter 配置 安卓、Ios启动图
android·flutter·ios
YSoup3 小时前
Android Studio报错Cannot parse result path string:
android·android studio
zhangphil4 小时前
Android Coli 3 ImageView load two suit Bitmap thumb and formal,Kotlin(七)
android·kotlin
与籍同行5 小时前
开发过程中遇到Selinux问题分析
android·selinux
韩仔搭建6 小时前
安卓端互动娱乐房卡系统调试实录:从UI到协议的万字深拆(第一章)
android·ui·娱乐
limingade7 小时前
手机打电话时如何将通话对方的声音在手机上识别成文字
android·智能手机·语音识别·funasr·蓝牙电话·ai电话机器人·funasr安卓移植和部署