A brief posting describing how I got my Android device connected to my Windows 7 machine so that I could use the Android adb tool to install an application.

My objective is to be able to run the Android Debug Bridge (adb) on my Windows 7 machine, connecting to an Android device. This allows me to perform a number of useful administrative tasks such as deploy applications, look at application logs and start a unix shell session on the device.

We’re getting into territory here where incautious actions can damage your Android device. The instructions here can get you powerful access on your device, so “caveat lector”, don’t do any of this unless you take responsibility for unpleasant outcomes such as your device becoming as useful as a housebrick.

The starting point is that you have installed Eclipse and the Android SDK manager. References on how to do this are supplied with the IBM Mobile Technology Preview as mentioned in my previous article. There are a number of optional installation packages which can be seen in Eclipse if you select Window->Android SDK Manager. You need to ensure that the Google USB Driver is installed.

image

When you select this item the drivers are downloaded and placed in your ADK installation directory.

image

However, this does not conclude the installation procedure, when I plugged in my device it was not visible to adb. So there’s one more step:

Installing the Driver for the Device

First, ensure that the device is attached to the USB port and that the device memory is not mounted as a disk. Then in the Windows Device manager you should be able to find your device. In my case, I happen to be using a StorageOptions Scroll, which manifests as a device called TCC8900. RightClick on the device and you get the option to install a driver, and can browse to the just downloaded material. Unfortunately I got a message saying that no suitable driver could be found.

It transpired that the driver supplied by Google was suitable but the configuration file android_winusb.inf did not contain a matching entry. A bit of Googling (rather cyclic, no?) lead to the solution: the  to the .inf file:

as I’m using 64 bit Windows, so I find the line

[Google.NTamd64]

on 32bit Windows it’s [Google.NTx86], and insert the lines

; Scroll – recovery
%SingleAdbInterface% = USB_Install, USB\VID_18D1&PID_DEED
%CompositeAdbInterface% = USB_Install, USB\VID_18D1&PID_DEED&MI_01
; Scroll – bootloader (fastboot)
%SingleBootLoaderInterface% = USB_Install, USB\VID_18D1&PID_D00D
;

just before the next entry

; HTC Dream

Then, retrying the installation works just fine. The device now appears under a more understandable name:

image

Magic Numbers

If you are using a different device then your entries in the inf file will be different. You can find the values by selecting your device, viewing the property tab and selecting hardware IDs.

Now what can we do?

So now that the device is attached we can simply select an Android application project, rightClick->Run As –> Android Application and it is deployed to the device and launched, any output appearing in the LogCat view. This is a great improvement on mounting a drive, copying an apk file and installing the app.

In my previous posting I described how to get started with the freely donwloadable  IBM Mobile Technology Preview. I took one of the samples provided and ran it in an Android emulation environment. That worked nicely to test some features of the samples but the speed of emulation is quite slow. This doesn’t make for a productive Code/Test cycle. In this article I want to describe an alternative approach using a Chrome Plugin known as Ripple. Ripple was created by the gloriously named Tiny Hippos, who were acquired by Research in Motion this year.

Hybrid Applications

One key aspect of the IBM Mobile Technology Preview is the use of PhoneGap to enable building Hybrid applications. That is applications that run in a browser and yet which exploit native device capabilities such as GeoLocation and the Accelerometer. In effect PhoneGap provides an device-independent JavaScript API hooking into a device-specific native implementations on each platform. The expectation is that the bulk of a Hybrid application is implemented in JavaScript that is portable across a wide range of devices. The Dojo mobile APIs will detect the particular device and hence allow suitable style-sheets to be selected giving a visual appearance that fiits the device standards. Hence we have a vision (to use an old phrase) of  “write once, run anywhere”. In my team’s experience this, with careful design, this vision can be realised.

When developing such Hybrid applications we can greatly accelerate the development/unit test cycle if we can simply run the JavaScript in a browser. This is where Ripple comes in: it provides an emulation of different device types and an implementation of the major PhoneGap APIs running directly in Chrome. I am going to show how to use Ripple to run the Mysurance sample, which uses GeoLocation in Ripple.

One note: some aspects of the Technology Preview, notably the Notification framework, depend upon Java code. We cannot test these aspects using Ripple as it currently stands. I believe that Mysurance is typical of most Hybrid applications in having very significant portions of the code in JavaScript and hence benefiting from testing in Ripple.

Setup

The application assets (web pages, JavaScript, css and images) are held in a assets directory. We need those to be accessible to the browser. It simplifies some of my other testing if I serve these files from a web server such as Apache or IBM HTTP Server.

I add these entries to my httpd.conf:

Alias /mysurance "C:/IBM/MobileTechPreview/samples/mysurance/eclipse-project/assets/www"

<Directory "C:/IBM/MobileTechPreview/samples/mysurance/eclipse-project/assets/www">
    AllowOverride None
    Options None
    Order allow,deny
    Allow from all
</Directory>

and restart Apache. I can now point my browser at

http://localhost/mysurance/apps/mysurance/step12.html

and see the Application

Ripple Installation

You can install Ripple into a running Chrome instance from this Ripple download site. On completion the Ripple icon is visible in the toolbar

image

The first time you access an application with Ripple installed you see this

image

which offers a number of possible runtimes, I choose PhoneGap, and then can select the Ripple icon and choose to Enable Ripple.

image

The Mysurance application now shows in a device emulator, along with various control capabilities.

image

GeoLocation

If you explore the Ripple control capabilities you will see that you can select different devices, emulate the accelerometer and send events. Here I’m going to focus on the GeoLocation. Expanding that section I see

image

With a default location of Waterloo Station. We can change this, if we know the latitude and longitude of our desired location. I will choose a place in Yorkshire, finding it’s coordinates from this site.

image

Ripple now shows the new location

image

Back in the application I pick Accident Toolkit and from this menu

image

select Call the Police. This brings up a map centred on the location we specified to Ripple, with nearest police station identified.

image

Select the station gives us the contact details.

image

Conclusion

This does seem to be a very promising approach to testing some aspects of Hybrid applications.

In October 2011 IBM announced the Mobile Technology Preview, which you can download here. The preview enables development of “Hybrid” mobile applications that can exploit server-push notifications.  A “Hybrid”  application is developed in Javscript and runs in a device’s browser environment and exploits a virtual device API (PhoneGap in this case) to access native device capabilities such as geolocation and the accelerometer. It is interesting to see that the preview also includes an Alpha release of the 8.5 version of the WebSphere Application Server, which is used for hosting the server-side code, and in particular the notification engine.

The promise of  the Hybrid approach is that rich applications exploiting device capabilities can be developed more cost-effectviley that developing device-specific Native applications.

In this article I want to describe how build and run one of the samples provided with the preview. I encountered a few minor glitches in getting this going, I hope I can save you some time.

Installation

The preview documentation includes an article, ProjectSetup.html,  which describes how to set up your development environment.  This procedure requires you to also download Eclipse, the Android SDK and the emulators – the Android Virtual Devices (AVD) that you will use for testing.

I did my initial testing with the Eclipse Helios release, but more recently have been using Indigo. I had occasional stability problems with the latest AVD 4.0 release and so chose to install version 2.2.

On completing the installation my Eclipse Window menu now has some Android-related options.

image

Note that amongst the installation steps is an adjustment to your eclipse.ini file to use a Sun JRE when launching Eclipse. This is necessary because the build procedure to produce an deployment package for Android depends on a Sun-specific package: sun.security.x509.

At present I have not managed to find how to launch Rational Application Developer (RAD) under a Sun JRE and hence I do not use RAD as my Android development environment.

Project Set Up

The tech preview includes a number of sample applications delivered in the form of eclipse project directories. The application build tools make certain assumptions about project structure, that structure is most easily created by using Android-specific project creation options.

If you use a default Java project structure then your application will appear to build correctly but you will get an exception of this form:

10-31 16:28:53.982: E/AndroidRuntime(1200): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.ibm.mobile.dojoshowcase/ com.ibm.mobile.dojoshowcase.DojoShowcase}: java.lang.ClassNotFoundException: com.ibm.mobile.dojoshowcase.DojoShowcase

So, use the following approach.

Import As An Android Project

In Eclipse select File->New->Other->Android->Android Project

image

Click Next and select Create project from existing source, and browse to the location of one the of sample projects, for example

image

You may see an error

    An Eclipse project already exists in this directory.
    Consider using File > Import > Existing Project instead.

It is important that you do not follow this advice! The File->Import option does not yield a correctly structured project.

Instead, in Windows Explorer, browse to that project directory and delete the .project file (do not delete the .classpath file) and retry creating the Android project, which will now succeed.

Click Next and select your chosen Build Target. By default the samples target Android 4, but so far I’ve been using Android 2.2

image

Click Next again and you will see that the project’s AndroidManifest.xml has been understood.

image

Your project should now build cleanly. On some occasions I’ve seen compilation errors

   Syntax error, annotations are only available if source level is 1.5 or greater  

Despite the fact that the workspace is set up to use Java 1.6. To fix this, select your project, rightClick->Properties->Java Compiler, check the “Enable Project-Specific Settings” option, choose some different compiler level and click OK. This forces rebuild. Then repeat the process reverting to having “Enable Project-Specific Settings” unchecked. I would have expected a project clean or a rebuild to be as effective, but this recipe is the one that worked for me.

Running the Application

To run the project in the emulator, select the Project, rightClick->Run As->Android Application

This will launch the appropriate emulator, package the applications, deploy it to the emulator and initiate it.

image

A couple of notes about this process

Startup Time

The emulator takes a considerable time to start (on my laptop over 5 minutes). It’s reassuring to watch the logs so that you can see progress. In Eclipse, Window->Show View->LogCat.

image

You should also open the Console view when you get to the stage of deploying the application.

Increase Timeout

You may also see an error of this form

11-02 20:30:02.950: I/System.out(391): onReceivedError: Error code=-6 Description=The connection to the server was unsuccessful. URL= file:///android_asset/www/demosite/demos/mobileGallery/demo.html

This is actually due to the emulator taking too long to retrieve the file. You can increase the timeout by adding a line of code to the application.

image

Set the loadUrlTimeoutValue by adding the code shown below

        super.onCreate(savedInstanceState);
        this.setIntegerProperty("loadUrlTimeoutValue", 70000);
        super.loadUrl(“file:///android_asset //etc

With that in place the sample ran correctly, if slowly.