Converting Javafx application jar file to apk files (Netbeans)

Ethyl Casin picture Ethyl Casin · Feb 11, 2015 · Viewed 8.8k times · Source

Is there a facility in netbeans that will automate the conversion of javafx jar file into apk files?

Answer

José Pereda picture José Pereda · Feb 11, 2015

Actually, there is a way to create an Android application (apk) from a JavaFX application, based on the JavaFXPorts project.

Recently, a new plugin has been released, so you can just 'drop it' on your JavaFX project and build the apk.

Have a look at the 'getting started' guide. Basically, considering you are using NetBeans, you will need:

  • JDK8u40 early access release installed, JAVA_HOME should be set with the JDK path.
  • Gradle 2.2.1 installed
  • Android SDK
  • Android Build Tools 21.1.1 using SDK Manager.
  • Gradle Plugin for NetBeans (optional)
  • And the plugin which is a 'build.gradle' file

It looks like this:

buildscript {
    repositories {
        jcenter()
        }

    dependencies {
        classpath 'org.javafxports:javafxmobile-plugin:1.0.0-rc3'
    }
}

apply plugin: 'javafxmobile'

mainClassName='org.javafxports.android.MainJavaFX'

repositories {
    jcenter()
}

jfxmobile {
    android {
        applicationPackage = 'org.javafxports.android'
    }
}

I suggest you try the Ensemble 8 project, clone the project, and see for yourself how easy it is to port this application to Android.

You can create new projects with the Gradle plugin, then add a JavaFX project, add the plugin, and it will create the apk as easy as:

gradlew android

Or you can use any existing JavaFX project with this build.gradle file.

Important considerations

The plugin works with the last JDK8 8u40, but it doesn't support all Java 8 features (Streams and Optional), while it supports Lambdas. On the contrary, it supports mainly all the JavaFX 8 features.

It's in working progress, so some issues may not been solved yet.