I have debbugable app, and I need to copy file to phone, and back after. I use this command and receive error.
adb shell run-as app cp /data/data/app/shared_prefs/app_preferences.xml /storage/emulated/0
cp: /storage/emulated/0/app_preferences.xml: Operation not permitted
I tryied to edit file
adb shell run-as app "echo test > /data/user/0/app/shared_prefs/app_preferences.xml"
/system/bin/sh: can't create /data/data/app/shared_prefs/app_preferences.xml: Permission denied
But if I try
adb shell
run-as app
echo test > /data/user/0/app/shared_prefs/app_preferences.xml
This way I able to edit file, but cp not. Also via Android Studio I can save and upload file.
In total, how to edit in one command or copy file?
Related
While using android debug bridge remount, it changes the system folder to r/w, but
as soon as the user tries to copy some file using android debug bridge to the system folder it changes to read-only
If the device is not rooted, you cannot copy anything to the System or Data partitions.
With root do the following commands in a command prompt or linux shell and all should be fine:
adb push fileName /data/local/tmp
adb shell
su
mount -o remount, rw /system
cp /data/local/tmp/fileName /system/folderOfYourChoise
chmod 644 (if its an apk and you want the system to use it as a system app)
exit (exits the su shell)
exit (exits the adb shell)
adb reboot (to apply and see changes on the 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
How do install a *.apk from adb command line?
First I tried to cp the *.apk from /sdcard/backups/apps to /system/app (after rw mounting the file system of course)
I did successfully move it to /system/app but the *apk was not "installed"
I used this code :-
**
adb shell
su
mount -o rw,remount /system
adb shell
su
cd /sdcard
mv com.ogp.gpstoggler-1.apk /system/priv-app
finally after I write
chown 644 /system/priv-app/com.ogp.gpstoggler-1.apk
and press enter the result is
Unable to open /system/priv-app/com.ogp.gpstoggler-1.apk: No such file or direc
tory***
how to fix this ? thank you ?
Instead of using "mv" use "cp" to copy it to system/priv-app folder.
Ensure it is in the priv-app folder using "ls"
use chmod 777 to give it privileges
Ensure it has the correct privileges using "ls -l"
use "adb reboot" to have the system install the application.
Edit
One thing I forgot to note - if you go into the system/priv-app folder and you see that all the other APK's are in their own folders, you might also have to create a folder for your apk.
mkdir system/priv-app/app_name
cp app_name.apk system/priv-app/app_name
cd system/priv-app/app_name
chmod 777 system/priv-app/app_name/app_name.apk
adb reboot
I am unable to pull a the database from the device even after changing the permission. I have a rooted phone.
It used to work. I could pull before. For some unknown reason now I cannot.
The error I receive is
remote object '/data/data/com.thuptencho.transitbus/databases/ttc.db' does not exist
Does anybody know why this is happening?
Below is what I did in command window.
C:\users\thupten>adb shell
shell#android:/ $ su
su
root#android:/ # cd /data/data/com.thuptencho.transitbus/databases/
cd /data/data/com.thuptencho.transitbus/databases/
root#android:/data/data/com.thuptencho.transitbus/databases # ls
ls
ttc.db
ttc.db-journal
webview.db
webview.db-journal
webviewCookiesChromium.db
webviewCookiesChromiumPrivate.db
root#android:/data/data/com.thuptencho.transitbus/databases # chmod 755 ttc.db
5 ttc.db <
root#android:/data/data/com.thuptencho.transitbus/databases # chmod 777 ttc.db
7 ttc.db <
root#android:/data/data/com.thuptencho.transitbus/databases # exit
exit
shell#android:/ $ exit
exit
C:\users\thupten>adb pull /data/data/com.thuptencho.transitbus/databases/ttc.db
remote object '/data/data/com.thuptencho.transitbus/databases/ttc.db' does not exist
I using these commands to get data from /data/data folders, no changing permission required
adb kill-server
adb root
I figured it out.
I had to chmod the databases folder as well and then the file.
The problem is that you need permission not just to the file, but also to its parent directories.
(That permission should not be 777 though!)
Rather than trying to change the permission, what you probably want to do is get adb running as root if that is supported, (ie, if you have an engineering build, rather than an aftermarket "rooting" of a secured device) or else use your root access (or the app itself, or the stock run-as command if you have a debug apk) to copy the file of interest somewhere accessible and then adb pull the copy.
My preferred solution was:
Install Chainfire's adbd insecure app
From within the adbd insecure app, select "Enable Insecure adbd"
adb pull /data/data/com.package.name/databases/database.db
Caution - adb insecure means adb is running as root on your device.
for i in `adb shell ls /data/ -1`;do adb pull /data/$i data; done
Can anyone tell me, is it possible to use the ADB to pull and push a database from an app, without root privileges on the phone?
For example, I know the location on my rooted magic and dream is:
/data/data/com.xxxx.xxxx/databases/xxxx
I know that you can use ADB without root, but when trying to use the shell - you can't view that location without root privaliges. But I have been told you can use push and pull if you know the file you want?
Basically I want to pull a database from MY app on a non rooted phone modify it and push it back on.
Only trouble I have is, the two phones I have are both root and I don't have access to a non root one to try it out.
While Nilhcem's answer didn't work for me, it lead me in the right direction (for that I upvoted) and I now have a working solution.
Old answer that may not work with newer versions of Android:
#Transfer file from app databases directory to PC
adb shell
$ run-as package.name
$ cd ./databases/
$ ls -l #Find the current permissions - r=4, w=2, x=1
$ chmod 666 ./dbname.db
$ exit
$ exit
adb pull /data/data/package.name/databases/dbname.db ~/Desktop/
#Transfer file from PC to app databases directory (requires the above permission change)
adb push ~/Desktop/dbname.db /data/data/package.name/databases/dbname.db
adb shell
$ run-as package.name
$ chmod 660 ./databases/dbname.db #Restore original permissions
$ exit
$ exit
Alternate method using external storage (confirmed to work with 6.0.1):
#Transfer file from app databases directory to external storage
adb shell
$ run-as package.name
$ cp ./databases/dbname.db /sdcard/
$ exit
$ exit
#Transfer file from external storage to app databases directory
adb shell
$ run-as package.name
$ cp /sdcard/dbname.db ./databases/
$ exit
$ exit
A quick workaround is to use the run-as command to copy the database in a folder where you can have access, such as /sdcard and then, do a normal adb pull
adb shell
$ run-as package.name cp /data/data/package.name/dbname.db /sdcard/
$ exit
adb pull /sdcard/dbname.db
More information on the run-as command here
Note that the run-as command is available since API level 8 (Android 2.2) and can only be used if the application is debbugable.
On OxygenOS (based on Android 5.2) I've combined the two solutions provided by Pilot_51.
First, I used run-as to gain access to /data/data/package.name/databases, but from here I wasn't able to copy directly to /sdcard/ so I changed the permissions of the file. After that, I exited from run-as mode and used cp to copy the file in /sdcard/ storage. Finally, I was able to use adb pull
$ adb -s <DEVICE_ID> shell
$ run-as package.name
$ chmod 666 databases/dbname.db
$ exit
$ cp /data/data/package.name/databases/dbname.db /sdcard/dbname.db
$ exit
$ adb pull /sdcard/dbname.db ./dbname.db
We set the file permissions to readable for all users from within the app.
if (BuildConfig.DEBUG)
{
new File(mDB.getPath()).setReadable(true, false);
}
Then just pull the .db off with adb normally.
adb -d pull //data/data/xxxxx/databases/xxxxx.db .
NOTE: I've discovered that this needs to be done each time the database file is opened, for example in onCreate as well as the constructor of your SQLiteOpenHelper wrapper (when your database is not null) or perhaps onOpen. If only in onCreate, then the next time you run your app and the .db already exists, for some reason the permissions have been changed back. This might have something to do with how Android manages its data.
if you want to push db file into the application
first of all, place "file.db" under "/storage/emulated/0/" because of permission issue. then you should pretend as application to access data folder.
adb shell
$ run-as com.package.name
:/data/data/com.package.name $ cp /storage/emulated/0/file.db /data/data/com.package.name/databases/
it copies the file.db that in main folder to databases.