Android Studio中Chrome模拟器localhost不安全证书设置无法持久化如何解决
持久启用Android Studio Chrome模拟器的"Allow invalid certificates for resources loaded from localhost"设置
方法1:通过adb命令启动Chrome并指定参数
- 启动Android模拟器后,打开终端执行以下命令:
- 连接到模拟器shell:
adb shell - 启动Chrome并启用不安全localhost证书:
am start -n com.android.chrome/com.google.android.apps.chrome.Main --args="--allow-insecure-localhost"
- 连接到模拟器shell:
- 每次用这个命令启动Chrome,该设置都会自动生效,无需手动在flags里修改。
方法2:修改Chrome偏好配置文件(需模拟器root)
- 先在AVD管理器中编辑目标模拟器,勾选Enable root access并重启模拟器。
- 打开终端执行:
- 进入模拟器root shell:
adb shell su - 编辑Chrome偏好文件:
vi /data/data/com.android.chrome/app_chrome/Default/Preferences - 在文件中找到
"allow_insecure_localhost"字段,将其值改为true - 保存退出后重启Chrome,设置即可持久化。
- 进入模拟器root shell:
- 注意:若模拟器重置或Chrome版本更新,该配置可能被覆盖,需重新修改。
方法3:在Android Studio Run配置中添加模拟器启动参数
- 打开Android Studio的Run/Debug Configurations
- 选择你的项目配置,切换到Emulator标签页
- 在Additional command line options输入框中添加:
-chrome-options "--allow-insecure-localhost" - 保存配置后,每次运行项目启动模拟器时,Chrome会自动加载该设置。
内容的提问来源于stack exchange,提问作者ragesh u
相关产品推荐
相关产品推荐

