109

I have a rooted Motorola Defy+ running a Cyanogenmod v11 custom ROM (nightly build) created by Quarx. Using Android Studio Workspace,(ASW) v.1.1.0, when I try and debug on this device, I get

????????????[null]

listed in the Choose Device window, with the Logcat window showing

insufficient permissions for device

I would really like to use this device and ROM for debugging purposes.

When I enter lsusb from the command line I get,

Bus 002 Device 002: ID 22b8:431d Motorola PCS

This is the correct device id for Motorola units. I have installed 51-android.rules and 71-android.rules in /etc/udev/rules.d/ with the correct Motorola ids in these files.

I've also tried Revoke USB debugging authority, from Developer Options on the device, with no luck.

I have not tried running ASW as root hoping that there might be another option; is there?

Update: I was able to get in and access ADB by

uvachem-gsmith2:/home/greg/Android/Sdk/platform-tools # ./adb

I then did a kill server, did an SU to root user and restarted the server. I then tried to connect to the device from Android Studio. Got a message on the device about accepting the RSA key from the PC, said "Yes" and then was able to deploy the app to the device. So back to my original question, Is there another way to access this device without logging in as root? It seems as if there is a permission issue on the phone file system that is preventing this...

Update #2 The core problem here was a permission thing. Even though running ADB as root will allow access to the rooted Android device, a better solution is to change permissions in the udev file for this device...resetting 664 to 666, (see answer below). This allows the PC to access the file system on the device.

