I am working in emulator to connect in localhost. For some reason, I need to change the locahost network connectivity. I received the localhost file from System and moved to say for eg: C:/temp/host location. In the host file, I edited and again I tried to move to System/etc/hosts but it fails to move the file. It display the error as couldnt create file: Read-only file system. Please suggest me solution.
Below are the Steps followed:
C:\Users\Android\sdk\platform-tools> adb pull /system/etc/hosts C:/temp/hosts
[100%] /system/etc/hosts
The file has been successfully moved to temp folder.
After I edited the file, I tried to push. But it fails.
C:\Users\Android\sdk\platform-tools>adb remount
Not running as root. Try adb root first
C:\Users\Android\sdk\platform-tools> adb root
C:\Users\Android\sdk\platform-tools> adb push C:\temp\hosts\system\etc
adb error: failed to copy 'C:\temp\hosts' to '/system/etc/hosts': couldn't create file Read only file system.
You must do "adb remount" after "adb root", after you can do the push.
adb root
adb disable-verity
adb reboot
adb root
adb remount
and the run the
adb push .....
you may see error like this because of all the reboot and roots
error: no devices/emulators found
just run this command
adb devices
you will see something like this
List of devices attached
0123456789ABCDEF device
and then try it again.
Related
I'm trying to modify the hosts file on my android phone and I am using adb for this on Ubuntu 20.04 to pull the file, modify it and push it back as suggested here. I was able to pull the file but when I try to push it I get an error
adb: error: failed to copy 'Documents/hosts' to '/system/etc/hosts': remote couldn't create file: Read-only file system
One suggestion seems to be to run adb remount or adb shell mount -o rw,remount /system (I'm not sure if these meant to be run on the android device itself) and this doesn't work for me, I get
/system/bin/sh: /system/bin/remount: inaccessible or not found
To this, there seems to be a suggestion to run adb root which returns adbd cannot run as root in production builds. Now I'm not sure how to proceed. There are some threads online saying what to do about this but I feel this is way above my head already. I just want to push the hosts file back to the phone. Is there a simple way to do this?
My phone Samsung Galaxy S5 mini is rooted. I'm trying to pull files from /data/data/myapp.package/ to folder on my PC.
adb pull /data/data/myapp.package E:\myapp\myapp.package
it gives me this error
adb: error: failed to copy '/data/data/myapp.package' to 'E:\myapp\myapp.package': Permission denied
I found many questions like mine but no answer solved my problem. Some suggested to execute this command adb root before pulling files. Some suggested to install adbd insecure app to enable root access. In fact after installing that app, phone disappeared from adb terminal. Both solution didn't work for me.
BTW, I can copy files using cp command from adb shell but I have to copy files to sdcard and then pull from sdcard. I'm looking for solution which allows me to copy files directly from /data/data/myapp.package to my PC
Any solution?
For your adb to be able to access /data/data directly (for adb pull), your adbd should be running as root - which can generally be done by adb root command.
adb root would not work on commercial devices like Samsung Galaxy S5 mini as commercial devices have ro.secure=1, i.e., the adbd can't be restarted as root due to a check of property called ro.secure. adbd insecure app circumvents this and restarts adbd in root mode to enable adb pull, etc. to work.
In short, if adbd insecure app doesn't work for you, it's not possible to do adb pull from /data/data in your existing ROM. It might be possible if you change the ROM / do some boot.img tweaks, but I would probably suggest trying latest version / different versions of adbd insecure app before going for ROM changes.
Read more on rooting here.
First you need to hit these two command from command line
adb root
adb remount
then
adb pull /data/data/myapp.package E:\myapp\myapp.package
This is my example pulling DB file from the root directory
adb -e shell "run-as com.example.project cp /data/data/com.example.project/databases/project.db /sdcard"
The key is run-as
Here's a one-liner that lets you pull a file without installing anything else and without having to copy it to a public location on the device to then pull it to your computer:
adb exec-out su -c cat /data/data/myapp.package/my_file.apk > my_file.apk
What this does:
adb exec-out runs a command and outputs the raw binary output
su -c runs the provided command as root
cat <file> prints out the file contents
> <file> redirects the output from adb (i.e. the raw file contents) to a local file.
I try to edit android emulator's host file.I follow steps:
step1
adb root
step2
adb remount
step3
adb pull /system/etc/hosts .
then I add new line for customer host information,then I push hosts file,I get some errors:
step4
adb push hosts /system/etc/hosts
error information:
adb: error: failed to copy 'hosts' to '/system/etc/hosts': couldn't create file: Read-only file system
envirements information:
osx ei capitan
android emulator: android 7.1.1
android studio: 2.2.2
I just ran into the same problem and made it work.
Run the emulator:
emulator -avd <EMULATORNAME> -partition-size 512 -writable-system
I believe that -writable-system param is the thing that fixed it for me.
In another terminal/cmd prompt:
adb root
adb -s emulator-5554 remount
adb -s emulator-5554 pull /system/etc/hosts hosts
Now, work your magic (add the IP to host file)
adb -s emulator-5554 push hosts /system/etc/hosts
Additional info:
emulator-5554 is the device name, you can find yours with adb devices
emulator program is located inside android-sdk/tools
adb program is located in android-sdk/platform-tools
Important update from comments:
Please check the comment from steven to this post about running adb reboot before running adb root.
This might be important to being able to start the emulator from AVD manager.
Captain suggests to run adb reboot after pushing the host file to avoid blackscreen error.
Happy debugging :)
After pushing the hosts file run adb reboot and you will have no problem with the black screens anymore.
I had problems with the other solutions, so i tested a lot and now i decided to write another answer and i hope it is useful for others.
Here are my steps to success (Android Studio on win 10):
Start Android Studio and open the AVD Manager and start your
Emulator.
Open a powershell and navigate to your android sdk/platform-tools/
.\adb.exe reboot -writable-system (your emulator should reboot now)
.\adb.exe root
.\adb.exe remount
.\adb.exe pull /system/etc/hosts C:\Temp\hosts
Èdit your hosts file
.\adb.exe push C:\Temp\hosts /system/etc/hosts
.\adb.exe unroot
Now you can open a browser in your emulator and open your custom domain to check if your hosts file has been changed.
Click the close-icon of your emulator to force a shutdown with snapshot saving. You should see a "Saving state..." message.
Now start your emulator again from AVD Manager. Your hosts file should persist. So check your domain again.
I had very strange issues with unstartable emulators after booting in writable-system mode, rooting and stopping emulator without doing the unroot. The problem is: whenever the snapshot fails the emulator will do a cold boot and your hosts file is gone. You need to repeat all the steps in that case.
So I have a local Sqlite file I am trying to push to my Rooted Android (Nexus 7 2013) device. Which I have confirmed is Rooted by tying adb shell, su and seeing the # displayed instead of $
I am trying to run the following command:
adb push D:\tfs\MyApp\MyDatabase.db3 /data/data/MyApp/files/MyDatabase.db3
But I keep getting
Failed to copy ...MyApp.. to ...MyApp...: Permission denied
I have searched the internet and found answers here and here and have come up with the following:
adb shell su -c "mount -o rw,remount /data"
adb shell su -c "chmod 777 /data"
But even after running these two above commands and running my Push Command I am still getting Permission Denied.
What am I doing wrong?
'adb push' cannot push to data/data/ directory.
However, you can do it by using a transfer station like this:
adb push D:\tfs\MyApp\MyDatabase.db3 ~/sdcard/MyDatabase.db3
adb shell
su
mv /sdcard/MyDatabase.db3 /data/data/MyApp/files/MyDatabase.db3
It works for me,good luck to you.
To push an APK file Eg:"MyApp" to /data/local/tmp/ from my local C:/Apps
adb push C:/Apps/MyApp /data/local/tmp/ is giving Permission Denied error
Steps to make this work (issue these commands in an order)
adb shell
su
chmod 777 /data/local/tmp/
exit
chmod 777 /data/local/tmp/
exit
Now if i give adb push, it worked
adb push C:/Apps/MyApp /data/local/tmp/
Simple solution:
Instead of:
.\adb.exe push c:/files-to-push.zip /mnt/sdcard/Download
I used:
.\adb.exe push c:/files-to-push.zip /sdcard/Download
The problem I had
After going to adb folder(in my case c:/adb)
I connected with:
.\adb.exe connect 127.0.0.1:58526
And then I tried to push this zip file c:/Games/pokemon.zip by running:
.\adb.exe push c:/Games/pokemon.zip /mnt/sdcard/Download
I got this error:
adb: error: stat failed when trying to push to /mnt/sdcard/Download: Permission denied
Explaining my solution:
I was trying to push files to a path that does not exist...
In my case I tried to push to /mnt/sdcard/Download
Then after running adb shell I got access to console
Finally just typed ls to check which folder I had there
In my case I saw there was no /mnt
So after that I tried to ls /sdcard and saw Download folder there...
Ok so heres my solution.
My phone was already Rooted but for some reason this isnt enough to do anything you want.
I had to go and download the apk onto my device named adbd insecure mentioned here which you can download on that thread or from the google play store. I then had to open the App on my device and click "Enable Insecure adbd" and I also clicked "Enable at boot"
After this running my normal command:
adb push D:\tfs\MyApp\MyDatabase.db3 /data/data/MyApp/files/MyDatabase.db3
worked
Run the commands below:
adb root
or
adb wait-for-device root && adb remount
I want to push some apk file to sd card, then to /system folder. I tried the following commands in order:
adb shell
su
mount -o rw,remount /system
adb push /data/app/com.project.android.xxx-2.apk /sdcard
But the last line always results in device not found error. I have even tried with system folder directly as, adb push /data/app/com.project.android.xxx-2.apk /system/app, but it gave me the same error. I have also tried to execute this line before push command:
chmod 644 /sdcard
But that didn't solve the push command problem.
My device is rooted.
Device driver is updated.
My device has sd card.
USB debugging mode is enabled.
When I write adb devices I get my device name.
What is causing this error, and how can I solve it?
You're executing adb push being already shell-ed into the device. By doing that you start another adb server on the target device now (not on your host machine), which is scanning ports in some range looking for devices attached. Since no device is found (attached to the target device) you get error: device not found. For the kind of task you're trying to achieve no need to use any of adb commands within shell.
Try either mv or cp command once you shell-ed in. For example (remounting part skipped):
adb shell
cp /data/app/com.project.android.xxx-2.apk /sdcard