Android Debug Bridge on HTC Desire

Illustration

Debugging Android programs on real device is easy. You just need to follow guide and everything will work. That is theory at least.

All instructions worked just fine up-to point where USB driver had to be installed. Dreadful “Driver not found” was all I was getting. Problem was obvious. My HTC Desire was just too new to be included in driver pack.

However, I had a hunch. “USB Driver for Windows, Revision 3” that was available to me was one that included support for Nexus One. Since Desire seems pretty close to it, I wanted system to use Nexus drivers anyhow.

First thing to do is right-click on My Computer, select Manage and go to Device Management. There you will see ADB device with yellow question mark. Right-click on that device and select properties. Under tab Details there is one combo box with properties. There we need to see “Hardware Ids”.

In case of HTC Desire hardware IDs in question were “USB\VID_0BB4&PID_0C87&REV_0100&MI_01” and “USB\VID_0BB4&PID_0C87&MI_01”. In “android_winusb.inf” file I just copied two entries for Google Nexus (“%SingleAdbInterface%” and “%CompositeAdbInterface%”) and replaced their hardware IDs with hardware IDs for Desire (with slight trimming). Changes are highlighted:

...
;Google NexusOne
%SingleAdbInterface%        = USB_Install, USB\VID_18D1&PID_0D02
%CompositeAdbInterface%     = USB_Install, USB\VID_18D1&PID_0D02&MI_01
%SingleAdbInterface%        = USB_Install, USB\VID_18D1&PID_4E11
%CompositeAdbInterface%     = USB_Install, USB\VID_18D1&PID_4E12&MI_01
;
;HTC Desire
%SingleAdbInterface%        = USB_Install, USB\VID_0BB4&PID_0C87
%CompositeAdbInterface%     = USB_Install, USB\VID_0BB4&PID_0C87&MI_01
[USB_Install]
...

And voilà, we have our driver ready.

P.S. While I talk about HTC Desire here, there is no reason why same method would not work for any other Android phone, providing that it is compatible (on USB communication level) with Nexus.

[2010-06-17: At least in case of Windows 7 and it’s “No driver found” error, it is enough to add only %CompositeAdbInterface%. I haven’t tested on other operating systems but I think that %SingleAdbInterface% is not used at all.]

Microsoft Kinect

Illustration

I wrote some time ago about Project Natal. It seemed like great technology but I heard no news about commercial release for quite a while.

Yesterday (2010-06-13) it was presented at Electronic Entertainment Expo in Los Angeles (E3) under it’s new name - Microsoft Kinect. Somebody ought to shoot marketing department since developer code names are pretty much always better than final product name.

Although release date was not specified, technology seems to be quite ready and I do hope that it will be released this year. Even with it’s new name it remains best thing to have in living room and, for me, single reason why I might buy XBox.

Get Application's Icon

When I was building “About” dialog for my applications, I wanted it to be as reusable as possible. That meant that all data should be retrieved while program is running. Only thing that I could not discover within .NET code was application’s icon.

Windows API came to rescue. In short we just load our own assembly for purpose of extracting one icon resource. That gives us “good old” pointer which can be used to create bitmap.

IntPtr hLibrary = NativeMethods.LoadLibrary(Assembly.GetEntryAssembly().Location);
if (!hLibrary.Equals(IntPtr.Zero)) {
    IntPtr hIcon = NativeMethods.LoadIcon(hLibrary, "#32512");
    if (!hIcon.Equals(IntPtr.Zero)) {
        Bitmap bitmap = Icon.FromHandle(hIcon).ToBitmap();
        if (bitmap != null) { return bitmap; }
    }
}

Probably most curious thing is “#32512” string. This is resource identifier that goes way back into non-CLR past (also-known-as IDI_APPLICATION constant) and it is not only one that can be used.

Here is full sample.

What Is Happening to Me?

Illustration

Few days ago I wrote instructions for setting-up Android development environment. Since I am mostly known as Windows developer this caused lot of questions in my neighborhood. Here are answers to most common ones and some observations of mine.

1. Yes, I am still C# developer at heart.

2. I still love Windows Mobile. This goes for 6.5. As far as Windows Mobile 7 is concerned, I have my reservations (this is drastic change after all) but it is really hard to comment anything at this time. Most of known limitations and features of that platform are subject to change by the time of launch. Anyhow most of things that bother me are just political decision (e.g. multitasking) and not a real limitation.

3. I do not consider my work in Android as betrayal of my love. While I love Visual Studio and what it does offer, I think that trying other environments can only lead to good things.

4. My phone ratio is 2:1 in favor of Windows Mobile (HP iPAQ 514, HTC S740 and HTC Desire).

5. Exchange ActiveSync is best protocol there is. I am not sure how good it was for Microsoft to allow Google and others to use it in their products but from customer side I must confess it is great decision. It allows all my phones to share same data regardless of their underlying platform and everything gets synchronized by “it-self”.

6. Both Windows Mobile and Android share same hate for letters Đ and đ (latin capital/small letter D with stroke). While I can synchronize existing contacts with this letter, neither of these platforms will allow me to enter this letter via keyboard. When letter is part of your alphabet it gets annoying fast.

7. Yes, I will probably make some comparison of development experience between these platforms in future.

Setting Android Environment

Illustration

Prerequisited

Before we start anything, we need two downloads:

Java SE Development Kit

This one is prerequisite for everything else. Just download it, run it and go wild on “Next”. Installation is as easy as it can be.

Installing Eclipse

Installing Eclipse is as easy as unpacking it. For purpose of this walk-through I will unpack it to root directory of drive D: (eclipse.exe will be located in directory D:\eclipse).

Installing Android SDK

Unpack archive to (D:\eclipse) and run “SDK setup.exe” (from “D:\eclipse\android-sdk-windows\SDK setup.exe”). Location is not set in stone but I like it in subdirectory of eclipse. If you desire some other location, just go for it.

As soon as you start it, it will attempt to download newest repository data. If you are behind proxy, this step will fail. In that case just go to “Settings” and fill proxy server and port fields. Often it is also necessary to check “Force https://… sources to be fetched using http://” for everything to download properly.

Once update is completed, you should get list of packages to install. I just leave it at default, check “Accept All”, and click on “Install”. Brace for lengthy download (around 800 MB for Android 2.2).

ADT Plugin for Eclipse

Once you start Eclipse go to “Help”, “Install new software”. Click “Add” once window opens. Now write “ADT Plugin for Eclipse” under site name (exact naming is not important) and “https://dl-ssl.google.com/android/eclipse/” under location. If your Internet access goes over proxy, you will need to use http location “http://dl.google.com/android/eclipse/”.

When packets are found (“Android DDMS” and “Android Development Tools”) I just select them both and click on “Next”/“I accept …”/“Finish” combo few times and download will start. After restart you need to go to “Window”, “Preferences”. There, under “Android” node, you need to select folder with unpacked Android SDK (in my case “D:\eclipse\android-sdk-windows”). All other things I left as default.

After one more restart (I am not really sure it is necessary) you will be able to create new project under “File”,“New”,“Project”:“Android\Android Project”.

Anything more

As you attempt to start project, you will get prompt to create emulator. If you would like audience as broad as possible, Android 1.6 is reasonable choice. If you want to target only newer devices, 2.1 is one that you should do your testing on. Those are only rule-of-thumb advices - do not take them too seriously.

If you intend to use command-line tools it would be good to add Android SDK tools to path (for me it is under “D:\eclipse\android-sdk-windows\tools”).

It is definitely not as easy as installing Windows Phone Developer Tools but it is not too bad.