Chinese Android Debugging: How to use a Unbranded Android Device for Application Testing on Ubuntu with Eclipse

developer.android.com has a nice writeup on how to setup a hardware android device for application testing on the Using Hardware Devices page. It also gives a list of USB Vendor IDs, which are required to setup your hardware device. But the list of vendors may not include your Chinese / Unbranded android phone or tablet.

For eg. The vendor ID of a NATPC/MID tablet is apparently not on the list of vendor ids which includes the likes of HTC, Asus, Google,Foxconn, etc.

In such a case, these are the errors you may get:

On selecting Run app in Eclipse, you are greeted with a prompt asking you to select an Android Device. However the list of Android devices shows a Android Device with Serial Number as "??????????" i.e a series of question marks and same for the state of the device. Additionally, this device is not selectable.

Eclipse: Prompt showing unrecognised android device

 Open Terminal and cd into your android-sdk/platform-tools folder and run adb (Android Debug Bridge)
android-sdk/platform-tools$ ./adb devices
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
List of devices attached
????????????    no permissions


This is because the Vendor ID is not recognised by adb. Which is because we could not specify a Vendor ID, as the same is not available to us.


Here are the steps to setup your Unbranded Android device for application testing.

1. USB Debugging: Go to the settings on your android device and turn on USB debugging.

2. Connect your android device via USB.

3. Open a terminal and run lsusb

$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 002: ID 18d1:0003 Google Inc. 


In the case of the Chinese device that I used, this was what lsusb returned. The last line of the above result shows a device labelled Google Inc. The Vendor ID is (see bold) 18d1

lsusb gives you a list of USB buses and the devices attached to your computer via USB.

Apparently, the Chinese device I used, makes itself appear as a device by Google Inc and uses the same Google Vendor ID. Your device may have a different Vendor & Vendor ID , but using lsusb you can easily access the same.

4. With root privileges, create a xx-android.rules file at /etc/udev/rules.d where xx is a number.

 for eg. I created a file called 51-android.rules with the following content

SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", MODE="0666", GROUP="plugdev" 


(Instructions given in Using Hardware Devices)

The device id in this case is in bold (18d1) and is all that you have to change.


The /etc/udev/rules.d/ folder contains custom rules that are read by udev.
If it is the only rules file you create for your android devices, the name of the rules file will not matter. The number is used for order of preference. (More info:  udev , the README file in the /etc/udev/rules.d/ folder)


5. Reboot

Now when you run ./adb devices from terminal you will get the serial number and Vendor of your device.

cd into your android-sdk/platform-tools folder and run ./adb devices

android-sdk/platform-tools/$ ./adb devices
List of devices attached
12345678    device


Eclipse will also recognize the device and you can select your device to test run your android application.

tl;dr:

If you do not know the Vendor ID of your android device, which is needed for the 51-android.rules file and your device vendor is not on the Vendor ID list on the Android Developers website, run lsusb from Terminal to get a list of devices with vendor ids attached via usb and use this id in your rules file.

Sources & Further Reading:
1. Android Developer: Using Hardware Devices
2. lsusb
3. udev
  

Comments

  1. Great article. A lot of people have this problem with no practical solutions out there like you provided.

    ReplyDelete

Post a Comment

Popular posts from this blog

CPU Temperature Guide for Intel Core 2 Duo : Range of Normal CPU Temperatures

CS50: "undefined reference to `GetString' " and other errors

Appengine: Custom Error Handlers using webapp2 - Python 2.7