I'm trying to edit the hosts file on an android emulator with API 30 - Android R. I have completed remount successfully but it says
Remount succeeded. Reboot device for changes to be effective
I am stuck on this step because no matter what way I reboot the emulator, it goes to
Device offline
and shows just a black screen.
It gets restored only if I do a factory reset, but again the emulator file system becomes read-only and I cannot edit the hosts file.
The solutions I tried are as follows:
First step is common.
In adb command prompt:
cd [...\Android\android-sdk\emulator directory]
emulator -avd [EMULATORNAME] -writable-system
Then in system command prompt,
cd [...\Android\android-sdk\platform-tools directory]
Method 1:
adb root
adb remount
Here remount succeeds but I need to reboot the device.
All these ways of rebooting result in Device Offline state and black screen:
adb reboot
Manually restarting emulator by long pressing power button
In adb command prompt, pressing Ctrl + C to stop the emulator and starting again with:
emulator -avd [EMULATORNAME] -writable-system
If I ignore the reboot and try to edit the hosts file pushing a new like this:
adb push hosts /system/etc
Then I get
Error, cannot write to a read-only file system.
Method 2:
adb shell
su
mount -o remount,rw /sys
This gives no error or success message. Then if I try any write operation such as:
adb push hosts /system/etc
or
cat hosts
10.1.3.5 bla.blabla.com >> hosts
Then it still says
Error, cannot write to a read-only file system.
I have already tried these links and solutions with no success:
How to edit /etc/hosts file in Android Studio emulator running in nougat?
I can't edit android emulator's host file
Android emulator-5554 offline
android emulator sdk 10 api 29 won't start after remount and reboot
Please help. Thanks in advance!
This is fairly a very old question but I am surprised that none of the solutions are working for me. I need to run an android app as system app in an AVD (in emulator) created for Android version 7.0. For this, I want to push apk file to system partition but I keep getting error saying it is read only file system. I found many similar questions on stackoverflow but nothing is working for me. I restarted adb in root, executed it with remount as suggested in answers to similar questions, but system partition file system permissions do not change. Here is a sample session:
mvsagar#mvslt:~/sw/android_sdk/platform-tools$ ./adb root
restarting adbd as root
mvsagar#mvslt:~/sw/android_sdk/platform-tools$ ./adb remount
remount succeeded
mvsagar#mvslt:~/sw/android_sdk/platform-tools$ ./adb push /home/mvsagar/projects/AndroidStudioProjects/LcnApps/app/LCNUE.apk /system/app/LCNUE.apk
adb: error: failed to copy '/home/mvsagar/projects/AndroidStudioProjects/LcnApps/app/LCNUE.apk' to '/system/app/LCNUE.apk': couldn't create file: Read-only file system
I have tried manually remounting with read/write(rw) options using adb shell, but the remounting fails.
Is there any way to have read/write permission on system partition?
My dev env is Android Studio on Ubuntu.
In my case, I use a avd( Based on: Android 8.0 (Oreo) Tag/ABI: google_apis/x86_64 ).
$ emulator -avd Nexus_5X_API_26_APIs -writable-system
$ adb root
$ adb remount
Then, /system is writeable.
$ adb push somefile /system/bin/ is work.
When working with Q, this is the only solution that worked for me: https://stackoverflow.com/a/64397712/1898527
Adding here the steps for completion (kudos to the original author):
> emulator -avd Pixel_3a_XL_API_29 -writable-system
> adb shell avbctl disable-verification
> adb disable-verity
Now reboot your emulator so that the changes take effect.
> adb root
> adb remount
> adb shell "su 0 mount -o rw,remount /system"
Note: you will need an emulator without Google Play, otherwise this won't work. You can get it by following the steps described here: https://stackoverflow.com/a/45668555/1898527
use genymotion emulator, which is faster, light weight and pre rooted. (which means you can access system directory)
For the benefit of others, answer to the question was answered a long ago by #Ishamael in another stackoverflow question Read only file system on Android
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
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
Step by Step
Don’t Create the AVD with a Google Play image.
Use for example Google APIs Intel x86 Atom System Image.
Start the emulator with the following command…
emulator.exe –avd <avd name> -writable-system
For example:
C:\Users\ilyas.mamun\AppData\Local\Android\Sdk\emulator>emulator.exe -avd Pixel_API_25 -writable-system
emulator: WARNING: System image is writable
HAX is working and emulator runs in fast virt mode.
audio: Failed to create voice `goldfish_audio_in'
qemu-system-i386.exe: warning: opening audio input failed
audio: Failed to create voice `adc'
Root and Remount the AVD like the followings…
C:\Users\ilyas.mamun\AppData\Local\Android\Sdk\platform-tools>adb root
C:\Users\ilyas.mamun\AppData\Local\Android\Sdk\platform-tools>adb remount
remount succeeded
C:\Users\ilyas.mamun\AppData\Local\Android\Sdk\platform-tools>adb shell
eneric_x86:/ # cd system
generic_x86:/system # cd etc
generic_x86:/system/etc # cat hosts
127.0.0.1 localhost
::1 ip6-localhost
generic_x86:/system/etc # echo "192.168.1.120 ilyasmamun.blogspot.com" >> hosts
generic_x86:/system/etc # cat hosts
127.0.0.1 localhost
::1 ip6-localhost
192.168.1.120 ilyasmamun.blogspot.com
generic_x86:/system/etc #
Here is how i was able to do it working on OSX. After reading a bunch of different instruction nothing seemd to work for me untill someone mentioned that you have a very narrow window for copying the file from your disk to the emulated device or it becomes read-only again
Start your emulator.
In your terminal find the folder "platform-tools" for your devices
Prepare the hosts file you want to copy to your device (in my case i put it on desktop)
String together a bunch of commands to copy the file quickly. This is what worked for me ./adb root && ./adb -s emulator-5554 remount && ./adb -s emulator-5554 push ~/Desktop/hosts /system/etc/hosts 'emulator-5554' is the name of my device which you can find by typing ./adb devices
after that the terminal responded with
restarting adbd as root
remount succeeded
[100%] /system/etc/hosts
you can veryfy the copy was successfull by ./adb shell and then cat /system/etc/hosts
I was then able to connect to my virtual hosts from the emulated device
Just to be complete here is how my hosts file looked like
10.0.2.2 my-virtual-host
I hope this helps someone as i spet quite some time trying to figure this out.
Below are the steps I followed on my Windows machine on Windows Terminal:
Run the following command to know your AVDs:
emulator -list-avds
Run the following command to open the emulator for writable mode:
emulator -avd Pixel_XL_API_29 -writable-system -no-snapshot-load
Replace Pixel_XL_API_29 with your AVD name.
Ignore the warnings there.
In a new Terminal tab run the following commands:
adb root
adb shell avbctl disable-verification
adb reboot
Wait for your emulator to reboot. It can take upto 1 minute.
When the emulator is rebooted, run the following commands:
adb root
adb remount
You will get a remount succeeded message after that:
Now is the time to push our host file from Windows machine to Android's emulator
adb push D:\hosts /system/etc/
D:\hosts is the location of the hosts file present at the D drive of my Windows machine.
/system/etc/ is the location in Android's emulator where we want to copy that file.
After successfull operation you will see a message like this:
To verify that the hosts file has been pushed you can run the following commands:
adb shell
cd system
cd etc
cat hosts
You will see the contents of hosts file in the Terminal:
I was able to edit the /etc/hosts file by launching the emulator with -writable-system and remounting the emulator using adb remount. After that the hosts file inside the emulator is editable. I tried pushing/replacing the file and succeeded.
Another approach to this matter would be to use the adb command line tool.
Make sure you have in path emulator and tools
export ANDROID_HOME="/Users/YOUR_USERNAME/Library/Android/sdk"
export PATH=$ANDROID_HOME/emulator:$ANDROID_HOME/tools:$PATH
EDIT: For Windows should something like this (instead of tools required platform-tools [or the path where adb resides])
C:\Users\YOUR_USERNAME\AppData\Local\Android\sdk\platform-tools
C:\Users\YOUR_USERNAME\AppData\Local\Android\sdk\emulator
Check device name (ideally it would be to have a short name without spaces, eg. API30X86)
emulator -list-avds
Then launch the emulator with the following arguments:
emulator -avd YOUR_AVD_NAME -writable-system -no-snapshot-load -no-cache
Run the following commands to run as root and remount the partition system as root
adb devices #you should see your devices
adb root
adb shell avbctl disable-verification
adb reboot
adb root
adb remount
After remount, you should be able to push the edited host file from your machine to the emulator.
adb push ~/Documents/hostsandroid /etc/hosts
Now you should be able to see your hosts file with Device File Explorer from Android Studio.
EDIT: In the case, you don’t see the Device File Explorer, you can check the Event Log if Android framework is detected. If so, click Configure and you're done.
When you are going to run again and push new changes with a new session, you’ll only have to do:
adb root
adb remount
adb push ~/Documents/hostsandroid /etc/hosts
Follow the below 3 steps :
Start emulator in writable mode : ./emulator -avd <emulator_name> -writable-system
remount : adb remount
push the hosts file attached : adb push hosts /system/etc/
Note :
Run one and only one emulator_name with above steps
executable emulator is located within android-sdk. For me it was under sdk/emulator.
Attached hosts file will resolve www.facebook.com to 127.0.0.1, hence blocks www.facebook.com on emulator.
First find your system hosts file and copy it to desktop
Then create a virtual device Nexus 5 with system image Nougat x86_64 Android 7.1.1 (non Google API version) once it is created
Then goto /Android/sdk/emulator in terminal then run the below code please add your own device name below as mine was Nexus_S_API_25 =>
./emulator -writable-system -netdelay none -netspeed full -avd Nexus_S_API_25
After that Open a new terminal and goto this location
/Android/sdk/platform-tools
then run
./adb root
./adb remount
./adb push ~/Desktop/hosts /system/etc/hosts - (It will copy your Desktop/hosts file and paste it into your emulator hosts file which is /system/etc/hosts)
That's it your emulator hosts file is updated Now if you want to re-check then run the below code
./adb shell
cat /system/etc/hosts (it will show you the emulator hosts file)
Restart the emulator to see the changes
./adb reboot
Tedious, but effective, you can build a new hosts file, line by line within your emulator shell.
Remount Emulator
You can edit/remount your emulator (to get a writeable filesystem) in your PC/Mac/linux command line / powershell / terminal.
(Stop your emulator if it's already running, then...):
emulator -avd <avdname> -writable-system
(this starts up a new emulator with a writable file system)
Still within your PC/Mac/Linux terminal run these two commands:
adb root
adb remount
Then connect to your running emulator via a shell:
adb shell
This part below is run from inside your emulator, inside the shell connection you just made.
Give yourself root access:
su
Change directory to where the hosts file is kept:
cd /etc
To make your emulator defer to your development machine's hosts file or DNS for a given domain, add a domain entry using ip of 10.0.2.2.
Example of appending a new domain entry line to emulator hosts file:
echo '10.0.2.2 mydev.domain.com' >> hosts
This 10.0.2.2 is a special address for Android emulators. It will proxy DNS requests for that domain to your development machine. So whatever IP address your PC/Mac/Linux machine hosts file lists for mydev.domain.com, the Android emulator will use it.
You can now exit the root shell & your emulator shell:
exit
exit
(1st gets you out of su. 2nd exits from the emulator shell, dropping you back into your development machine's terminal).
You're done. You can open up a web browser inside your emulator, type the domain you just added to hosts into the address bar and check the emulator is routing that domain properly.
Remount failed
If you're on Android emulator 29+ and getting
remount failed
when calling adb remount, check out the workaround by Kidd Tang here.
You can use the ADB Shell to edit the file by changing the access (Read Only to RW)
Try #P.O.W answer,
Make sure you have a blank line after the last entry of the hosts file
If you use tabs in the hosts file, replace them with spaces
Restart Android and try again:
adb reboot
place all these export in z shell using terminal
vim ~/.zshrc press enter
then zshell will open
then press i
past all the export (verify the path i have used all default location for instalation)
then press esc
then press this :wq!
press enter
close terminal and open it again
export PATH="$PATH:$HOME/Dev/flutter/bin"
export GEM_HOME=$HOME/.gem
export PATH=$GEM_HOME/bin:$PATH
export ANDROID_HOME=$HOME/Library/Android/sdk
export ANDROID_SDK_ROOT=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools
only use google apis image do not usese play image
u will get list of avds
emulator -list-avds
emulator -avd Nexus_5_API_29 -writable-system (do not close terminal) (open a new terminal)
adb root
adb remount
copy mac host file to Downloads from /private/etc/hosts
adb push Downloads/hosts /system/etc/hosts
adb reboot
Running Android Studio on a Macbook for the first time and I'm getting this error. The program does not start on my device, I just get a crash message.
On Android Studio, I get "The target device does not support the 'run-as' command" and when I plug this into google I get no results. I get a "Learn More" section though which points to this link under the heading "About Instant Run": https://developer.android.com/studio/run/index.html?utm_medium=android-studio#instant-run.
Any suggestions would be highly appreciated.
I recently upgraded to AS 2.2 and this message suddenly appeared today.
Restarting Studio caused this message to disappear.
But the build in general seemed slow - so I used the adb commands to stop and start the server and now it seems Instant run is working better
adb kill-server
adb start-server
my phone is Moto G x1032 w lollipop
I had this same problem after rooting my device and the other answer didn't solve it.
When I ran adb run-as command in the terminal I kept getting
Could not set Capabilities: operation not permitted.
It's a permissions issue. You have to change permissions on run-as file in /system/bin folder. This solved it for me (needs root access):
1. remount /system rw
2. chmod 4750 /system/bin/run-as
3. remount /system ro
If running custom recovery:
1. reboot to recovery
2. find the mount system and check it (make sure 'mount system as read-only' is unchecked)
3. open a terminal and type: adb shell
4. type: chmod 4750 /system/bin/run-as
5. uncheck the System mount and reboot!
See here issue 58373: https://code.google.com/p/android/issues/detail?id=58373
I try to push updated hosts file into the android device which I create with Android Studio.
I follow these steps:
~/Library/Android/sdk/platform-tools/adb devices
~/Library/Android/sdk/platform-tools/adb -s emulator-5554 remount
~/Library/Android/sdk/platform-tools/adb -s emulator-5554 pull /system/etc/hosts ~/Desktop/
~/Library/Android/sdk/platform-tools/adb -s emulator-5554 push ~/Desktop/hosts /system/etc/hosts
After the last command, I get this error:
"adb: error: failed to copy '~/Desktop/hosts' to '/system/etc/hosts': Read-only file system"
About 2 months ago, I tried the same steps and I didn't get any errors. It worked correctly.
What more should I do?
Creating new virtual devices everytime is not the most practical option. As of March 2018, you can follow these steps and you should be able to modify the android hosts file:
Open terminal then:
android list avd
Now copy the Name of the AVD you want to use. For example, my AVD's name is Nexus_4_API_19.
emulator -avd Nexus_4_API_19 -writable-system
Open a new terminal window and:
adb remount
adb pull /system/etc/hosts /Users/{username}/Documents/
Edit the hosts file adding an entry pointing to your host computer. Example:
192.168.0.31 mywebsite.com
Then
adb push /Users/{username}/Documents/hosts /system/etc
The issue has been solved.
I removed the virtual device and set up a new one.