So I'm just trying to modify the hosts file on a family members phone. I've put the phone in debug mode and pulled the hosts file, edited it, but when I try to push it I get the message, "adb: error: failed to copy 'D:/hosts\hosts' to '/system/etc/hosts/hosts': remote couldn't create file: Not a directory"
Here's the commands I've used:
adb pull /system/etc/hosts D:\hosts
/system/etc/hosts: 1 file pulled. 0.0 MB/s (56 bytes in 0.003s)
adb push D:\hosts /system/etc/
adb: error: failed to copy 'D:\hosts\hosts' to '/system/etc/hosts/hosts': remote couldn't create file: Not a directory
This is my first time using android debugging/adb and nothing else I've read helped. Thanks in advance.
EDIT: So I've made a little progress. I realized that the hosts file is not in a hosts directory, so I changed it to adb push D:\hosts /system/etc which still didn't work, but adb push D:\hosts\hosts /system/etc gave me the response adb: error: failed to copy 'D:\hosts\hosts' to '/system/etc/hosts': remote couldn't create file: Read-only file system So it looks like my problem is now in adb shell chmod
EDIT2: So after some more research I came across this Read only file system on Android. When trying mount -o rw,remount /system I get mount: '/dev/block/dm-0' not user mountable in fstab. In the mounts file /dev/block/dm-0 is on /system. The new problem is fstab is not located in /etc
EDIT3: It looks like my big problem is I have to root the phone I think. I don't have su or sudo to do the remount. Seeing as it's not mine, I don't want to root the phone.
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.
When running the code,
Installation error:INSTALL_FAILED_CONTAINER_ERROR Occurred
Please check logcat output for more details.
Launch canceled!
I just try to solve these Error by changing the
android:installLocation="preferExternal" into
android:installLocation="auto"
But still now Error remains the same.So that apk couldn't be installed in Emulator.
AndroidMainfest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.gems.android"
android:versionCode="1"
android:versionName="1.0"
android:installLocation="auto"
>
Storage:
LogCat:
E/memtrack(1386): Couldn't load memtrack module (No such file or directory)
E/android.os.Debug(1386): failed to load memtrack module: -2
D/AndroidRuntime(1386) : Calling main entry com.android.commands.pm.Pm
W/ActivityManager(381) : No content provider found for permission revoke: file:///data/local/tmp/GEMS.apk
E/Vold(47) : Error creating imagefile (Read-only file system)
E/Vold(47) : ASEC image file creation failed (Read-only file system)
W/Vold(47) : Returning OperationFailed - no handler for errno 30
E/PackageHelper(640) : Failed to create secure container smdl2tmp1
E/DefContainer(640) : Failed to create container smdl2tmp1
W/ActivityManager(381) : No content provider found for permission revoke: file:///data/local/tmp/GEMS.apk
Available Memory in SD Card is also 483 MB.
If anybody know how to solve these reply me.Thank you.
This is because of
ASEC image file creation failed (Read-only file system)
Mounting, remounting, chmod for SDcard won't help either - at least it didn't for me
C:\Users\<User Name>\AppData\Local\Android\sdk\platform-tools>adb shell
root#generic:/ # mount -o remount rw /storage/sdcard
mount -o remount rw /storage/sdcard
root#generic:/ # mount -o remount rw /mnt/sdcard
mount -o remount rw /mnt/sdcard
root#generic:/ # chmod -R 777 /mnt/secure/asec
chmod -R 777 /mnt/secure/asec
Unable to chmod /mnt/secure/asec: Read-only file system
Still got Unable to chmod /mnt/secure/asec: Read-only file system
Adb reset, as per some accepted answers here on Stack Overflow, was perhaps a part of solution, but it didn't help too. As neither helped deleting SDCARD/.android_secure/smdl2tmp1.asec via Windows explorer after mounting sdcard.img file(file that is used as an image for SD card on emulator and can be located in C:\Users\.android\avd\.avd ) with ImDisk program(please make sure you have on theright tab "Image file access" -> "Virtual disk drive accesses image file directly" radio checked).
What instantly helped was from Android Settings app on emulator: "Storage"->"Erase SD card". If you selected Intel Atom as emulator CPU in AVD settings, you may have to change it to ARM at least temporarily to erase the SD via emulator, since reportedly - SD formatting fails on emulated Intel Atom CPU quite often.
Hope that helps!
Although this works most of the time, even a new emulator and/or sdcard setup sometimes shows this failure right away for me.
One thing that always works for me (and makes for a considerably faster development-test cycle compared to killing images and emus, then rebooting the emu) is to explicitly install the package on the internal device flash - apparently the installation failures only occur in conjunction with the sdcard image - at least for me.
Using the pm tool, you can explicitly install either on the sdcard or the flash, so I adb push my package to the device's sdcard, then open an adb shell to use pm for explicit installation:
adb -e push myapk.apk /mnt/sdcard/temp.apk
adb -e shell
pm install -f /mnt/sdcard/test.apk
If you used -s instead of -f you would instruct pm to explicitly install to the sdcard.
BTW - as a related side note:
I also observed that, if the sdcard works in the emulator, using adb uninstall followed by adb install has a higher chance of success than using reinstall via adb install -r. This proved true in several tests, but I haven't invested enough time to say this with 100% confidence. This might also be chance.
Deleting my emulator and recreating one seemed to solve this problem for me.
How to push a file from computer to an Android device having no SD Card in it. I tried:
C:\anand>adb push anand.jpg /data/local
3399 KB/s (111387 bytes in 0.032s)
C:\anand>adb push anand.jpg /data/opt
3199 KB/s (111387 bytes in 0.034s)
C:\anand>adb push anand.jpg /data/tmp
3884 KB/s (111387 bytes in 0.028s)
Above commands to move a file anand.jpg to a device but I didn't get this jpg file in the device.
I didn't get any success result on cmd prompt, I only got:
3399 KB/s (111387 bytes in 0.032s).
From Ubuntu/Mac Terminal, the below command should work.
./adb push '/home/hardik.trivedi/Downloads/one.jpg' '/data/local/'
For adb v33 and above if you are getting a permission denied error, try what I tried. The following command and it works fine.
The only caveat is you might need to use tmp directory on such an emulator.
adb shell //Entering into shell
su //Super user mode
chmod 777 /data/local/tmp/ //Grantint RWX access
exit
chmod 777 /data/local/tmp/ //Grantint RWX access
exit
And then try
./adb push '/home/hardik.trivedi/Downloads/one.jpg' '/data/local/tmp/'
I did it using the push command, which has syntax:
adb push filename.extension /sdcard/0/
Example of copying directory, and sub-directory content:
adb push C:\my-location\data\. /storage/emulated/0/Android/data
Note that push did just hang in latest platform-tools (33.0.1, at time of writing) for a certain amount of files, beside the adb.exe suddenly taking 5MB+ instead of 1.5MB, hence I just did replace the adb.exe with one I had from 28.0.0 version of platform-tools (I did not downgrade the entire platform-tools, because adb.exe is kind of stand-alone).
I don't say there is any conspiracy around data folder,
But my Samsung device puts limits on my USB file transfer, beside Android v11+ not allowing access to data folder anymore, hence I needed above command to work with 100% speed (without hanging one hour for little more files).
Follow these steps :
go to Android Sdk then 'platform-tools' path on your Terminal or Console
(on mac, default path is : /Users/USERNAME/Library/Android/sdk/platform-tools)
To check the SDCards(External and Internal) installed on your device fire these commands :
1) ./adb shell (hit return/enter)
2) cd -(hit return/enter)
now you will see the list of Directories and files from your android device
there you may find /sdcard as well as /storage
3) cd /storage (hit return/enter)
4) ls (hit return/enter)
you may see sdcard0 (generally sdcard0 is internal storage) and sdcard1 (if External SDCard is present)
5) exit (hit return/enter)
to come out of adb shell
6) ./adb push '/Users/SML/Documents/filename.zip'
/storage/sdcard0/path_to_store/ (hit return/enter)
to copy file
Sometimes you need the extension,
adb push file.zip /sdcard/file.zip
run below command firstly
adb root
adb remount
Then execute what you input previously
C:\anand>adb push anand.jpg /data/local
C:\anand>adb push anand.jpg /data/opt
C:\anand>adb push anand.jpg /data/tmp
After Trying all the answers this worked for me
Where I am Pushing a file on Desktop to Android Device (Redmi K20 pro) connected Over the air using adb.
This command pushes the file to the downloads folder on my phone
adb push ~/Desktop/notifications.drawio ./storage/emulated/0/Download
after running this if you get a permission denied error
try running these commands in order (which basically changes the directory permission)
adb shell
chmod 777 /data/local/tmp
exit
and then run try the adb push command
I have documented this here feel free to share your views and help improve it.
Try this to push in Internal storage.
adb push my-file.apk ./storage/emulated/0/
Works in One plus device, without SD card.
My solution (example with a random mp4 video file):
Set a file to device:
adb push /home/myuser/myVideoFile.mp4 /storage/emulated/legacy/
Get a file from device:
adb pull /storage/emulated/legacy/myVideoFile.mp4
For retrieve the path in the code:
String myFilePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/myVideoFile.mp4";
This is all. This solution doesn't give permission problems and it works fine.
Last point: I wanted to change the video metadata information. If you want to write into your device you should change the permission in the AndroidManifest.xml. Add this line:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
I've got a Nexus 4, that is without external storage. However Android thinks to have one because it mount a separated partition called "storage", mounted in "/storage/emulated/legacy", so try pushing there: adb push anand.jpg /storage/emulated/legacy
As there are different paths for different versions. Here is a generic solution:
Find the path...
Enter adb shell in command line.
Then ls and Enter.
Now you'll see the files and directories of Android device. Now with combination of ls and cd dirName find the path to the Internal or External storage.
In the root directory, the directories names will be like mnt, sdcard, emulator0, etc
Example: adb push file.txt mnt/sdcard/myDir/Projects/
This might be the best answer you'll may read.
Setup Android Studio
Then just go to view & Open Device Explorer.
Right-click on the folder & just upload a file.
In Mac: To push files via adb
adb push /Users/Downloadsâ©/amazon.sdktester.json '/mnt/sdcard/amazon.sdktester.json'
You are trying to write to system folders. With ADB you have root (admin) access so you see the system folders of which sdcard is one of them so to send a picture you could use
D:\Program Files\Android\sdk\platform-tools\adb push am files\android sdk\adb.exe push C:\Downloads\anand.jpg /sdcard/pictures/
NB: C:\Downloads\anand.jpg replace with path and name to picture..
Certain versions of android do not fire proper tasks for updating the state of file system.
You could trigger an explicit intent for updating the status of the file system.
(I just tested after being in the same OP's situation)
adb shell am broadcast -a android.intent.action.MEDIA_MOUNTED -d file:///
(You could pass a specific filepath instead of file:/// like file:///sdcard )
In my case, I had an already removed SDCard still registered in Android.
So I longpressed the entry for my old SDCard under:
Settings | Storage & USB
and selected "Forget".
Afterwards a normal
adb push myfile.zip /sdcard/
worked fine.
To push all the files at your directory to the Android device use:
PS D:\myFiles> adb push . '/data/local/tmp/'
I want to write log from my android device to the file under Windows XP.
I'm trying to use command:
adb logcat -f test
But it returns:
log file locked.couldn't open output file: Bad file number
If I use
adb logcat >test
then it works OK, but it doesn't show anything to the console.
I thought that using "-f" option would show data in console and simultaneously write to the file.
How to do it?
Just sharing in case someone fall here.
The -f options expects a path from phone folder (and not from your PC). For example:
adb logcat -f /sdcard/test.txt
Then, after stopping the log, you must pull that file from phone:
adb pull /sdcard/test.txt