JavaFX and Android
JavaFX and Android
Join the DZone community and get the full member experience.Join For Free
Java-based (JDBC) data connectivity to SaaS, NoSQL, and Big Data. Download Now.
I think we can consider JavaFX to be stable on the desktop, and that is a very important fact. However, the client-side in the IT industry in general is shifting from desktop to mobile. Platforms need to have an answer for this. That is why I started a community project for porting JavaFX to the Android platform a couple of months ago.
When JavaFX 2 was announced, many developers and analysts said its success would be dependent on the ability to run JavaFX applications on mobile platforms. Today, we see that Oracle has done a great job in making JavaFX available on all major desktop systems (Windows, MacOS and Linux) and on embedded systems. The mobile area, including phones and tables, however, is not covered by Oracle. As far as I'm aware, there is no official explanation from Oracle on why mobile platforms are not (yet) officially supported. I'm not happy with that decision, but complaining about it is not going to help.
Developers are usually better in doing it themselves than in complaining. With the JavaFX code being open sourced over the past years, and with lots of work already being done by Oracle people, a community-effort for porting JavaFX to mobile platforms turned out to be a viable option.
I have some experience in porting efforts, as I was part of the Blackdown team porting Java to Linux. One of the things I learned is that the community has the power to drive innovation. Big companies might jump into the area later, and I am very ok with that. The Blackdown team became rather obsolete once Sun Microsystems started to invest in Java on Linux itself, and that was a nice way to become obsolete.
Since RoboVM is already doing great work on the JavaFX iOS port (see http://www.robovm.org and consider becoming a sponsor!), I decided to focus on the Android port. I talked with JavaFX architect Richard Bair during Devoxx, and got a jump-start thanks to Tomas Brandalik who already did lots of work on the native parts and Stefan Fuchs who maintained the Java 7 backport. After only a few weeks, we delivered a JavaFX Runtime for the Android platform.
The JavaFX Android community project is hosted at https://bitbucket.org/javafxports/android/wiki/Home and it contains instructions on how to run JavaFX applications on Android. The code is currently available at https://bitbucket.org/javafxports/android-graphics-rt . This repository is a mirror of the openjfx-8-graphics repository that is used to build the main JavaFX 8 code. Based on this code, a JavaFX Android runtime is created and available for download at https://bitbucket.org/javafxports/android/downloads/dalvik-sdk-b4.zip . Note that we changed the name of the download from android-sdk to dalvik-sdk, as our port relies on Dalvik (which is available on Android devices) and not on a separate JVM. The latter would be possible as well, and some work has been done in this area, but unfortunately there is no open-source JVM that is close enough to be usable right now.
With dalvik-sdk-b4, and with the instructions athttps://bitbucket.org/javafxports/android/wiki/Building%20and%20deploying%20JavaFX%20Applications, we reached a milestone. Most of the JavaFX 8 Ensemble applications are now working out of the box on Android devices. I've seen many reports from JavaFX developers demonstrating their applications on Android, which is very cool.
I think we proved that there is room for JavaFX on Android devices. I know at least a few companies that are considering JavaFX partially base their decision on whether or not their application will run on Android and iOS. I think both RoboVM and our Android community effort show that it is very well possible to run JavaFX applications on mobile devices.
Going forward, there are a number of challenges that need to be addressed. Currently, only applications compiled with Java 7 can be deployed on Android. Lambdas, Streams and Defender Methods are not yet supported. Also, the tools need to improve. Currently, we provide a gradle script that generates an ant-project that allows your javafx application to be packaged into an .apk bundle, which can then be deployed on an Android device -- or, in the end, uploaded to the Play store. Integration with leading IDE's would be extremely helpful to developers.
At the same time, the main JavaFX development is no longer happening in the openjfx-8-graphics repository that we use as the upstream repository. A new repository is created, and this seems like a good moment to try to merge our changes back into the main repository. Clearly, there are a number of challenges we encounter, but I don't think there is a real show-stopper. For example, we are investigating RetroLambda for allowing the use of Lambda code.
The JavaFX port for Android has been an interesting project so far, and I'm really excited to see videos and screenshots from people who got their applications working on Android. Keep them coming!
Published at DZone with permission of Johan Vos , DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.