从0到1学Binder-环境准备

前言

终于要开始啃 binder 了,其实还没准备好,但是先走出去吧,目标是 2024 年一个整年能把 binder 学完。

我的微信公众号"ZZH的Android",还有更多 Android 系统源码解析的干货文章等着你。

1 环境配置

Ubuntu 22.04

Cuttlefish 模拟器:

AOSP 版本: Android 14

Android Kernel 版本: 6.1

2 环境搭建

2.1 Cuttlefish 环境准备

bash 复制代码
sudo apt install -y git devscripts config-package-dev debhelper-compat golang curl
git clone https://github.com/google/android-cuttlefish
cd android-cuttlefish
for dir in base frontend; do
  cd $dir
  debuild -i -us -uc -b -d
  cd ..
done
sudo dpkg -i ./cuttlefish-base_*_*64.deb || sudo apt-get install -f
sudo dpkg -i ./cuttlefish-user_*_*64.deb || sudo apt-get install -f
sudo usermod -aG kvm,cvdnetwork,render $USER
sudo reboot

2.2 Android 14 下载编译

bash 复制代码
// 代码下载
repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest -b android-14.0.0_r17
repo sync
repo start --all android-14.0.0_r17

// 代码编译
source build/envsetup.sh
// 注意,一定要选cf的,他是Cuttlefish的缩写
lunch aosp_cf_x86_64_phone-userdebug
make -j8

2.3 Android Kernel 下载编译

bash 复制代码
// 代码下载
mkdir android-kernel
cd android-kernel
repo init -u https://android.googlesource.com/kernel/manifest -b common-android14-6.1
repo sync
// 代码编译,Android13之后的用bazel编译
tools/bazel run //common-modules/virtual-device:virtual_device_x86_64_dist
// 注意两个编译产物,后面会用
out/virtual_device_x86_64/dist/bzImage
out/virtual_device_x86_64/dist/initramfs.img

2.4 启动 Cuttlefish 模拟器

下载 cvd-host_package.tar.gz,用于启动和结束模拟器设备

ruby 复制代码
参考链接: https://source.android.google.cn/docs/setup/create/cuttlefish-use?hl=zh-cn
或者用如下链接直接下载:
https://ci.android.com/builds/submitted/11339591/aosp_cf_arm64_phone-userdebug/latest/cvd-host_package.tar.gz

新建路径解压上述文件

bash 复制代码
mkdir -p ~/work/android-cuttlefish/android14
cd ~/work/android-cuttlefish/android14
tar -xvf cvd-host_package.tar.gz

编写启动脚本 start

ruby 复制代码
# 以下涉及到的路径换成自己的路径
HOME=/home/zzh/work/aosp/android-14.0.0_r17/out/target/product/vsoc_x86_64
./bin/launch_cvd --daemon \
    -kernel_path=/home/zzh/work/android-kernel/out/virtual_device_x86_64/dist/bzImage \
    -initramfs_path=/home/zzh/work/android-kernel/out/virtual_device_x86_64/dist/initramfs.img

启动成功后如下:

此时没有界面显示,需要我们用投屏软件来查看界面,这里用的是 scrcpy

退出脚本 stop

ruby 复制代码
HOME=/home/zzh/work/aosp/android-14.0.0_r17/out/target/product/vsoc_x86_64
./bin/stop_cvd

退出成功后如下:

我们尝试修改下 binder 的代码

查看启动日志:

相关推荐
沐怡旸1 天前
【底层机制】【Android】深入理解UI体系与绘制机制
android·面试
啊森要自信1 天前
【GUI自动化测试】YAML 配置文件应用:从语法解析到 Python 读写
android·python·缓存·pytest·pip·dash
下位子1 天前
『AI 编程』用 Codex 开发识字小帮手应用
android·openai·ai编程
Zender Han1 天前
Flutter 实现人脸检测 — 使用 google_mlkit_face_detection
android·flutter·ios
君逸臣劳1 天前
玩Android Flutter版本,通过项目了解Flutter项目快速搭建开发
android·flutter
叫我龙翔1 天前
【MySQL】从零开始了解数据库开发 --- 基本查询
android·mysql·数据库开发
2501_916008891 天前
iOS 26 性能分析深度指南 包含帧率、渲染、资源瓶颈与 KeyMob 协助策略
android·macos·ios·小程序·uni-app·cocoa·iphone
撩得Android一次心动1 天前
Android adb 基础使用指南
android·adb
为java加瓦1 天前
PHP MQTT 订阅服务:实时消息接收与数据库存储解决方案
android
怿星科技1 天前
Android MVVM架构解析:现代开发的首选模式
android·架构