Launch JavaFX application with external libraries in Android?

I just developed a JavaFx application that uses the RXTX library for serial communication, and will use Bluecove for bluetooth in the future. I realized that there are some ways to run a JavaFx application on Android devices, so I started my research.

The first option was the jar application with the Java Manager Android application. The problem here is that I do not know what to do with external libraries, since there is no standard JVM device on Android devices where I could host them. I found this project http://v-lad.org/projects/gnu.io.android/ ", but it seems to be targeting Android apps.

So, when I found " http://javafxports.org/ , I tried to take the first steps with it. This project seems to be needed for me, but I'm new to Android and I find the documentation a bit confusing, so I'm not sure with where to start.Moreover, I'm still not sure that I could use these java libraries in Android with this approach.

Does anyone know if what I am doing is doable? In this case, what steps should be followed?

+6
source share
1 answer

You can already try the JavaFXPorts plugin. It is in continuous development, but the latest versions are mature enough to use it without problems.

Take a look at the basic requirements to start here . You will need the JDK8u40 +, Gradle 2.2+, Android SDK and Android Build tools.

Once you are ready, you can try samples .

I also suggest you take a look at the Gluon-plugin for NetBeans. Basically, this will create a new empty JavaFX project for you, and you can create and deploy it on your desktop, on Android and on iOS platforms.

Check out 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 latter: 1.0.0-b8.

Create and run on your desktop or run tasks such as androidInstall to generate apk and deploy it on your Android mobile device.

After you have tested it and everything works correctly, you can start adding the code of your project.

And back to your question, yes, you can add any third-party bank to the project.

Basically you just need to add a 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 that you can add dependencies that are added to only one platform, for example androidCompile or androidRuntime .

Since apk will run on Dalvik VM, only Java 7 functions are allowed. You can use lambdas, though, since the plugin uses the Retrolambda project inside your code. Keep in mind that it does not apply to added jars.

As an example of using banners in your project, you can use the open-source library Gluon-Charm-Down, which already provides access to some native services on your device, for example, 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 the jfxmobile plugin and this library, the 2048FX game was successfully ported to Android ( Google Play ) and iOS ( Apple Store ).

+3
source

Source: https://habr.com/ru/post/987031/


All Articles