JavaFX + Android + Live Preview

Post to Twitter

We had a lot of fun this week - with JavaFX :)

My last article was about JavaFX on mobile devices with JavaFXPorts. It was awesome that JavaFX worked without bigger problems on mobile devices but the number of needed re-deployments was high. The app build process needs some time (~2-3 mins) and if you do a lot of UI related changes in your application (CSS, layout, ...) you lose development time.

How to save deployment time?

Simply don't deploy!

We have our product VisionX and it has a Live Preview for applications while developing. Our idea was that we could use the existing functionality to show changes on mobile devices immediately. It should work with Android devices because dynamic class loading is possible with custom classloaders.

But as so often, things won't work as expected.

Android has support for URLClassLoader but it doesn't work because the implementation is "legacy" . This means that loading classes with URLClassLoader didn't work. Android has a DexClassLoader!

The DexClassLoader works great if you have the archive on the device. But it has no support for remote class loading. The other thing was that DexClassLoader needs a jar that contains a classes.dex archive. The classes.dex contains all class files (in dex format).

The first problem was: How to create the DEX archive?

Not too hard because Android comes with dx.bat and dx.jar. It's super easy to convert a jar file or a classes folder to a dex archive. After the hardest part was solved, it was simple to implement remote class loading with Android, for our JavaFX application! If you need more information, leave a comment!

Here's the result of our Live Preview experiment as Video:

Window shutter web control

It works great and reduces deployments to a bare minimum: 1

8 Responses to “JavaFX + Android + Live Preview”

  1. Hiran says:

    woow, that was soo impressive.

  2. Vinayaka says:

    Sir can you please explain me to convert javafx .jar to android .apk. am new to javafx and while converting am getting like following:
    :dex FAILED
    Execution failed for task ':dex'.

    Please help me out to resolve this error.

  3. rjahn says:

    Please read: http://docs.gluonhq.com/javafxports/#_getting_started and chapter Prerequisites. If you have problems with Gluon Plugin, please us their support forum: http://gluonhq.com/forums/forum/javafxports/

    Hint: Start from scratch with a simple Hello World application and follow the instructions, e.g. don't use another JDK version or plugin version - double check!

  4. Vinayaka says:

    >>Please read: http://docs.gluonhq.com/javafxports/#_getting_started and chapter Prerequisites. If you have problems with Gluon Plugin, please us their support forum: http://gluonhq.com/forums/forum/javafxports/

    Hint: Start from scratch with a simple Hello World application and follow the instructions, e.g. don't use another JDK version or plugin version - double check!

    Thank you for your reply sir. sir i followed that one only but it giving Dex error sir. i'll get build failed error on every time sir.

  5. rjahn says:

    Please us the GLUON support forum: http://gluonhq.com/forums/forum/javafxports/
    or the google group: https://groups.google.com/forum/#!forum/javafxports

    Be sure that dex is available in your Android SDK...

  6. Vinayaka says:

    Sir can you please explain little bit. is there any system settings should i do before running. please tell me about it sir.

  7. Vinayaka says:

    sir in my SDK, dex is available and its the latest version SDK too

  8. rjahn says:

    Sorry Vinayaka, but this blog isn't the right place for GLUON plugin problems, so please ask the plugin developers.
    They'll certainly help.

Leave a Reply

Spam protection by WP Captcha-Free