Port JavaFX application fo Android APK, with javafxports

javafxports provide tools to build a Java(FX) runtime for Android devices. You can follow the instructions to port JavaFX Application to Android APK.

Here show how to port JavaFX Hello World to Android APK, on Ubuntu.

JavaFXAndroid
- It's assumed Android SDK is install on your system, at /home/eric/Android in my case.

- Gradle is need to create Android project from JavaFX application. To install Gradle (currently 1.4) on Ubuntu, run the command:
$ sudo apt-get install gradle


- You need a JavaFX-Dalvik Runtime. You can either download it here (easy) or build this yourself (less trivial). Always download the latest version of the runtime: dalvik-sdk-latest. /home/eric/dalvik-sdk in my case.


- Create a JavaFX Hello World project compiled with Java 7. To specify compiled with Java 7 in Netbeans, click File (or right click the project), -> Project Properties, select Category of Sources, select Source/Binary Format of JDK 7.


- To run Gradle to generate Android project, and ant to generate APK, the following environment setting have to be set.

path to Android SDK:
$ export ANDROID_SDK=/home/eric/Android/sdk
$ export PATH=$ANDROID_SDK/tools:$ANDROID_SDK/platform-tools:$PATH

Android and Java Home:
$ export ANDROID_HOME=/home/eric/Android/sdk
$ export JAVA_HOME=/home/eric/jdk1.8.0_20

- Switch to /home/eric/dalvik-sdk/android-tools, run the command to generate Android Project:

gradle -PDEBUG -PDIR=/home/eric/JavaFXAndroid -PNAME=JavaFXAndroid -PPACKAGE=com.JavaFXAndroid -PJFX_SDK=/home/eric/dalvik-sdk -PJFX_APP=/home/eric/NetBeansProjects/com.JavaFXAndroid/dist -PJFX_MAIN=com.javafxandroid.ComJavaFXAndroid -PANDROID_SDK=/home/eric/Android/sdk createProject

Where:

DIR=/home/eric/JavaFXAndroid - the output directory.
NAME=JavaFXAndroid - Name of the target Android project.
PACKAGE=com.JavaFXAndroid - package name of Java application
JFX_SDK=/home/eric/dalvik-sdk - location of downloaded JavaFX-Dalvik Runtime.
JFX_APP=/home/eric/NetBeansProjects/com.JavaFXAndroid/dist - The location of the Netbeans JavaFX project.
JFX_MAIN=com.javafxandroid.ComJavaFXAndroid - fully name of the main class of your JavaFX Application
ANDROID_SDK=/home/eric/Android/sdk createProject - location of your Android SDK.

Once successfully finished, switch to the the directory of the generated Android Project,  /home/eric/JavaFXAndroid/JavaFXAndroid in my case.

Run the command to generate the APK in its bin directory.
$ ant debug

Then you can run the adb command in bin directory to install the APK to real Android devices.
$ adb install -r -debug.apk


Run the ported Android app on real device: