Enabling USB debugging mode on Reh Hat Linux - android

I am currently using RHEL 5 and need to connect my Nexus 4 to my PC with USB debugging enabled (done) so that I can run my android projects directly on the phone rather than the emulator which is very slow and painfully time consuming. I have updated my Android SDK manager and noticed that I did not find any Google USB drivers as those available in Windows. Some more Googling and I came across some steps to be followed to accomplish this in Ubuntu:
1. sudo lsusb
2. get the two hex values sepearetd by a ':'(This is the manufacturerID:deviceID you need to tell the system to handle)
3. Then as root, do the following:
sudo su -
cd /etc/udev/rules.d
vi 51-android.rules
In this file, add a line that enables you to handle your device. Problem is: I do not have this file in my rules.d folder. So what is the procedure for making my device recognizable in any other linux distro (in my case RHEL 5).
Also, when I do this :
adb devices
output:
List of devices attached
???????????? no permissions
Please Help. Thanks in Advance :)

You can change the permissions of adb executable to be able to access usb.
Try first, if adb works properly, when using it with root permission:
sudo ./adb kill-server
sudo ./adb start-server
sudo ./adb devices
If you do not have 'sudo' installed on your system, just do the operations above with the root user. If it works, you can use the following workaround to make it work permanently:
chown root:user_group adb
chmod 4550 adb
After this it should work.

You'll have to create the file from scratch and insert the line, otherwise it won't work.
Follow the instructions that you have found and you are safe.
The adb devices will show your device properly if you follow the steps.

I've run into this problem too, when using RHEL/CentOS 6.6, where no plugdev group is present.
I run adb with unprivileged user account myuser.
My solution was to create the /etc/udev/rules.d/50-android.rules file with the rules:
# udev rules for USB android devices
# samsung: 04e8
SUBSYSTEM=="usb", ATTR{idVendor}=="04e8", MODE="0666", GROUP="myuser"
# LG: 1004
SUBSYSTEM=="usb", ATTR{idVendor}=="1004", MODE="0666", GROUP="myuser"
After which I did (as root):
udevadm control --reload-rules ; udevadm trigger
and then, as myuser:
adb kill-server
adb devices -l
The explanation: the GROUP= option in the udev rules file specifies the group which will own the device when plugged in. In Debian-based distributions there is a plugdev group which fulfills this purpose, but some newer RHEL-based distros don't have it. This creates a permissions problem when adb is run with a regular (non-root) user, since it won't have access to the devices.
The solution is to assign the USB devices to a group which exists, and to which your linux user belongs. In my case I chose to assign the device to my user's "personal" group, to which it has the proper permissions.
Another solution (untested, but should work the same) would be to create the plugdev group and add your user to it.

Related

Android devices don't show up in "adb devices" until logged into Ubuntu GUI session

We have thousands of devices that we test on hundreds of Ubuntu hosts and one of the big problems we're running into is that unless you log into the host via the GUI, some of the devices don't show up. I was speaking with a coworker and he was saying this was due to the device being unable to mount until an active GNOME session was started, but he didn't know how to fix it - does anyone know a way around this? This is a huge problem for us because if we need to reboot a host (or many hosts), we need to remote into each one, log in, and then the devices show up - logging in via Putty doesn't have any effect - it's only if you log into the GUI that the devices show up.
Our systems are running Ubuntu 16.04.
sudo adb kill-server
sudo adb devices
Has been tried, and does not help.
Thanks!
Create this file as root if it's not created already:
touch /etc/udev/rules.d/51-android.rules
Use this format to add each vendor id from your devices to the file:
SUBSYSTEM=="usb", ATTR{idVendor}=="12d1", MODE="0666", GROUP="plugdev"
In this example, the vendor ID is for my HUAWEI device. The MODE assignment specifies read/write permissions so when you have created/updated the file, execute.
Make the file executable:
chmod +x /etc/udev/rules.d/51-android.rules
Now try restart adb again.
adb kill-server; adb start-server; adb devices -l
If you do not know your vendor ID i have created a list for the most known brands for you, otherwise the vendor ID can be found by lsusb command if you got this package installed, the bolded text is your Vendor ID if the phone is listed.
List devices Vendor ID via lsusb:
lsusb
Bus 002 Device 019: ID 12d1 :107e Huawei Technologies Co., Ltd.
List Vendor ID's for different phone models via curl:
curl -L https://nr1.nu/xm89
SUBSYSTEM=="usb", ATTR{idVendor}=="0502", MODE="0666", GROUP="plugdev" #Acer
SUBSYSTEM=="usb", ATTR{idVendor}=="0b05", MODE="0666", GROUP="plugdev" #ASUS
I assume you know that the phone is connected properly already but if you are not sure about this type dmesg -w followed by connecting the device to your pc again, you should see a message that a new device has been found if everything is okey.
Try this
adb kill-server
adb devices
adb server will be restarted hence there is a change to detect the connected devices

