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

查看启动日志:

相关推荐
小草帽学编程30 分钟前
鸿蒙Next开发真机调试签名申请流程
android·华为·harmonyos
dog shit2 小时前
web第十次课后作业--Mybatis的增删改查
android·前端·mybatis
科技道人4 小时前
Android15 launcher3
android·launcher3·android15·hotseat
CYRUS_STUDIO8 小时前
FART 脱壳某大厂 App + CodeItem 修复 dex + 反编译还原源码
android·安全·逆向
Shujie_L10 小时前
【Android基础回顾】四:ServiceManager
android
Think Spatial 空间思维11 小时前
【实施指南】Android客户端HTTPS双向认证实施指南
android·网络协议·https·ssl
louisgeek12 小时前
Git 使用 SSH 连接
android
二流小码农12 小时前
鸿蒙开发:实现一个标题栏吸顶
android·ios·harmonyos
八月林城13 小时前
echarts在uniapp中使用安卓真机运行时无法显示的问题
android·uni-app·echarts
雨白13 小时前
搞懂 Fragment 的生命周期
android