IBM Mobile Technology Preview –Getting Started

November 2, 2011

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.

About these ads

One Response to “IBM Mobile Technology Preview –Getting Started”

  1. […] 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 […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: