Unable to run 'adb root' on a rooted Android phone [duplicate] - android

This question already has answers here:
adb shell su works but adb root does not
(11 answers)
Closed 5 years ago.
After rooting my device, I need to run adb root and then adb shell so I could then access my applications database. When trying to run adb root I keep getting "adbd cannot run as root in production builds". Why is this? The only other option is to use the Android emulator for testing, but we all know how terrible the emulator is (not really a viable development solution).

I finally found out how to do this! Basically you need to run adb shell first and then while you're in the shell run su, which will switch the shell to run as root!
$: adb shell
$: su
The one problem I still have is that sqlite3 is not installed so the command is not recognized.

Related

Android Studio see device as null [duplicate]

This question already has answers here:
set up device for development (???????????? no permissions)
(30 answers)
Closed 4 years ago.
On Ubuntu Android Studio shows devices as null.
Every time I turn on my laptop, I need to run the following console commands to add permissions:
./adb devices
./adb kill-server
sudo ./adb devices
Enter my password and then repeat:
./adb kill-server
./adb devices
Note I'm using a xiaomi phone.
Is there a way to get around this permission issues so I don't have to do it ever time.
Anyway, what I did to solve this problem.
Defined in what cases I need to run these commands. For most ubuntu users there is a home folder (hidden file .bashrc).
In which you can record the launch of these commands. But these commands will be triggered when you enter the bash command in the console.
Since I have a shell .zshrc then I did the following:
open console: gedit .zshrc
When the file opens, add the following line:
./.add_device_permissions.sh
After or before, we need to create this file: .add_device_permissions.sh in which we write the following:
#!/bin/bash
# Add permissions for Xiaomi Redmi Note 5
ADB="/home/vadimm/Android/Sdk/platform-tools/adb"
$ADB devices
$ADB kill-server
cat .permissions_redmi_note | sudo -S $ADB devices
$ADB kill-server
cat .permissions_redmi_note | sudo -S $ADB devices
Also we need create .permissions_redmi_note where we need to hardcode our password.
Not to add to the file .zshrc unnecessary we can specify the path when starting the system itself: Startup Applications Preferences
Where we press on "Add" and write our command: /home/vadimm/.add_device_permissions.sh

How to make system partition in AVD in emulator writable

This is fairly a very old question but I am surprised that none of the solutions are working for me. I need to run an android app as system app in an AVD (in emulator) created for Android version 7.0. For this, I want to push apk file to system partition but I keep getting error saying it is read only file system. I found many similar questions on stackoverflow but nothing is working for me. I restarted adb in root, executed it with remount as suggested in answers to similar questions, but system partition file system permissions do not change. Here is a sample session:
mvsagar#mvslt:~/sw/android_sdk/platform-tools$ ./adb root
restarting adbd as root
mvsagar#mvslt:~/sw/android_sdk/platform-tools$ ./adb remount
remount succeeded
mvsagar#mvslt:~/sw/android_sdk/platform-tools$ ./adb push /home/mvsagar/projects/AndroidStudioProjects/LcnApps/app/LCNUE.apk /system/app/LCNUE.apk
adb: error: failed to copy '/home/mvsagar/projects/AndroidStudioProjects/LcnApps/app/LCNUE.apk' to '/system/app/LCNUE.apk': couldn't create file: Read-only file system
I have tried manually remounting with read/write(rw) options using adb shell, but the remounting fails.
Is there any way to have read/write permission on system partition?
My dev env is Android Studio on Ubuntu.
In my case, I use a avd( Based on: Android 8.0 (Oreo) Tag/ABI: google_apis/x86_64 ).
$ emulator -avd Nexus_5X_API_26_APIs -writable-system
$ adb root
$ adb remount
Then, /system is writeable.
$ adb push somefile /system/bin/ is work.
When working with Q, this is the only solution that worked for me: https://stackoverflow.com/a/64397712/1898527
Adding here the steps for completion (kudos to the original author):
> emulator -avd Pixel_3a_XL_API_29 -writable-system
> adb shell avbctl disable-verification
> adb disable-verity
Now reboot your emulator so that the changes take effect.
> adb root
> adb remount
> adb shell "su 0 mount -o rw,remount /system"
Note: you will need an emulator without Google Play, otherwise this won't work. You can get it by following the steps described here: https://stackoverflow.com/a/45668555/1898527
use genymotion emulator, which is faster, light weight and pre rooted. (which means you can access system directory)
For the benefit of others, answer to the question was answered a long ago by #Ishamael in another stackoverflow question Read only file system on Android

How to push sqlite databse to android app by usb cable? [duplicate]

This question already has answers here:
Ship an application with a database
(15 answers)
Closed 7 years ago.
I'm generating a sqlite database on my desktop system, this database (file with .db extention) should be pushed to my Android app by USB cable.
Is it possible?
If yes, how?
Short answer on your question is Yes and No.
Yes - if your device is coming with android version 4.3 and below and in every case if your device is rooted. (I will explain procedure below for non-rooted and android <=4.3);
No - if your device is not rooted and android version is 4.4 and higher.
Assuming that your device is not rooted and version of android is 4.3 and minor, you have to perform next actions:
Changing permissions on current db:
adb shell
$ run-as your.package.name
$ cd ./databases/
$ chmod 666 ./dbname.db
$ exit
$ exit
Backing up the original db:
adb pull /data/data/your.package.name/databases/dbname.db /your/path/to/file/on/computer
Replacing current with new database:
adb push /your/path/to/file/on/computer/dbname.db /data/data/your.package.name/databases/dbname.db
Restoring original permissions:
adb shell
$ run-as package.name
$ chmod 660 ./databases/dbname.db #Restore original permissions
$ exit
$ exit
Also, note that you have to adapt paths and file names for your current situation.
If you have rooted phone, then you have to change permissions over su user. If you need that procedure, I can post it, also.
Try this: Using DDMS(Dalvik Debug Monitor Server )

adb shell command from batch file [duplicate]

This question already has an answer here:
windows batch script not execute next line after "adb shell"
(1 answer)
Closed 5 years ago.
I have a .bat file that runs script for testing an app and printing the log to file i have all the commands i tested them manually.
Problem:
after entering the command adb shell, the shell opens in the command prompt. I wrote the next commands that are entered in the shell with root#generic
the commands aren't going through and it just waits at that spot.
what do i have to type in front of the commands to make them appear
example of what i have
cd directory of sdk
adb
adb shell
am instrumentation ... (this is the command that won't go through once the shell is open.
any help appreciated I've tried a few things with no success
Just use the following line in your batch file:
adb shell am instrumentation
that will connect to the shell on the Android device and run the am command.

Using the adb root command [duplicate]

This question already has answers here:
adb shell su works but adb root does not
(11 answers)
Closed 4 years ago.
The 'adb root' command's description says that it restarts the adbd with root permissions.
I tried it on my phone (Note 2 Android 4.3), which is not rooted, and it didn't work. I searched online, and I found that even on rooted devices, it can give error messages as "adbd cannot run as root in production builds".
My question is under what conditions will 'adb root' successfully restart adbd with root permissions ?
Thanks.
adb root needs a development (aka debug) build with ro.debuggable=1

Categories

Resources