A summary of my lessons learned building a first, still simple, pure JavaFX Android
application based on the components of an already existing JavaFX application using
the Gluon Client Maven plugin which is based on the GraalVM
First of all I would like to thank the team at Gluon again which made all the following possible. Without their continuous, hard work it would not be possible at all to compile a modern JavaFX application into a native Android application. My thanks of course also include all the people involved in the GraalVM project which laid the foundation for the work done for JavaFX by Gluon.
This article summarizes the experiences which I collected while converting one of my existing Java applications to a native Android application using the Gluon Client Maven plugin. The application is still relatively small and manageable but otherwise a real-world application with a lot of external dependencies and technical challenges. It was not always an easy ride but in the end it worked out nicely.
This is the initial welcome screen which also serves the purpose of an about screen.
Two variants of this screen had to be provided so that it looks nice in portrait as well as in landscape mode. The switching between the two can then be done easily in standard JavaFX.
This is the normal map mode. You can navigate the map with the usual gestures (scroll, zoom and rotate).
The map display is written in pure JavaFx and is identical to the one used on desktop with the regular Java VM. For better performance it makes even use of some 3D features which also work nicely on Android.
Via the menu you can reach several other pages.
On this page you can activate tracking. It takes the position data from the built-in GPS and sends it via MQTT to a public MQTT-Server.
In this case I had to implement my own Position-Service because the existing one does not provide all the data I need, e.g., the precise time stamp and also speed and bearing. My service is just an extension of the existing one, so doing this was not a big deal.
The MQTT-Client is just the standard Eclipse Paho Client out of the box.
When you go back to the map while tracking is activated, the map will show an own-ship symbol and will be rotated according to the current bearing (track-up mode).
On the map settings page you can manage the locally installed maps and select one map as the current map. The image shows the view while it is just downloading the map for Austria. The colors of the progress bar indicate the status of the respective map. The load/unload buttons on the left are disabled while a download is running in the background.
This first, still relatively simple application already uses several external libraries which can all be used in their standard implementation right from the Maven repository. No special Android version is needed.
plus all the JavaFX-specific libraries from OpenJFX/Gluon
The build step still takes a long time. For this project, on my Intel NUC with Ubuntu 20.04, a build takes about 4-5 minutes. This isn’t nice but it also isn’t a big problem because you do not have to go through this all the time. I currently use a development style where I do all development and testing on my preferred platform (macOS) with the regular Java VM. This works because the GUI is all pure JavaFX and even the mobile specific controls work on desktop. Therefore you do not even need any emulator because you can just work in your preferred development environment. When I am ready with some funtionality I synchronize the NUC with the GIT repository and start a build for Android, so that I can test it on a real device.