adb shell su works but adb root does not

I rooted my unlocked Galaxy S3 (SGH-T999)
Now, I'm trying to run adb root from Windows Command Prompt, however, I'm getting adbd cannot run as root in production builds error. So, the very first thing I checked was whether my phone was really rooted?
So I tried the following:
Open Command prompt
$adb devices // lists my device
$adb shell //goes to shell
$su // opens a 'SuperSu' prompt on my phone and I 'Grant' permission
# // Before following the rooting instructions, I was getting 'no su command found' in the previous step. So, I believe my phone is ROOTED. **Correct me if I'm wrong.**
However, when I do adb root, I get adbd cannot run as root in production builds error.
So, I thought, I might have to do some additional stuff beyond what I did above. I tried all the solutions in the following SO questions:
Launch a script as root through ADB
adb remount permission denied, but able to access super user in shell -- android
Unable to run 'adb root' on a rooted Android phone
None of the above worked for me. All they do is give the ROOT access INSIDE of SHELL. I want adb root to work so that I can execute various adb commands WITHOUT going into shell.
By design adb root command works in development builds only (i.e. eng and userdebug which have ro.debuggable=1 by default). So to enable the adb root command on your otherwise rooted device just add the ro.debuggable=1 line to one of the following files:
/system/build.prop
/system/default.prop
/data/local.prop
If you want adb shell to start as root by default - then add ro.secure=0 as well.
Alternatively you could use modified adbd binary (which does not check for ro.debuggable)
From https://android.googlesource.com/platform/system/core/+/master/adb/daemon/main.cpp
#if defined(ALLOW_ADBD_ROOT)
// The properties that affect `adb root` and `adb unroot` are ro.secure and
// ro.debuggable. In this context the names don't make the expected behavior
// particularly obvious.
//
// ro.debuggable:
// Allowed to become root, but not necessarily the default. Set to 1 on
// eng and userdebug builds.
//
// ro.secure:
// Drop privileges by default. Set to 1 on userdebug and user builds.
In some developer-friendly ROMs you could just enable Root Access in Settings > Developer option > Root access. After that adb root becomes available. Unfortunately it does not work for most stock ROMs on the market.
I ran into this issue when trying to root the emulator, I found out it was because I was running the Nexus 5x emulator which had Google Play on it. Created a different emulator that didn't have google play and adb root will root the device for you. Hope this helps someone.
I use for enter su mode in abd shell
adb shell "su"
I have a rooted Samsung Galaxy Trend Plus (GT-S7580).
Running 'adb root' gives me the same 'adbd cannot run as root in production builds' error.
For devices that have Developer Options -> Root access, choose "ADB only" to provide adb root access to the device (as suggested by NgaNguyenDuy).
Then try to run the command as per the solution at Launch a script as root through ADB.
In my case, I just wanted to run the 'netcfg rndis0 dhcp' command, and I did it this way:
adb shell "su -c netcfg rndis0 dhcp"
Please check whether you are making any mistakes while running it this way.
If it still does not work, check whether you rooted the device correctly.
If still no luck, try installing a custom ROM such as Cyanogen Mod in order for 'adb root' to work.
You need to replace the adbd binary in the boot.img/sbin/ folder to one that is su capable. You will also have to make some default.prop edits too.
Samsung seems to make this more difficult than other vendors. I have some adbd binaries you can try but it will require the knowledge of de-compiling and re-compiling the boot.img with the new binary. Also, if you have a locked bootloader... this is not gonna happen.
Also Chainfire has an app that will grant adbd root permission in the play store: https://play.google.com/store/apps/details?id=eu.chainfire.adbd&hl=en
Lastly, if you are trying to write a windows script with SU permissions you can do this buy using the following command style... However, you will at least need to grant (on the phone) SU permissions the frist time its ran...
adb shell "su -c ls" <-list working directory with su rights.
adb shell "su -c echo anytext > /data/test.file"
These are just some examples. If you state specifically what you are trying to accomplish I may be able to give more specific advice
-scosler
adbd has a compilation flag/option to enable root access: ALLOW_ADBD_ROOT=1.
Up to Android 9: If adbd on your device is compiled without that flag, it will always drop privileges when starting up and thus "adb root" will not help at all.
I had to patch the calls to setuid(), setgid(), setgroups() and the capability drops out of the binary myself to get a permanently rooted adbd on my ebook reader.
With Android 10 this changed; when the phone/tablet is unlocked (ro.boot.verifiedbootstate == "orange"), then adb root mode is possible in any case.
If you really need to have ADB running as root, the quickest and easiest way is to install Android Custom ROMs and the most popular is CyanogenMod for it has the Root Access options in developer options menu where you can choose to give root access to apps and ADB. I used CM before but since it wasn't developed anymore, I tried looking for some solutions out there. Although CyanogenMod is still a good alternative because it does not have bloatware.
One alternative I found out from a friend is using adbd insecure app which you could try from here: https://forum.xda-developers.com/showthread.php?t=1687590. In my case, it works perferct with an Android custom kernel, but not with the Android stock ROM (vanilla android only). You may try other alternatives too like modifying boot.img of the Android ROM.
in my case, ( device is rooted )
linux$ adb shell # in linux shell
mobile$ su root #=> notice the $ will become #
mobile# whoami #=> root
if you installed "adb root" module in Magisk, you still have to manually switch to root by su root, otherwise, it just LOOKS LIKE you are root, but actually you are NOT root.
I have a Samsung Galaxy Tab S2 running Android 7.0.
Here's how I rooted it today:
Root the device using Odin
Read Alex P.'s answer in this thread regarding editing system\build.prop file.
download onto your tablet: v1.3.9 System Tools Android: All-In-One toolbox
run the app; under "System Utilities" confirm your Odin root worked using "Root Check"
in the same app goto "Root Manager" and use the "Build.prop editor" to effect the changes in the system\build.prop (as specified by Alex P.).
Final Confirmation:
C:\Android\sdk\platform-tools>adb shell
gts28vewifi:/ $ whoami
shell
gts28vewifi:/ $ su
gts28vewifi:/ # su root
gts28vewifi:/ # whoami
root
Upvote Alex P.'s answer.
Further info
and here
and here too
Root Access in Windows Command: adb shell su
Root Access in MacOS Command: ./adb shell su

