Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to edit /etc/hosts file in Android Studio emulator running in nougat?

Anyone know how to edit /etc/hosts file inside an android studio emulator running in nougat? I will be editing it so I can use my virtual host in my local web server. I tried editing it through terminal using adb however, it is returning Read-only file system. Tried also using chmod but still it fails.

Update: I also tried pulling and pushing files using adb $ ./adb -s emulator-5554 push ~/Desktop/hosts /system/etc/hosts

adb: error: failed to copy '/Users/Christian/Desktop/hosts' to '/system/etc/hosts': couldn't create file: Read-only file system

like image 963
Christian Callelero Avatar asked Dec 13 '16 09:12

Christian Callelero


People also ask

How do I edit etc hosts on Android?

Navigate to the /system/etc directory. Locate the hosts file in this directory and long-press it to open the "Properties" menu. Select the "Change" option in the permissions section.

How do I edit a etc file in Linux?

Right-click on the Notepad icon and select Run as administrator. In Notepad, click File then Open. In the File name field, paste c:\Windows\System32\drivers\etc\hosts . Save the changes by clicking File > Save .


1 Answers

1) android-sdk-macosx/tools/emulator -avd <avdname> -writable-system 2) ./adb root 3) ./adb remount 4) ./adb push <local>/hosts /etc/hosts 

Android file host can be

/etc/hosts <--- This worked for me /etc/system/hosts /system/etc/hosts 

Check

1) ./adb shell 2) cat /etc/hosts 3) ping customsite.com 
like image 101
P.O.W. Avatar answered Oct 19 '22 13:10

P.O.W.