When I run below command directly on prompt, it works fine by pulling all files from emulator sdcard:
adb -s emulator-5556 pull /sdcard/.
However when I create bash file (extract.sh) with above command and run it I get following error:
remote object 'C:/Program Files (x86)/Git/sdcard/' does not exist
As can be seen it somehow adds C:/Program Files (x86)/Git before it. These are the contents of bash file:
#!/bin/bash
adb -s emulator-5556 pull /sdcard/.
Does anyone have an idea of why it works when direcly typing on prompt and not via bash file ? Thanks
Is there any reason you're not specifying the destination directory? For example, the batch command I use when pulling pictures from my phone over USB is adb pull "/sdcard/DCIM/Camera" "E:\Phone Pics\HTC DNA" which specifies both the source directory on the phone and the destination directory on my computer. As a side note, like enedil I recommend using this in a batch file when working in Windows.
Related
I want to download the content of /storage/emulated/0/android/data/com.xxxx.myapp as zip file to my Mac download folder.
I connect my Android phone with USB to my Mac
I open terminal
I run adb shell
I run cd /storage/emulated/0/android/data
Now, how to zip and download com.xxxx.myapp folder to my Mac download folder?
Or, how to copy com.xxxx.myapp folder to my Mac download folder?
When I run adb shell, the prompt becomes a50:/ $ in Terminal.
If I do cp com.xxxx.myapp /Users/my_user/Downloads I get
cp: Skipped dir '/Users/my_user/Downloads': No such file or directory'.
You can use adb pull.
(Running cp on the phone can't work because your Mac's folders won't exist on the phone. Plus, you forgot -R.)
How to zip: You can create a tarball and save it in /data/local/tmp or some other location you have write access to, by using a regular tar command on the phone:
tar -czf /data/local/tmp/archive.tgz com.xxxx.myapp
Then, exit the ADB shell and run an adb pull command on the host instead:
adb pull /data/local/tmp/archive.tgz ~/Downloads/
You can also just pull the whole folder without compressing it first:
adb pull /storage/emulated/0/android/data/com.xxxx.myapp ~/Downloads/
I have a simple bash script to push an executable to the android and then remove it.
#!/bin/bash
adb push CMakeBuild_Android_armv8/Out/Release/exec /data/local/tmp/exec
adb shell rm data/local/tmp/exec
This is saved as 'adb_push.sh'. I made sure that this is an executable via chmod.
chmod +x adb_push.sh
But when I run this script in the Cygwin ./adb_push.sh, I get an error that there is no such directory.
CMakeBuild_Android_armv8/Out/Release/exec: 1 file pushed, 0 skipped. 62.5 MB/s (7302616 bytes in 0.111s)
rm: data/local/tmp/exec: No such file or directory
Is there any obvious steps that I am missing in creating a bash script or is there any error in what I am doing?
Any hint or comment would be highly appreciated.
ADB version:
$ adb version
Android Debug Bridge version 1.0.41
Version 31.0.0-7110759
Installed as C:\platform-tools_r31.0.0-windows\platform-tools\adb.exe
Disclaimer: I already tried putting the source and destination path in quotes, it did not work for me. Also tried the same with a .wav file instead of an executable and I get the same error which lead me to believe that something's not right in the bash script.
Your second command assumes the working directory is the root /. It appears this assumption is false.
The first command is succeeding. Only the second command is failing.
If adb shell doesn't start at the root (/), then the destination path you supply in the first command (/data/local/tmp/exec) is different from the path you supply in the second command (data/local/tmp/exec, note the missing slash at the beginning).
I'm gonna guess adb shell on your device starts a shell in some user's home directory, not /.
Option 1: Use absolute file path
You can fix this by giving the full absolute file path in your second command:
adb shell rm /data/local/tmp/exec
Option 2: Change directories before your command
Alternatively, you can change to the root directory before running the command. adb shell (as of version 31.0.0-7110759) does not have the ability to set the working directory, but you can do this inside the shell by adding a cd before your rm. Note that the command must now be quoted to prevent your local shell from interpreting the list operator &&:
adb shell 'cd / && rm data/local/tmp/exec'
Note: The adb shell default working directory may vary by device or ROM. On my stock Pixel 3 it does in fact start at the root:
$ adb shell pwd
/
I have a flutter project that i created and manage with vscode.
I now need to access some files on my android emulator.
Everything i read online references the File Explorer tool in android studios.
However, i am not using android studios and i dont have a android studio project.
The only way i see at the moment is to abandon using vscode and recreate my project using android studios then using the file explorer from there...
However, this seems silly and excessive... i am sure there is someway i can access the file on my emulator without having to trow vscode in the trash.
Any ideas?
You can't access emulator's file system from VS Code as of now. If you don't want to use Android Studio then an alternative way is to use ADB Shell.
Here are the commands that you can use to interact with the File System of your emulator.
adb pull - To copy a file or directory and its sub-directories from the Android device
adb push - copy local files/directories to Android device
adb shell ls- List Files and Directories
adb shell cd - change directory
adb shell rm - rm is a command-line utility for removing files, directories and symbolic links
adb shell mkdir - make directories
adb shell touch- the touch command is a standard command used in UNIX/Linux operating system which is used to create, change and modify timestamps of a file
adb shell pwd - printing the current working directory
adb shell cp - copy files and directories
adb shell mv - moves files or directories from one place to another
For a detailed example please visit ADB Shell.
My working directory is /data/local/tmp.
I create and push a shell script file here named get_meminfo.sh.
The core function of it is record the RSS usage and save as a log file, like this: rss_res >> rss.log
But now I find a problem: I can run the script file when I enter the android shell, like ./get_meminfo.sh, and I can see the log file created in the path.
However when I try to run it from adb, like: adb shell /data/local/tmp/get_meminfo.sh, it will get an error: can't create file, read-only file system!
It seems that you do not quite understand the concept of the current working dirtectory.
The rss_res >> rss.log command creates rss.log in the current working dirtectory. Which in case of the following command sequence is /data/local/tmp:
adb shell
cd /data/local/tmp
./get_meminfo.sh
So rss.log gets created in /data/local/tmp which is world writable.
But in case of adb shell /data/local/tmp/get_meminfo.sh the cwd is the / root folder. Which is not writable and the command fails.
The easiest way to mitigate that is to use the absolute path for your log file inside of your script like this rss_res >> /data/local/tmp/rss.log
Trying to copy file from device to desktop, here is a command:
adb pull sdcard/log.txt Users/admin/Desktop
But this command creates a folder Users/admin/Desktop inside platform-tools folder where adb is located. How to pull file to my desktop ?
Use a fully-qualified path to the desktop (e.g., /home/mmurphy/Desktop).
Example: adb pull sdcard/log.txt /home/mmurphy/Desktop
Judging by the desktop folder location you are using Windows. The command in Windows would be:
adb pull /sdcard/log.txt %USERPROFILE%\Desktop\
Be root, Define file on device and define new filename.
adb root
adb pull /data/data/.../databases/launcher.db launcher.db
On Windows, start up Command Prompt (cmd.exe) or PowerShell (powershell.exe). To do this quickly, open a Run Command window by pressing Windows Key + R. In the Run Command window, type "cmd.exe" to launch Command Prompt; However, to start PowerShell instead, then type "powershell". If you are connecting your Android device to your computer using a USB cable, then you will need to check whether your device is communicating with adb by entering the command below:
# adb devices -l
Next, pull (copy) the file from your Android device over to Windows. This can be accomplished by entering the following command:
# adb pull /sdcard/log.txt %HOME%\Desktop\log.txt
Optionally, you may enter this command instead:
# adb pull /sdcard/log.txt C:\Users\admin\Desktop\log.txt
List item
Use following command to pull data from ADB
adb pull data/user/0/project package name/files/.local/share/dbname C:\Users\vijayalaxmi.k
data/user/0/project package name/files/.local/share/dbname this path you will get when you debug application. i.e database path
project package name example => com.example
instead of C:\Users\vijayalaxmi.k user your own path where you want to save your file. for example, c:\documents
do adb pull \sdcard\log.txt C:Users\admin\Desktop