【android】エミュレータのhostsを書き換える
Android Debug Bridge (adb) を使用して ローカルにあるhostsファイルをエミュレータ上に配信させて書き換えます。
まず、エミュレータをroot権限で操作できるように設定します。
$ adb root
remountします。
$ adb remount
127.0.0.1のまま差し替えちゃうとエミュレータ自身を見に行ってしまうので、自PCのプライベートIPに差し替えます。
(192.xxxの部分は適宜書き換えてください)
$ cat /etc/hosts | gsed 's/127.0.0.1/192.168.1.9/' > /tmp/hosts-adb
エミュレータ上にhostsを配信します。
$ adb push /tmp/hosts-adb /system/etc/hosts