背景
需要在AVD中把charles的ca证书内置到目录/system/etc/security/cacerts/下
遇到错误
- adb: error: failed to copy … to …: remote couldn’t create file: Read-only file system
- mount: ‘/system’ not in /proc/mounts
- [liblp]bool android::fs_mgr::WritePrimaryMetadata(int, const android::fs_mgr::LpMetadata &, uint32_t, const std::string &, const std::function<bool (int, const std::string &)> &) write 740 bytes failed: I/O error
- qemu-system-x86_64 virtio zero sized buffer
- 等等错误
网上的回答都无法解决问题
参考:https://www.repeato.app/resolving-adb-remount-failures-system-not-in-proc-mounts/
https://stackoverflow.com/questions/61570717/bootloop-if-writable-system-is-used
https://stackoverflow.com/questions/42647209/how-to-make-system-partition-in-avd-in-emulator-writable
https://stackoverflow.com/questions/64695086/how-do-i-make-system-writeable-in-android-studio-emulator
解决方案
最终搜索到一个大佬的回答,换个思路海阔天空
# 先把charles证书下载到本地 charles-ssl-proxying-certificate.pem
# 查看证书的哈希值
openssl x509 -inform PEM -subject_hash_old -in charles-ssl-proxying-certificate.pem | grep -B 1 BEGIN
# 第一行显示的97b095f6就是证书哈希值, 给证书改名为 : 哈希值.0
mv charles-ssl-proxying-certificate.pem 97b095f6.0
# 因为./emulator -avd Pixel_4_API_30 -writable-system 会出现很多bug 难以解决,所以换个思路,覆盖文件夹
adb shell mkdir /data/local/tmp/cacerts/
adb shell cp /system/etc/security/cacerts/* /data/local/tmp/cacerts/
adb push 97b095f6.0 /data/local/tmp/cacerts/
adb root
adb shell mount -t tmpfs tmpfs /system/etc/security/cacerts
adb shell mv /data/local/tmp/cacerts/* /system/etc/security/cacerts/
adb shell chcon u:object_r:system_file:s0 /system/etc/security/cacerts/*
参考:https://android.stackexchange.com/questions/242222/cold-boot-snapshot-failed-to-load