Developing hybrid applications for Android? Try mobile web tools in Rational Application Developer with Android Eclipse SDK
Jim Zhang 120000QGNC Comment (1) Visits (8406)
Note that the information provided here regarding using Rational Application Developer for hybrid development is not an officially supported scenario. In RAD 8.0.3 ifix1, only purely web-based mobile solutions are officially supported. However, as you will find out below, the existing tools do actually lend itself nicely to the hybrid development needs.
At the end of the install, you will be prompted to restart RAD. Click "Restart Later" to close the dialog. You should manually shut down RAD and restart it because an additional step must be preformed before RAD can be successfully started after the Android tools are installed. This additional step involves making the necessary changes to launch RAD with a Sun Java 1.6 JDK. The Android SDK requires a Sun-specific JCE provider in order to add the digital signature to the .apk during the build. This class is not included in IBM JDKs that come with RAD installs. To get around this problem RAD must be configured to launch with a Sun JDK. Replace the parameters in the eclipse.ini file, in the same folder as eclipse.exe, with the following:
Now you are ready to write some code! At a high level three types of code are typically developed for a hybrid solution. First, the bulk of the application should be written in web code, HTML
My suggestion is that you break this process into three steps:
1. Develop the web code using the full browser as the target environment. The environment in the full browser is almost identical to the embedded browser that gets packaged in the hybrid application, with some minor differences mainly in page load events. For instance, in full browsers dojo code is kicked off by the dojo.ready() event. When running in the native application, the code must be changed to listen to the DOM "deviceready" event which is fired by PhoneGap when it's fully loaded. More than 95% of the code should work the same way. The advantage of developing as much as possible in this environment is that with a fast and light-weight server, such as the Ajax Test Server, changes can easily be made and then quickly reloaded in the browser for instant testing. This saves the time of waiting for the build and sitting around until the emulator catches up. With the Mobile Browser Simulator you can get a sense of the look-and-feel of your UI in the target phone's specific form factor and in different orientations. In addition, using the Rich Page Editor (beta) you can easily put the UI together with markup. RAD also provides one-click publishing of your web projects onto the target server.
2. Develop the native code and PhoneGap code in the Android project. There's no need to go into details about native development here. For the PhoneGap part, the typical tasks are listed in the Getting Started guide. What about the web code? I suggest for this phase you keep the web code in its original web project, separate from the Android project, especially if the project contains a lot of code, taking into account any dependent libraries such as Dojo. Doing this saves time by avoiding lengthy builds.
And there's a specific reason for doing this if Dojo is used. If Dojo itself is put inside the Android project, it will not work due to a problem with the Android build tool. The problem is that all folders and files starting with "_" are not included in the .apk (htt
In order to get the web resources loaded into the native Android Application, built using the PhoneGap tools, you can use the PhoneGap API like this, in the Application class that extends DroidGap:
Note that the link can't be "localhost" because on the device emulator that maps to the device itself instead of the development machine that is running the emulator and webserver. Use the IP address for the development machine instead.
3. Move the necessary code into the Android project. Once the code is well tested both in the Mobile Browser Simulator (in step 1) and the emulator (in step 2), the web resources, including any libraries such as Dojo, can be moved into the Android project. If Dojo is used, a custom build needs to be produced for three reasons: 1) reduce size, 2) better performance, and 3) getting around the excluded resources problem (see step 2). This custom build can be created by using the Dojo Custom Build wizard provided in RAD. Make sure to thoroughly test the consolidated layers by continuing to load them with the http:// URL. After the custom layers have been well tested the web resources can be moved into the Android project.
Create a folder "www" inside the "assets" folder which should have been created by the Android project wizard. Then start moving the web resources into that folder. Because of the custom layers (large js files consolidating multiple dojo modules), most of the Dojo source files can be left behind. You should never copy the entire Dojo source tree into the Android project for the reasons already mentioned.
Finally, to start loading the web resources inside the Android package, change the Android application class to something like the following:
From this point on, all coding and testing is done exclusively in the Android development environment. Most of the web development tools are not supported in Android projects, except for the CSS editor and JSON editor which can continue to be used.
Although the current release of RAD does not claim support for hybrid development, it does offer value if a process such as the one described here is leveraged. From searching the Internet many have already started using Android Development Tools with Rational Application developer to develop in the hybrid model. Some have run into problems, and I hope this article will provide a method for solving these problems. Happy coding!