简体   繁体   English

Android覆盖主机文件

[英]Android override the hosts file

Question

I want to call my secure website, which is using a self-signed certificate, and is running on my development machine, from my emulator that is running on the same machine 我想从运行在同一台计算机上的模拟器中调用一个使用自签名证书并且在我的开发计算机上运行的安全网站

context 语境

I create a self-signed certificate, and installed on my development machine, and edited the hosts file to link the localhost to my domail. 我创建了一个自签名证书,并将其安装在开发计算机上,并编辑了hosts文件以将localhost链接到我的domail。 So: https://mydomain:8080 works perfectly on my development machine. 所以: https:// mydomain:8080可以在我的开发机器上完美地工作。

I installed the same certificate on my emulator, so: https://10.0.2.2:8080 works but there emulator cannot verify the certificate because I am calling 10.0.2.2 while the certificate is issued for mydomain 我在模拟器上安装了相同的证书,因此: https ://10.0.2.2:8080可以运行,但是那里的模拟器无法验证证书,因为在为mydomain颁发证书时我正在调用10.0.2.2

The solutoin is to link the 10.0.2.2 to my mydomain on the hosts file 解决方法将10.0.2.2链接到主机文件上的mydomain

The problem is that I am not able to override (edit) the hosts file on the emulator, the error message states that the file is "read-only" 问题是我无法在模拟器上覆盖(编辑)主机文件,错误消息指出该文件为“只读”

My attempts 我的尝试

It is being a long time and I am trying, I almost tried everything thing I could found, but no success, to list some: 这是很长时间了,我正在尝试,我几乎尝试了所有可以发现的事情,但没有成功,列举了一些:

First 第一

adb shell su mount -o rw,remount /system chmod 777 /system adb shell su mount -o rw,重新安装/ system chmod 777 / system

The I get the same error message 我得到同样的错误信息

Second I run the emulator from adb command, with writable permission, but the same error happened 其次,我以可写权限从adb命令运行模拟器,但是发生了相同的错误

Third 第三

I tried to root the emulator so I can use apps, such as Hosts Editor, but after so many trial and errors, I am not able to root the emulator 我尝试将仿真器植根,以便可以使用主机编辑器之类的应用程序,但是经过多次尝试和错误后,我无法植根仿真器

Well, I tried many, I hope you guys can give me some insights 好吧,我尝试了很多,希望你们能给我一些见解

Update 更新资料

According to the aastefanov's answer , maybe the system/ folder is still not allowed to have write access on it 根据aastefanov的回答 ,也许仍然不允许system/文件夹对其进行写访问

I found a solution: 我找到了解决方案:

The solution is to modify the hosts file from the shell script, without overtiring it. 解决方案是从shell脚本中修改hosts文件,而不要覆盖它。

Move technical stuff 移动技术资料

  1. adb root 亚行根
  2. adb shell 亚行外壳
  3. su //to get the root access su //获取root权限
  4. whoami // just to be sure we are the root user now whoami //只是要确保我们现在是root用户

//now we are root but we cannot modify the hosts file because it is just on read-only state //现在我们是root用户,但是由于它处于只读状态,因此我们无法修改hosts文件

  1. mount -o rw,remount /system //to make it writable (you can be more specific and apply it to just system/etc folder) mount -o rw,remount / system //使其可写(您可以更具体地将其应用于system / etc文件夹)

  2. echo "10.0.2.2 williamromadomain" >> /system/etc/hosts 回声“ 10.0.2.2 williamromadomain” >> / system / etc / hosts

This is just a work around, because I have to do that every time I run the simulator 这只是解决方法,因为每次运行模拟器时都必须这样做

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM