Android Emulator hosts 변경 방법
Android/Tips 2015. 11. 17. 10:00 |Testing sites on mobile devices is a necessity. When you find a bug that needs some loving and you want to do the code tweaks on your localhost, the Android emulator balks. It doesn’t know anything about your localhost. Luckily, you can resolve this by editing the emulator’s /system/etc/hosts/
file. Here’s what to do:
First, start your emulator setting a partition size so the emulator doesn’t throw an out of memory error:
1 | $ emulator -avd nameOfAvd -partition-size 512 |
Next – in another shell window/tab – check what devices are running (so you can edit the one you want):
1 2 3 4 | $ adb devices List of devices attached emulator-5554 device |
The emulator-5554 is the device I started with the emulator
command. Right now it is in read-only mode. Remount the device to make it writable
1 2 3 | $ adb -s emulator-5554 remount remount succeeded |
Now that it is remounted, grab the hosts
file and put it somewhere on your filesystem (I use the Desktop):
1 2 3 | $ adb -s emulator-5554 pull /system/etc/hosts ~ /Desktop/ 6 KB /s (25 bytes in 0.003s) |
Edit the ~/Desktop/hosts
file as needed with the editor of your choice:
1 2 | 127.0.0.1 localhost 192.168.1.100 bacon.local |
Finally, push that hosts
file onto your emulator:
1 2 3 | $ adb -s emulator-5554 push ~ /Desktop/hosts /system/etc/hosts 45 KB /s (249 bytes in 0.005s) |
BAM! The emulator can now access sites using the hosts specified in the newly edited hosts file.
'Android > Tips' 카테고리의 다른 글
[dex2jar]추출한 APK 파일에서 classes.dex 파일 디컴파일(decompile)하기 (0) | 2016.07.26 |
---|---|
[Android] Enum Type을 피하라? (0) | 2015.11.25 |
Android Proguard 설정법 (0) | 2015.06.02 |
Google I/O 2015에서 언급된 새로운 OS (Android M)에 대한 내용 요약 (0) | 2015.06.01 |
[android] rooting 없이 db 내용 보기. (open source library) (0) | 2015.04.03 |