如何使用最新构建版本更新/刷入Android模拟器
Android模拟器模块更新失败的问题分析与解决流程
核心错误原因
你当前的操作只完成了模块编译,但没有将新产物同步到模拟器使用的system镜像中,同时系统分区默认只读,导致旧文件无法被覆盖:
mma仅编译单个模块,但不会自动把新的二进制、.rc、.te文件合并到模拟器依赖的system.img里——这个镜像只有在全量构建或单独生成system镜像时才会更新。- 模拟器的
/system分区默认是只读挂载状态,你无法直接替换该目录下的旧文件,只能推送到可读写的/data,但这不是系统模块的默认加载路径,自然不会生效。
正确的构建与更新流程
1. 确认模块配置正确
先检查你的Android.bp(或Android.mk)是否正确声明了所有文件的安装规则,确保构建系统能把产物放到正确的system目录:
cc_binary { name: "hello", srcs: ["hello.cpp"], // 指定rc文件的安装路径(默认会放到/system/etc/init/) init_rc: ["hello.rc"], // 配置sepolicy规则 sepolicy: { name: "hello_sepolicy", srcs: ["hello.te"], }, // 如果需要指定二进制安装路径,可添加: // install_path: "/system/bin/", }
2. 编译模块并更新system镜像
- 在模块目录执行
mma编译最新产物:mma -j$(nproc) - 回到源码根目录,生成包含新产物的system镜像:
make systemimage -j$(nproc)
3. 启动模拟器加载更新后的镜像
关闭当前模拟器,然后指定使用刚生成的镜像启动:
# 替换<your-target>为你的模拟器目标(如aosp_x86_64) emulator -avd <你的AVD名称> -system out/target/product/<your-target>/system.img
如果是直接启动模拟器(无单独AVD),确保它默认加载的是out目录下的最新镜像,而非SDK预构建的镜像。
快速调试的临时方案(无需重新生成镜像)
如果只是想快速验证修改,可临时挂载系统分区为可读写:
- 获取root权限并重新挂载:
adb root adb remount
- 将编译好的产物推送到对应系统路径:
adb push out/target/product/<your-target>/system/bin/hello /system/bin/ adb push out/target/product/<your-target>/system/etc/init/hello.rc /system/etc/init/ adb push out/target/product/<your-target>/system/etc/sepolicy/private/hello.te /system/etc/sepolicy/private/
- 重启init服务让新配置生效:
adb shell stop && adb shell start
注意:该方案是临时的,重启模拟器后若使用旧镜像,修改会丢失。
常见排查点
- 检查
out/target/product/<your-target>/system/下是否存在你编译的新产物,确认构建系统已正确复制文件 - 执行
make systemimage时查看控制台输出,排查是否有sepolicy语法错误或文件复制失败的问题 - 确认启动模拟器时未指定旧的system镜像路径,避免加载预构建的旧版本
内容的提问来源于stack exchange,提问作者FotisK
相关产品推荐
相关产品推荐

