• Home
  • Category: ADB

Setting up adb on Linux for Android

If you install adb somewhere and try to run it, you get the an error stating “Insufficent permissions”. So we need to setup a couple of steps to get adb ready to work on Linux with our device.

1. Install Android SDK (Instructions found elsewhere)
First install Android SDK to someplace and set its path in ~/,bashrc

2. Setup path to adb
Edit bashrc and add the following line after the normal PATH statement:

PATH=$PATH:/pathto_adb

Set paths like this:

kate ~/.bashrc

Eg:

PATH=$PATH:~/android/sdk:~/android/android-ndk-r6b:~/android/sdk/tools:~/android/sdk/platform-tools:~/android/android-ndk-r6b/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin:~/android/android-ndk-r6b/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/arm-linux-androideabi/bin[/code]
3. set up permissions

On Android Lollipop, you need to enable adb from Developer options:
First enable developer mode, by clicking on build version in About menu multiple times.

Next, under Debugging>Android debugging, toggle it on.
[email protected]:~$ lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 003: ID 0424:2512 Standard Microsystems Corp. USB 2.0 Hub
Bus 004 Device 002: ID 046d:c03d Logitech, Inc. M-BT96a Pilot Optical Mouse
Bus 001 Device 004: ID 0bb4:0c87 High Tech Computer Corp. Desire (debug)
Bus 001 Device 005: ID 0781:5406 SanDisk Corp. Cruzer Micro U3

The important part is this: Bus 001 Device 004: ID 0bb4:0c87 High Tech Computer Corp. Desire (debug)

Note: ID 0bb4:0c87

Or it might be:

[[email protected] ~]$ lsusb | grep -i 'desire'
Bus 001 Device 007: ID 0bb4:0ff9 High Tech Computer Corp. Desire / Desire HD / Hero (Charge Mode)

Here, note

0bb4:0ff9[/code]
N.B: The ID 0bb4:0c87 (or 0bb4:0ff9 depending on the PC) is unique for the Desire. So you can just as well copy and paste into the permissions file.

For a Samsung Galaxy Note 2, it is:
[[email protected] ~]$ lsusb
Bus 001 Device 009: ID 04e8:6860 Samsung Electronics Co., Ltd 

For one plus one, it is:
Bus 002 Device 008: ID 05c6:6764 Qualcomm, Inc. A0001 Phone [OnePlus One]

For Oneplus 3, locating it was slightly more difficult:
First you have to enable Developer mode (Clicking on Build version 5 times), and then toggle USB debugging to On.

lsusb showed:

[email protected]:~$ lsusb
Bus 002 Device 014: ID 2a70:9011
Bus 002 Device 004: ID 1058:0820 Western Digital Technologies, Inc. My Passport Ultra (WDBMWV, WDBZFP)
Bus 002 Device 003: ID 046d:c534 Logitech, Inc. Unifying Receiver
Bus 002 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

I couldnt get any clue as to which one was OnePlus 3.
So I disconnected and reconnected the device, and took a look at dmesg logs:
dmesg:

[email protected]:~$ dmesg
[22373.685139] usb 2-1.4: USB disconnect, device number 13
[22377.722778] usb 2-1.4: new high-speed USB device number 14 using ehci-pci
[22377.816588] usb 2-1.4: New USB device found, idVendor=2a70, idProduct=9011
[22377.816598] usb 2-1.4: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[22377.816603] usb 2-1.4: Product: Android
[22377.816607] usb 2-1.4: Manufacturer: Android
[22377.816611] usb 2-1.4: SerialNumber: 87a9854a
[22377.820830] usb-storage 2-1.4:1.1: USB Mass Storage device detected
[22377.821088] scsi host15: usb-storage 2-1.4:1.1
[22378.819918] scsi 15:0:0:0: CD-ROM            OnePlus  Device Driver    0318 PQ: 0 ANSI: 2
[22378.829944] sr 15:0:0:0: [sr1] scsi-1 drive
[22378.830294] sr 15:0:0:0: Attached scsi CD-ROM sr1
[22378.830507] sr 15:0:0:0: Attached scsi generic sg4 type 5

Thus from idVendor=2a70, idProduct=9011, I found out that the line ID 2a70:9011 referred to Oneplus 3

Create/Edit /etc/udev/rules.d/99-android.rules

gksu gedit /etc/udev/rules.d/99-android.rules (Gnome)
kdesudo kate /etc/udev/rules.d/99-android.rules (KDE)

 

Or use your favorite editor.

SUBSYSTEM=="usb", ATTRS{idVendor}=="0bb4:0c87", SYMLINK+="android_adb", MODE="0666" GROUP="plugdev"
TEST=="/var/run/ConsoleKit/database", 
RUN+="udev-acl --action=$env{action} --device=$env{DEVNAME}"

For OnePlus 1:

ATTR{idVendor}=="05c6", ATTR{idProduct}=="6764", SYMLINK+="libmtp-%k", ENV{ID_MTP_DEVICE}="1", ENV{ID_MEDIA_PLAYER}="1"

For OnePlus 3:

ATTR{idVendor}=="2a70", ATTR{idProduct}=="9011", SYMLINK+="libmtp-%k", ENV{ID_MTP_DEVICE}="1", ENV{ID_MEDIA_PLAYER}="1"
sudo service udev restart

Now unplug and then reinsert the Device to the usb connection.

Now, adb devices shows my device

On Ubuntu 16.04, and my Oneplus One all of this is no longer necessary. The steps are:
sudo apt install android-tools-adb
OPO:
Connect phone in MTP mode.
Developer options (enable it by multi-tapping About:Android version) > Android debugging: On
Accept the “Trust computer” dialog
Test with

adb devices