How to properly add an Android device to Linux for device debugging?

On a Ubuntu 13.10 Linux I am trying to add an Android device to be able to debug it. The device is a 'Vodafone Smart II' (alcatel smart 2 II) and the interesting line of lsusb is as follows:
Bus 002 Device 006: ID 18d1:0002 Google Inc.
I therefore added the following line to the file /etc/udev/rules.d/51-android.rules according to some similar posts found on the web and on SO:
SUBSYSTEM=="usb",SYSFS{idVendor}=="18d1",MODE="0666",GROUP="plugdev"
Then I change file permissions, reloaded the table and tried again with no success:
> sudo chmod a+r /etc/udev/rules.d/51-android.rules
> sudo service udev reload
> adb devices
List of devices attached
???????????? no permissions
I also tried to reconnect the device, and to leave out the SYSFS part and the GROUP part as well. But I always get a list of question marks.
How can I properly add this device to Linux for debugging?
Relaunch adb daemon as root. Simply go to android-sdk/platforms-tools via shell and type:
sudo adb kill-server
sudo adb start-server
It should work correctly from that moment.

How can usb debugging for Kindle Fire can be enabled on a Linux (Ubuntu)?

I am trying to do some Android development on a Kindle Fire, however I am having trouble making my Ubuntu 11.04 recognize the device for using it with the ADB. I've added a line like this SUBSYSTEM=="usb", ATTR{idVendor}=="1949", MODE="0666", GROUP="plugdev" in my etc/udev/rules.d/51-android.rules file, restarted the computer and plugged in the Fire but still adb devices did not show it.
Any suggestions?
It seems that it works if you edit ~/.android/adb_usb.ini and add 2 lines containing 0x1949 and 0x006 and restart the adb server using
adb kill-server
adb start-server
Also, the 51-android.rules file contains the Lab126 vendor id.
You may also need to edit the inf file. See the instructions here:
http://g-ecx.images-amazon.com/images/G/01/sdk/Connecting_your_Kindle_Fire_to_ADB.pdf
Add a single line to: ~/.android/adb_usb.ini. The content of the line: 0x1949
Restart server
$ adb kill-server
$ sudo adb start-server
Worked for me on Ubuntu 11.10
There will be a number of steps you have to take. Basically you need to edit an ini file. Different steps is needed for MAC and PC.
Kindle Fire: Enable USB Debugging

adb devices command not working

I'm running Ubuntu 10.10 64 bit. I have ia32-libs installed along with Android Debug Bridge version 1.0.26.
My problem(s):
adb devices >>> ???????????? no permissions
sudo adb devices >>>> sudo: adb: command not found
adb shell >>> error: insufficient permissions for device
I guess these are all related. Here's the relevant info.
$ echo $PATH
/home/me/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/opt/android-sdk-linux_x86/tools:/opt/android-sdk-linux_x86/platform-tools
$ which adb
/opt/android-sdk-linux_x86/platform-tools/adb
$ adb devices
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
List of devices attached
???????????? no permissions
$ sudo adb devices
sudo: adb: command not found
$ adb shell
error: insufficient permissions for device
I get the same results with a rooted Moto Droid running CM6.1 and a rooted G-Tab running a CM7-based ROM.
I have reviewed the following related posts:
http://forum.xda-developers.com/archive/index.php/t-522827.html
http://ubuntuforums.org/archive/index.php/t-1164359.html
adb command not found in linux environment
I tried most (not all) of the suggestions and I have not been able to resolve my issue. The things I didn't try seemed inappropriate. I would appreciate a few more tips and I'll keep troubleshooting.
One thing I didn't try was editing /etc/udev/rules.d/70-android.rules. Is that likely to be the issue? I can't see how that would cause "sudo: adb: command not found". Maybe my problems are not all related. Anyway, at this point I think I need some input from other people because I don't believe I have a path problem or the other common problems discussed in those other posts.
EDIT: SOLVED thanks to EboMike and RivieraKid. This was actually two different problems:
Item #2 above (sudo: adb: command not found) was solved by making a symlink as follows:
$ sudo ln -s /opt/android-sdk-linux_x86/platform-tools/adb /usr/local/sbin/adb
That allowed me to then do as EboMike suggested and use this solution. Doing that was required for my Moto Droid. (Running adb as sudo was not required for my Viewsonic G-Tablet, however.)
My other two items were resolved by implementing the udev rule as RivieraKid suggested (from this link).
One thing I didn't try was editing
/etc/udev/rules.d/70-android.rules. Is
that likely to be the issue?
Any particular reason why you didn't do that? To answer the question - YES! The udev rules are what informs Ubuntu what your device is and allows user-space tools to therefore access it.
You will not be able to use adb without correctly following the instructions.
With that in mind however, you don't say what version of Ubuntu you're using but I had issues with 10.10 - let me know if you need me to post the contents of my rules file.
Don't worry about running adb via sudo, you don't need it. The MODE="0666" from the udev rule allows you to access the device as any user.
EDIT:
Don't forget to reload the rules:
sudo udevadm control --reload-rules
EDIT #2:
As #Jesse Glick correctly points out, if adb is already running in daemon mode, you'll also need to restart it for this to work:
sudo adb kill-server
I've used sudo here, since that will guarantee that adb will be killed , and it's the officially supported method to stop the server. It will be automatically restarted the next time adb is used, but this time with the correct environment.
You need to restart the adb server as root. See here.
On my Gentoo/Funtoo linux system I am having similar problems:
I gotting always not the correct device description and insufficient permissions:
# sudo ./adb devices
List of devices attached
???????????? no permissions
# ./adb usb
error: insufficient permissions for device
For me helps the howto from Google.
In my case I needed to add the udev rule:
# cat /etc/udev/rules.d/51-android.rules
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", MODE="0666", GROUP="plugdev"
and setting up the filesystem rights
# chmod a+r /etc/udev/rules.d/51-android.rules
After replugging my smartphone the access to the phone was successful, it also appears now in Eclipse' Android Device Chooser:
# sudo ./adb devices
List of devices attached
3XXXXXXXXXXXXXC device
# sudo ./adb usb
restarting in USB mode
You also have to check the membership of your user to the plugdev-group.
Every answer I've read indicates the SUBSYSTEM=="usb". However, my (perhaps ancient) udev needed this to be changed to DRIVER=="usb". At last I can run the adb server as a non-root user... yay.
It can be instructive to look at the output of udevmonitor --env, followed by the output of
udevinfo -a -p <DEVICE_PATH_AS_REPORTED_BY-udevmonitor>
Please note that IDEs like IntelliJ IDEA tend to start their own adb-server.
Even manually killing the server and running an new instance with sudo won't help here until you make your IDE kill the server itself.
restarting the adb server as root worked for me. see:
derek#zoe:~/Downloads$ adb sideload angler-ota-mtc20f-5a1e93e9.zip
loading: 'angler-ota-mtc20f-5a1e93e9.zip'
error: insufficient permissions for device
derek#zoe:~/Downloads$ adb devices
List of devices attached
XXXXXXXXXXXXXXXX no permissions
derek#zoe:~/Downloads$ adb kill-server
derek#zoe:~/Downloads$ sudo adb start-server
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
derek#zoe:~/Downloads$ adb devices
List of devices attached
XXXXXXXXXXXXXXXX sideload
I fixed this issue on my debian GNU/Linux system by overiding system rules that way :
mv /etc/udev/rules.d/51-android.rules /etc/udev/rules.d/99-android.rules
I used contents from files linked at :
http://rootzwiki.com/topic/258-udev-rules-for-any-device-no-more-starting-adb-with-sudo/
HTC One m7 running fresh Cyanogenmod 11.
Phone is connected USB and tethering my data connection.
Then I get this surprise:
cinder#ultrabook:~/temp/htc_m7/2015-11-11$ adb shell
error: insufficient permissions for device
cinder#ultrabook:~/temp/htc_m7/2015-11-11$ adb devices
List of devices attached
???????????? no permissions
SOLUTION: Turn tethering OFF on phone.
cinder#ultrabook:~/temp/htc_m7/2015-11-11$ adb devices
List of devices attached
HT36AW908858 device
I just got the same situation, Factory data reset worked well for me.

Categories

Resources