Hecl and Android

Android Hecl Quick Start

As of mid-2008, Hecl runs on Google's Android platform, although it's not yet a 'mature' port. That's ok right now, though, because Android isn't production ready yet, either.

Due to a different GUI model, a very extensive API, and a much more complete implementation of Java [1] Hecl on Android takes a different approach: the Android version of Hecl includes a java command, and introspection capabilities in order to be able to dynamically create Hecl commands that call out to native Java calls.

Android Hecl Quick Start

Developing for Android Hecl is quite similar to Java ME development, with the same cycle of editing a script, creating an application bundle, and testing it in an emulator.

  1. To work with Android, of course the first thing you need to do is to get the SDK from Google: http://code.google.com/android/download.html. On my system, I installed it in here: /opt/android-sdk/.

  2. Next, edit android/android.properties to point to the SDK, and the tools it needs to work (usually the tools directory within the SDK directory).

  3. As with Java ME Hecl, you need a script file to work with. Here's a "hello world":

    set context [activity]
    set layout [linearlayout -new $context]
    $layout setorientation VERTICAL
    set layoutparams [linearlayoutparams -new {FILL_PARENT WRAP_CONTENT}]
    set tv [textview -new $context -text {Hello World} \
                     -layoutparams $layoutparams]
    $layout addview $tv
    [activity] setcontentview $layout

    To see more code, have a look at android/res/raw/script.hcl, which has examples of many different widgets.

  4. You won't need it right away, but you might as well start the emulator:

    /opt/android-sdk/tools/emulator -avd your_avd

    You need to create an "AVD" before launching the emulator. This is documented here: http://developer.android.com/guide/developing/tools/emulator.html#avds

  5. Now we create the new Hello.apk file.

    java -jar ./hecl/jars/AndroidBuilder.jar -android \
        /opt/android-sdk/platforms/android-1.5/ -class Hello \
        -label Hello -package hello.world \
        -script hello.hcl

    It's important to point out that the directory used with the -android option is a subdirectory of the SDK: /opt/android-sdk/platforms/android-1.5/, rather than the top level.

    The command line options are as follows:

    -android: The location of the Android SDK.
    -class: The class name to utilize for the new .apk.
    -label: The user-visible name of the package.
    -package: The Java package to use. You can pretty much use any name you like, it doesn't matter much.
    -script: The location of the script you want to use in the new .apk.
  6. We now have a Hecl.apk file. We need to sign it with the debug key:

    keytool -genkeypair -keystore debug.keystore \
        -keypass android -alias androiddebugkey -storepass android \
        -dname "CN=Android Debug,O=Android,C=US"

    jarsigner -keystore debug.keystore -keypass android \
        -storepass android -verbose Hello.apk androiddebugkey

  7. At this piont, we can send the signed file, Hello.apk to the emulator:

    /opt/android-sdk_m5-rc15_linux-x86/tools/adb install Hello.apk

[1] Android doesn't actually run Java, it just compiles code written in Java into bytecodes for the Dalvik engine.