从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 的代码

查看启动日志:

相关推荐
程序员陆业聪3 小时前
从 OpenClaw 到 Android:Harness Engineering 是怎么让 Agent 变得可用的
android
hnlgzb5 小时前
常见的Android Jetpack库会有哪些?这些库中又有哪些常用类的?
android·android jetpack
钛态8 小时前
Flutter 三方库 http_mock_adapter — 赋能鸿蒙应用开发的高效率网络接口 Mock 与自动化测试注入引擎(适配鸿蒙 HarmonyOS Next ohos)
android·网络协议·flutter·http·华为·中间件·harmonyos
王码码20358 小时前
Flutter for OpenHarmony:Flutter 三方库 algoliasearch 毫秒级云端搜索体验(云原生搜索引擎)
android·前端·git·flutter·搜索引擎·云原生·harmonyos
左手厨刀右手茼蒿8 小时前
Flutter for OpenHarmony: Flutter 三方库 shamsi_date 助力鸿蒙应用精准适配波斯历法(中东出海必备)
android·flutter·ui·华为·自动化·harmonyos
代码飞天8 小时前
wireshark的高级使用
android·java·wireshark
2501_915918419 小时前
苹果App Store上架审核卡住原因分析与解决方案指南
android·ios·小程序·https·uni-app·iphone·webview
skiy10 小时前
MySQL Workbench菜单汉化为中文
android·数据库·mysql
小小小点10 小时前
Android四大常用布局详解与实战
android
MinQ11 小时前
binder和socket区别及原理
android