portsample
  • 1,986
  • 4
  • 19
  • 35
  • I know this might be a simplistic approach, but did you enable USB debugging in developer tools?. Could try an adb root before. And also and abd remount – Bogdan V. Feb 24 '15 at 20:04
  • @BogdanV. Yes, USB debugging is enabled. Please expand on the suggestions in your last two sentences. Thanks. – portsample Feb 24 '15 at 20:12
  • Go to a terminal and type "adb devices". If you see your device, then the Android Debug Bridge (adb) sees the device. If it does, type "adb root" to make adb able to issue adb shell commands as root. Then do an adb remount to get access to the entire filesystem on the device. If it doesn't work still, then the issue lays with Android Studio – Bogdan V. Feb 24 '15 at 20:39
  • @BogdanV. Android Debug Bridge (ADB) is not found either when logged in as user or root. I tried "adb devices" as well as "./adb devices" with "no such file or directory" returned. Currently I am debugging to a Panasonic Toughpad with Android Studio and having no problems. – portsample Feb 24 '15 at 21:07
  • This is peculiar, as adb is a basic Android SDK tool. Maybe you don't have the android sdk platform tools directory added to the path. But anyway, if you have a solution, use that. – Bogdan V. Feb 24 '15 at 21:12
  • The Toughpad is running a stock ROM and has no problems being recognized, whereas the Defy+ has the Cyanogenmod custom ROM and IS NOT recognized by either by Eclipse with the ADT plugin, or Android Studio. – portsample Feb 24 '15 at 21:20
  • @BogdanV. NO! Running adbd **on the device** as root has NOTHING to do with the problem here. In suggesting `adb root` and `adb remount` you are giving **dangerously mistaken advice which will not help with this problem in any way** - fortunately advice that would fail on consumer devices, but is potentially rather dangerous on customized devices like the poster has. – Chris Stratton Feb 25 '15 at 02:26
  • @porstample - Edit the actual line from your android rules file which you believe will handle this device into your question. If it mentions a username, make sure that is yours. Also, did you tell udev to reload its rules and subsequently plug-cycle the device? Or failing that, reboot the PC? – Chris Stratton Feb 25 '15 at 02:28
  • @ChrisStratton The etc/udev/rules.d/ directory did not have an **-android.rules file until I put them there (51- and 71-)...could they be someplace else in openSuse 13.2? I have done several reboots after udev mods w/no success. TIA – portsample Feb 25 '15 at 05:50
  • Where there any other rules files there? Again, please include the specific line from the rules file you think will handle this device as an edit to your post. – Chris Stratton Feb 25 '15 at 07:05
  • @ChrisStratton The only rules file previously in etc/udev was 55-libsane.rules and applied only to scanners. There are additional *.rules in /usr/lib/udev, but none appear to have relevence to this issue. I'm suspecting the openSuse may have a different method of hardware recognition as it applies to Android Studio. – portsample Feb 25 '15 at 15:50
  • The fact that there was already a file there (for something else) at least hints that it is the right place (or else it's been previously guessed to be). **But -1 for still not having posted the line of the rules file which you are hoping will handle this device**. If you just downloaded the current rules file off the developer site verbatim, **that will not work**. – Chris Stratton Feb 25 '15 at 15:52
  • #Motorola SUBSYSTEM=="usb", ATTR{idVendor}=="22b8", MODE="0664", GROUP="plugdev" – portsample Feb 25 '15 at 15:56
  • Note that by posting that in a comment, and not in the body of your question, you make it look as if the entire line is commented out and thus ineffective, when that is not really the case but rather an artifact of SO comment formatting. – Chris Stratton Feb 25 '15 at 19:41

22 Answers22

215

I had this while using a Linux machine with a Nexus 4 running Android 5.1

The fix was to enable both 'debug over USB' and 'connect as MTP'. The opposite is true when using the same device and Android Studio and adb on OSX though - to allow Android Studio to recognise the handset, I need to disable 'connect as MTP'.

cro
  • 2,437
  • 2
  • 10
  • 9
  • 1
    I ran into similar behavior on the same development environment with two different devices, and felt it is worth mentioning to anyone led to this post as I was. I have an LG Realm that only works in Android Studio (running on Linux Mint) if I connect using MTP, and an LG Logos that only works when I connect using PTP. So it might be worthwhile to tinker with both options for any troublesome device. Odd indeed, took me over an hour to figure that out just now... – BMB Apr 24 '16 at 19:19
  • That is strange but it is the case. Not sure if I have to mount the device or not. – jamie Jul 28 '17 at 18:06
  • 2
    On my Pixel XL, I had to choose "Use USB to transfer photos (PTP)". – yohosuff Mar 14 '18 at 00:57
  • 1
    Even with Android Studio (3.0.1) I had to enable MTP. – ffonz Mar 25 '18 at 15:01
  • 2
    On Android 8, this option can be found under _Developer options -> Networking -> Select USB Configuration: MTP (Media Transfer Protocol)_. – Lucio Paiva Oct 13 '18 at 20:06
  • For MotoG6 I have to select "Use device as MIDI" – Confused Apr 21 '19 at 12:02
  • @cro Thanks for this! Saved my day as I was having the same issue in Arch Linux. Apparently, any form of file transfer you select in your device will do the trick. The default and safe (if not in use) 'no data transfer' won't work - and makes total sense. This thought comes based on tests I just made with my Moto G7 Play. – José Jan 20 '20 at 20:11
107

I found a simple answer that worked for me:

adb kill-server
sudo adb start-server
sudo adb devices

You will find your device then.

Reference: http://itsfoss.com/fix-error-insufficient-permissions-device/

starball
  • 20,030
  • 7
  • 43
  • 238
84

It's simple. Just change your USB mode to File Transfer mode then it works.

isarojdahal
  • 994
  • 8
  • 12
39

Android 8

MTP is no longer available. On my android 8 "Transfer Files" option did not work.

"Transfer photos PTP" Is worked, and Studio showed the device name.

  • Steps on your cell phone

    1. Open the developer options
    2. Enable USB debugging.
    3. change USB connection to PTP
  • Steps on Linux

    1. on console run sudo usermod -aG plugdev $LOGNAME

Android 9

With Android 9 use the option File Transfer.

kelalaka
  • 5,064
  • 5
  • 27
  • 44
29

Changing permissions in this line from /etc/udev/rules.d/51-android.rules,

#Motorola 
SUBSYSTEM=="usb", ATTR{idVendor}=="22b8", MODE="0664", GROUP="plugdev"

to,

#Motorola 
SUBSYSTEM=="usb", ATTR{idVendor}=="22b8", MODE="0666", GROUP="plugdev"

resolves this issue in a manner that DOES NOT require running adb as root.

portsample
  • 1,986
  • 4
  • 19
  • 35
  • 6
    Yes, if you give permissions to all users that will work, but your rules files is designed based on the idea that what you are supposed to do is add your user account to the plugdev group, log out, and then log back in - that gives you the "group" 6 in the original 0664. – Chris Stratton Feb 25 '15 at 19:40
  • 1
    This file doesn't exist for me, using Elementary OS Freya – Mark O'Sullivan Nov 04 '16 at 11:43
  • I have just created this file on Ubuntu 14.04 for a Huawei device. Works perfect! Thanks for this answer!! – BenRoob Jun 19 '17 at 09:37
  • i had to restart the adb server after this to get `adb shell` to work – rrosa Jun 29 '17 at 03:45
  • 5
    worked for me but first had to create the file because it didnt exist and then change the idVendor to what it is in lsusb(see greg93 answer). This should not be part of starting developing on linux. – tonisives Nov 23 '17 at 11:11
  • I created this file in Ubuntu 18.04, added support for Qualcomm. Then reloaded all rules, unplug and re-plugged the USB cable, it worked!! – Aananth C N Oct 24 '18 at 05:31
  • I found more details in [this answer](https://askubuntu.com/a/349191/572578) at the Ask Ubuntu Stack Exchange. – dan-gph Feb 17 '19 at 09:11
  • +1. Works great. This is the only method which allows you to have internet from the device as RNDIS and debugging on the same device at the same time. Refer to https://askubuntu.com/a/349191/572578 for more details. If you have 2 or more devices just add the line mentioned above for each of the devices in the same file which is 51-android.rules. Make sure to put the id from lsusb command for each device. Check the link mentioned to get the id. – Doc Aug 28 '20 at 04:04
12

IN my phone Symphony W75, in option USB computer connection-> selecting Connect as Media device(MTP) has solved the problem.

ranit
  • 397
  • 3
  • 10
10
  • Enable USB debugging
  • Use USB to transer file
Mayoogh Girish
  • 501
  • 1
  • 6
  • 14
8

Long to short, I had the same problem with a Prestigio PMP5570C tablet,

all you have to do is to confirm on your tablet that you want to copy data to/from your computer (what i forgot), and add the 2 lines that @portsample wrote.

You can find the idVendor of your device typing

lsusb

in UBUNTU 12.04, then you get:

Bus 001 Device 011: ID 2207:0010,

where 2207 is your vendor id. Summed up the question and answer...

greg93
  • 389
  • 3
  • 6
8

I updated my device (Nvidia Shield) that was previously connecting fine, so I knew that the PC setup is correct already. The developer settings seem to have a new layout on Android 7.0.

It is under Settings > Preferences > Developer options > Networking > Select USB configuration

Here, I needed to select PTP and everything works fine again:

Selecting USB configuration mode

Habib
  • 472
  • 4
  • 9
7

This procedure solves the problem for me:

- On the Android device, drag the top menu and select "USB for file transfer"
- Press "Run" again
5

Go to Developer Options -> Default USB Configurations and Change to PTP

Run these two commands in terminal

 sudo adb kill-server
 sudo adb start-server

Should Work!

Aakash
  • 5,181
  • 5
  • 20
  • 37
3

I made a script for this error. For me it works fine in Fedora 28, but it should work in many Linux distributions. Just create a file with the content of the selfexpanied script. I called it usbDebbugingAndroidStudio.sh
Give him execution permission with: chmod +x usbDebbugingAndroidStudio.sh

And run it: sudo ./usbDebbugingAndroidStudio.sh

After that check the list displayed by the command lsusb and introduce the Id of your device. For example: My output was: Bus 006 Device 002: ID 05c6:9091 Qualcomm, Inc. So I type 05c6 and press enter.

The script:

#!/usr/bin/env bash


#This script configure Android Debug Bridge permissions to solve the following
#error: com.android.ddmlib.AdbCommandRejectedException: insufficient permissions for device
#This error is produced when you try to install an APK from Android Studio in your device.
#You can check the vendorId here:
#https://developer.android.com/studio/run/device#setting-up
#If your device's brand isn't listed check the info displayed by the command lsusb

lsusb
#My output was:
#Bus 006 Device 002: ID 05c6:9091 Qualcomm, Inc.
#The id for this line is 05c6
echo -n "Enter the id of your mobile device: "
read usbProviderId
cd /etc/udev/rules.d/
sudo touch 51-android.rules
(
sudo cat << _EOF_
SUBSYSTEM=="usb", ATTR{idVendor}=="$usbProviderId", MODE="0666", GROUP="plugdev"
_EOF_
) | sudo tee 51-android.rules

#Give read and write permissions to the file
sudo chmod a+r /etc/udev/rules.d/51-android.rules

#Kill the Android Debug Bridge server to restart it
cd $HOME/Android/Sdk/platform-tools
sudo ./adb kill-server

#If this still doesn't work unplug the usb cable and connect again.
#And repeat the last step Kill the ADB server.
jesusjbr
  • 31
  • 1
  • 2
1

What the F... ! :) Note : I have seen it on android 8.1 on a One+5t...

Even we do all of above, it is necessary to make something on your android device .. in addition to go in dev options menu (usb debug) (don't hesitate to reset "cancel authorization" or something like this (I am in french version ;) )

If some people meet the same problem than me, maybe it could be usefull for you too : Don't forget to authorize devices in your phone (each time of usb connect on the android device if you don't select always box). Beside, you can suppress the old authorized devices on your phone and start with proper parameter to authorize clearly your pc on your android device

When you connect the android device, a pop up or notification ask to authorize a mac address or equivalent to the device : authorize it if you want to authorize connection between your linux pc and your android device.

It is necessary to obtain autorisation on your android device when you use connect the usb cable (if you don't accept all the time but if it is the first time this box is going to appear on your devices) if you don't do it, adb devices show unauthorized even all rights are good (666, UDEV etc)

Note : thank you for your precious help. A last thing, sorry for my english

gnutux95
  • 31
  • 4
1

I'm facing this issue while run flutter app from android studio 4.1, i did remove usb cable and plug into second usb port and its working :),

I'm writing this if someone face same issue then they can get help.

hio
  • 915
  • 8
  • 26
1

Same issue on Fedora 32, to fix this try this:

adb kill-server
adb start-server
ahmnouira
  • 1,607
  • 13
  • 8
0

For me and possibly many others the issue is to do with access rights to devices on the machine. Now that this is well documented in the android documentation, I think the best solution is here

On Debian based Systems you can run lsusb or dmesg to get vendor id if your vendor does not exist on the given list

Peter Chaula
  • 3,456
  • 2
  • 28
  • 32
0

I have face the same problem and i have resolved this by Adding the path of your_android_sdk_path to the environment variable like

sudo export $PATH:/your_android_sdk_path/platform-tools/adb

its your wish how you want to add this to your account or system wide by editing these file ~/.bashrc file or ~/.profile or /etc/profile, /etc/bash.bashrc, or /etc/environment if u want to add to system wide access.

and then create the link of that in bin

sudo ln -s /your_android_sdk_path/platform-tools/adb /bin/adb

if you have used adb devices or any command then first kill the server like

adb kill-server

then start the server like

adb start-server
adb devices

now you can see your devices are listed properly without an issue

Naval Kishor Jha
  • 894
  • 9
  • 13
0

As the error message said, it is a permission insufficient problem. In my experience, it only happened on my Linux machine, and works well on MacOS and Windows. Launching your Android Studio with root permission could avoid this problem.

$sudo /your_android_studio_path/bin/studio.sh
richa
  • 1
0

In my situation:

cd /etc/udev/rules.d/
sudo chmod a+r ./*.rules  #the name of your rules files.

Then,I can use adb without this error.

0

if accepted answer not worked for you then just simple follow steps: Just open your android studio terminal:-

adb kill-server

adb start-server

it worked for me.

Ravish Sharma
  • 207
  • 2
  • 14
-1

Without running Linux sudo apt-get install adb. Don't forget to enable USB debugging.

Ref: https://developer.android.com/studio/run/device

-1

On Android 12: Developer Option -> Default USB configuration -> PTP then run application. It will work