You can already try JavaFXPorts plugin. It's in continuos development, but the recent versions are mature enough to use it without problems.
Have a look at the basic requirements to get started here. You will need JDK8u40+, Gradle 2.2+, Android SDK and Android Build tools.
Once you have everything ready, you can try the samples.
Also I suggest you have a look at Gluon-plugin for NetBeans. Basically it will create a new empty JavaFX project for you, and you will be able to build it and deploy it on your desktop, on Android and on iOS platforms.
Have a look at the build.gradle
file:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.javafxports:jfxmobile-plugin:1.0.0-b4'
}
}
apply plugin: 'org.javafxports.jfxmobile'
repositories {
jcenter()
}
mainClassName = 'org.test.javafxports.TestJavaFX'
jfxmobile {
ios {
forceLinkClasses = [ 'org.test.javafxports.**.*' ]
}
}
First of all, you just need to update the plugin version. Check here for the last one: 1.0.0-b8.
Build and run on your desktop, or run the tasks like androidInstall to generate the apk and deploy it on your Android mobile.
Once you have tested it, and everything is working properly, you can start adding the code of your project.
And back to your question, yes, you can add any third party jar to the project.
Basically you just need to add the dependency on the gradle file. You can use compile
or runtime
with local files or from external repositories:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.javafxports:jfxmobile-plugin:1.0.0-b8'
}
}
apply plugin: 'org.javafxports.jfxmobile'
repositories {
jcenter()
}
dependencies {
compile files('lib/<your local jar>.jar')
compile 'org.glassfish:javax.json:1.0.4'
androidCompile 'org.glassfish:javax.json:1.0.4'
}
mainClassName = 'org.test.javafxports.TestJavaFX'
jfxmobile {
ios {
forceLinkClasses = [ 'org.test.javafxports.**.*' ]
}
}
Note you can add dependencies that only are added to one single platform, like androidCompile
or androidRuntime
.
Since the apk will run on Dalvik VM, only Java 7 features are allowed. You can use lambdas, though, since the plugin uses Retrolambda project internally on your code. Be aware that it is not applied on the added jars.
As an example of using jars on your project, you can use Gluon-Charm-Down open source library, that already provides access to some native services on your device, like local storage or GPS.
dependencies {
compile 'com.gluonhq:charm-down-common:0.0.1'
androidRuntime 'com.gluonhq:charm-down-android:0.0.1'
desktopRuntime 'com.gluonhq:charm-down-desktop:0.0.1'
}
In fact, with jfxmobile plugin and this library, the 2048FX game has been successfully ported to Android (Google Play) and iOS (Apple Store).