Thursday, September 22, 2011

It Just Works

It is nice to have an actual device to test and try things, especially when your Lion is bitten by the infamous 19099 bug. Mine is. So I was very happy to plug in my new Lenovo Thinkpad Tablet, configure the device for development, start some Honeycomb samples from Google, and run them on ... 
Surprise. The tablet was not visible in the Eclipse Run and Debug dialogs.  

With a little help this friend came out of the box in my adb. 
I could see that it was connected to my Mac, but adb did not pick it up. Reboots etc. did not help. Google. Result: I am not the only one having that problem and it seems to concern other tablets too. So here is the treat:

Step 1. Connect the tablet to you Mac
Sometimes we forget this step and looking for errors then becomes … interesting.

Step 2. Prepare the tablet
Go to your tablet settings
  • Check "Applications > Unknown Sources"
  • Check everything under "Applications > Development". Note: These settings are for development only and should be disabled for security (and battery) reasons when you use the device in the "real world" (or the "Matrix", if you prefer).
  • Check Accounts & sync > Allow sync with PC
  • Select USB Settings > "Charge Only" (I use this setting, "Transfer files" seems to work, too)

Step 3. Open a shell and run 
adb devices 
If you get an error message like "command not found" you should set up your Android development tools. If the output of the command is empty, however, then you have the same problem that I had. Read on...

This means that the Android Debug Bridge does not recognize the device. On a different OS, you could probably fix it by installing specific USB drivers, but on a Mac?  After googling around a bit, I found the money quote in the Android documentation for setting up your device.

If you're developing on Mac OS X, it just works.

Yes it does. Except when it doesn't. 

Thanks to user "Volker1" in the Lenovo forums for pointing out this solution to the problem:

Step 4. Get the USB Vendor ID for your tablet
You can get this from "About this Mac" in the detailed listing under Hardware > USB. You can also look up a number of known USB vendor IDs here. For Lenovo it is "0x17ef". 

Step 5. Edit the file .android/adb_usb.ini 
This file is in you HOME directory, so if you use vi, do vi ~/.android/adb_usb.ini

Add a line just with the ID from step 4, so in my case after editing the file looks like this:

# USE 'android update adb' TO GENERATE.

Note the capital "DO NOT EDIT" and the second line: "USE 'android update adb'  TO GENERATE." I tried and this DID NOT WORK. So I DID EDIT. Shouting doesn't help here either.

Step 6. Then do in a shell
adb kill-server
adb start-server
adb devices

Now should see your tablet and can deploy your code from Eclipse too. And it just works.