how to wipe cache android from adb terminal? - android

I'm using an android system builded with yocto and I do often the updates of the apps with adb from linux, but after a certain quantity of updates the partition /dev/block/mmcblk2p3 remain full, and I can't continue to do others updates.
How can I wipe the cache or clean it. using adb commands?

you can try adb shell su -c "rm -rf /data/data/<app's package>/cache/*"
if your application is compiled with a debug key, you can also use run-as command in adb's shell. So it would look like this: adb shell run-as <app's package> rm -rf /data/data/<app's package>/cache/* This method does not require root.
or below requires root
rm -r /data/dalvik-cache
rm -r /cache/dalvik-cache

adb shell run-as <app's package> rm -rf /data/data/<app's package>/cache/*

I resolved the my problem.
before sending the update files you need to kill the app process.
killall my_app_name_process
then
push files like this
adb push "my_app_name_process" /my_path/my_app_name_process
adb shell pm clear com.my_app.vow

Related

How to push a file from computer to /data/.../databases/ using adb command?

Below command is to pull a file:
adb -d shell "run-as com.myapp cat /data/data/com.myapp/databases/file.db" > file.db
But how to push it back like Android Studio does via Device File Explorer?
There is no simple command for uploading the file. What Android Studio does when uploading a file using Device File Explorer is this:
Upload the file via adb push to /data/local/tmp/<random file name>
Execute adb shell run-as com.myapp sh -c 'cp /data/local/tmp/<random file name> /data/data/com.myapp/<path>/<final file-name>'
Delete the temp file via adb shell rm /data/local/tmp/<random file name>
Get the updated view for Device File Explorer using adb shell run-as com.myapp sh -c 'ls -al /data/data/com.myapp/<path>/'
I discovered this by capturing the adb traffic on TCP port 5027 using Wireshark. An interesting detail is that each command executed using adb shell command uses the form <command-to-be executed in adb shell> || echo ERR-ERR-ERR-ERR
From Robert's answer now I can do like this:
function dbpull() {
adb shell run-as "com.$1.debug" cat "/data/data/com.$1.debug/databases/$2.db" > "/Users/username/Desktop/$2.db"
}
function dbpush() {
adb push "/Users/username/Desktop/$1.db" "/sdcard/db/tmp/"
}
function dbpush2() {
adb shell run-as "com.$1.debug" cp "/sdcard/db/tmp/$2.db" "/data/data/com.$1.debug/databases/$2.db"
}
function dbcheck() {
adb shell run-as "com.$1.debug" ls -al "/data/data/com.$1.debug/databases/"
}
Just write above code lines in your .bash_profile and then call it in terminal.
dbpull myapp mydata
At this moment I prefer to use Visual Studio Code than Android Studio to develop my Android apps. So, I need to know more about commands in terminal, e.g. adb, gradle, etc.
I hope this would be useful for everyone.
Use this command
adb push <file_path> <android_device_path>
adb pull <android_device_path>

How to write adb commands into a bat

I have my laptop connected to an android phone.
I am doing a task many times, so I wish to write a .bat file to run the commands automatically.
adb shell
cd /sdcard/speech
rm -f *
The bat file only executed adb shell, the rest codes were not executed.
I guess because the it entered the android device so the commands did not run as usual.
One solution was adb shell rm -f -r /sdcard/speech/*
What if there are more and more complicated commands?
Is there a way to do it ?
You can do your job with adb shell "cd /sdcard/speech; rm -f *".
For more complicated jobs, you can put all the commands in a Linux shell script, use adb push command to push the script to your Android device, and run the script using adb shell.
For example, put all the commands in run.sh, then issue:
adb push run.sh /data/local/tmp
adb shell "chmod +x /data/local/tmp/run.sh"
After this you can run your jobs with:
adb shell "/data/local/tmp/run.sh"
You can include the above line in a .bat file.

ADB Root Shell, "rm -r /storage/sdcard/some/path", Permission Denied

I've got a rooted phone running, have done adb root; adb connect <phone>; adb shell; and I am unable to rm, chmod, chown or in any way rid myself of some files under /storage/sdcard1/path/this_is_to_be_deleted/some_files.foo.
I am also unable to remove them via the file manager or terminal on the phone, even with superuser granted. WTF?
How on earth does root not have rights to rm anything and everything? On all the *nix systems I've used root can rm -rf /*, dd if=/dev/zero of=/dev/sda or any other virtually suicidal thing it wants.
Ok, for some ungodly reason, it was necessary to cd /mnt/media_rw/sdcard1; chown -R media_rw:media_rw *; cd /storage/sdcard1/path; rm -r this_is_to_be_deleted;
Explanations would be welcome!
Doing adb shell is not going to give you root, which is what HappyCactus is trying to say. You have to do:
> adb root
# _
If you see a hash mark, you are root.
If that doesn't work, try this:
> adb shell
$ su
# _
If that still doesn't give you a #, something is going on or your device isn't actually rooted.

How to get adb remount to work?

I'm attempting to remove certain files from the SD image mounted on the emulator.
NDUNN-PC ~
$ adb devices
List of devices attached
emulator-5554 device
NDUNN-PC ~
$ adb shell rm -f /sdcard/maps/*
rm failed for -f, Read-only file system
NDUNN-PC ~
$ adb remount
remount succeeded
NDUNN-PC ~
$ adb shell rm -f /sdcard/maps/*
rm failed for -f, Read-only file system
From all the docs I've read, remount is supposed to toggle between read-write/read-only permissions. But that doesn't seem to work in this case. Any idea what's wrong? Using Windows XP, emulator is running Android SDK 1.6 (with Google Maps APIs).
Removing the -f command from rm made it work. Weird.

Android ADB access to application databases without root

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.

Categories

Resources