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

查看启动日志:

相关推荐
恋猫de小郭4 小时前
Meta 宣布加入 Kotlin 基金会,将为 Kotlin 和 Android 生态提供全新支持
android·开发语言·ios·kotlin
aqi004 小时前
FFmpeg开发笔记(七十七)Android的开源音视频剪辑框架RxFFmpeg
android·ffmpeg·音视频·流媒体
androidwork6 小时前
深入解析内存抖动:定位与修复实战(Kotlin版)
android·kotlin
梦天20156 小时前
android核心技术摘要
android
szhangbiao8 小时前
“开发板”类APP如果做屏幕适配
android
高林雨露9 小时前
RecyclerView中跳转到最后一条item并确保它在可视区域内显示
android
移动开发者1号11 小时前
ReLinker优化So库加载指南
android·kotlin
山野万里__11 小时前
C++与Java内存共享技术:跨平台与跨语言实现指南
android·java·c++·笔记
Huckings11 小时前
Android 性能问题
android
移动开发者1号12 小时前
剖析 Systrace:定位 UI 线程阻塞的终极指南
android·kotlin