Why adb push gives device not found error? - android

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

Related

Which Android Emulator image do contain 'su'?

How to know which Emulator image will contain su?
I can see that often it only contains su or google play
Run adb root and you get a root shell ... otherwise su needs to be manually installed.
However, when already having a root shell available, installing it isn't much of a problem.
All images are rooted, but SDK apps requesting escalation of privileges do rely upon su.
This question here generally duplicates: How to get root access on Android emulator?
adb shell scripting must:
start the emulator
run adb root
run adb shell
remount system partition
adb push the su binary
chmod to set permissions
exit
Or to answer the question:
start the emulator
and check if the file exists, eg. with adb shell stat /usr/bin/su
Where stat gives this response, when it's not installed:
stat: '/usr/bin/su': No such file or directory
One could even loop all Android images installed in $ANDROID_SDK_HOME...
there's no "one click" solution, but adb can be fully automated with Bash or Batch. And one wouldn't even have to run the emulator, but can mount QCOW2 as a nbd network block device.

Phone is rooted but can't pull files from /data/data folder

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.

How to change readable permission to writable permission in android emulator

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.

Why am I getting Permission Denied when trying to push a Sqlite file to my rooted Android device?

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

Run a native C program on unrooted Android device

I've managed to build a native executable for Android, after reading How do I build a native (command line) executable to run on Android?, but I can't execute it on my unrooted phone, it gives
/system/bin/sh: /storage/sdcard0/Download/hello_world: can't execute: Permission denied
because the SD card is mounted with noexec, and I can't write anywhere else.
I found a solution that works for me - it seems that /data/local/tmp is writable, and it isn't on a noexec partition.
The solution requires using adb. I connected the phone through USB, and I enabled USB debugging from developer options.
Then I uploaded the file to the phone using:
adb push C:\Workspace\hello_world\libs\armeabi\hello_world /data/local/tmp/hello_wo
rld
Then I ran adb shell:
adb shell
And from it I changed the write permission, and ran it:
chmod 755 /data/local/tmp/hello_world
/data/local/tmp/hello_world

Categories

Resources