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

查看启动日志:

相关推荐
_extraordinary_4 小时前
MySQL 事务(二)
android·数据库·mysql
鸿蒙布道师8 小时前
鸿蒙NEXT开发动画案例5
android·ios·华为·harmonyos·鸿蒙系统·arkui·huawei
橙子1991101613 小时前
在 Kotlin 中什么是委托属性,简要说说其使用场景和原理
android·开发语言·kotlin
androidwork13 小时前
Kotlin Android LeakCanary内存泄漏检测实战
android·开发语言·kotlin
笨鸭先游14 小时前
Android Studio的jks文件
android·ide·android studio
gys989514 小时前
android studio开发aar插件,并用uniapp开发APP使用这个aar
android·uni-app·android studio
H3091914 小时前
vue3+dhtmlx-gantt实现甘特图展示
android·javascript·甘特图
像风一样自由14 小时前
【001】renPy android端启动流程分析
android·gitee
千里马学框架16 小时前
重学安卓14/15自由窗口freeform企业实战bug-学员作业
android·framework·bug·systrace·安卓framework开发·安卓窗口系统·自由窗口
xianrenli381 天前
android特许权限调试
android