Dev environment for JavaFX/Android development

332 views
Skip to first unread message

Esa Kylli

unread,
Dec 7, 2014, 11:36:31 AM12/7/14
to javafx...@googlegroups.com
I'm in the process of creating my first JavaFX app for Android where I want to use the Bluetooth API's of Android.
I was thinking of creating two projects: one "core" standard Java-project with the JavaFX GUI and attached logic + another Android-project with the necessary calls to Bluetooth API's, and then communication between these via interfaces.

I wanted to ask you how you have set up your dev environment when you want to use JavaFX together with Android API's?
I have previously used Netbeans for some JavaFX development (mostly just testing) and Eclipse/ADT for Android development.
But I would like to use only one IDE (if possible).

jo...@lodgon.com

unread,
Dec 7, 2014, 3:37:27 PM12/7/14
to javafx...@googlegroups.com
Hello,

I have successfully set up a multiproject using gradle. I have separated the code in three sub projects: core, android and desktop. Inside the android project, I am able to use android specific code, but not in the core and desktop project. You can have a look at the code here: https://bitbucket.org/tiainen/clt-forum-javafx/src. There's also an example of how to abstract away some things that would be done different on desktop and android by using the ServiceLoader.

As for my development environment, I currently use Netbeans together with two of the NBAndroid plugins: the Android plugin itself and the NBAndroid Gradle Support plugin. You can find out more about these plugins here: http://nbandroid.org/wiki/index.php/Installation.

Op zondag 7 december 2014 17:36:31 UTC+1 schreef Esa Kylli:

Esa Kylli

unread,
Dec 10, 2014, 4:51:48 AM12/10/14
to javafx...@googlegroups.com, jo...@lodgon.com
I installed the NBAndroid plugin and have created 3 projects (core, desktop, android) in Netbeans.
I got the desktop-project running with the help of ServiceLoader. Thanks for the example!

But I'm now struggling with the Android-project with the following issues (in Netbeans):
- I can't reference the core-project since only Android-projects can be referenced. I solved this (at least for compile-time?) by pointing out the built jar-file in the core's dist-folder. Is this right?
- If I want to use Android-api's requiring Context (for example Toast-messages) I don't know how to get that reference? I know you can get it from FXActivity but how do I get access to this class? Should I copy the necessary jar-files from the Dalvik SDK into the project's libs-folder?
- Would it be possible to do the other way round, starting with the Android-specific activity and getting it to load/launch the JavaFX GUI in the core-project?

I'm getting the feeling that I can't get the right project-structure in Netbeans, compared to how the example is setup with gradle-build....

Any pointers of how to make some progress with my issues are greatly appreciated!

Jörg Wille

unread,
Dec 10, 2014, 9:48:09 AM12/10/14
to javafx...@googlegroups.com, jo...@lodgon.com
The NBAndroid-Gradle plugin is based on the NetBeans Gradle Plugin, which I had installed before I installed NBAndroid-Gradle Plugin.
I just keep using the Netbeans Gradle Plugin Project Templates (New Project Wizard). As soon as I apply plugin 'android' in build.gradle and
have AndroidManifest in place, Netbeans automatically "changes" project to android project, which can use Android-api.
But all other gradle project hierarchy keeps working.
Joerg

Esa Kylli

unread,
Dec 17, 2014, 2:35:29 PM12/17/14
to javafx...@googlegroups.com
OK, I have made some progress now.
I installed the gradle plugin's in Netbeans and copied the project-structure from MultiProject (from javafxports/samples).
Then I applied the ServiceLocator pattern from the first example (mentioned by Johan earlier in this thread).

I have gotten the desktop-part to work and almost the android-part... I get the GUI displayed and when I touch it I get into my class in the Android-project, in there I make this call to Android-API:
Toast.makeText(FXActivity.getInstance(), "[my message]", Toast.LENGTH_SHORT);

When this is called I get the following stack-trace:
E/AndroidRuntime(10926): java.lang.RuntimeException: Can't create handler inside
 thread that has not called Looper.prepare()
E/AndroidRuntime(10926):        at android.os.Handler.<init>(Handler.java:200)
E/AndroidRuntime(10926):        at android.os.Handler.<init>(Handler.java:114)
E/AndroidRuntime(10926):        at android.widget.Toast$TN.<init>(Toast.java:336
)
E/AndroidRuntime(10926):        at android.widget.Toast.<init>(Toast.java:100)
E/AndroidRuntime(10926):        at android.widget.Toast.makeText(Toast.java:250)

Any ideas of what's going on here? Have I used the FXActivity in the right way?

jo...@lodgon.com

unread,
Dec 18, 2014, 3:56:21 AM12/18/14
to javafx...@googlegroups.com
I believe the reason for this, is that the JavaFX main thread is running on a different thread than the android application thread. You can only directly create a Toast message from within the main android thread. To create a Toast message from a different thread, use the Activity.runOnUiThread method: http://developer.android.com/reference/android/app/Activity.html#runOnUiThread(java.lang.Runnable). In the JavaFX case it would be something like:

FXActivity.getInstance().runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(FXActivity.getInstance(), "[my message]", Toast.LENGTH_SHORT).show();
}
});


Since the latest JavaFX on android builds are based on JDK 8u40, I believe you could also try and use the new JavaFX dialogs API: http://code.makery.ch/blog/javafx-dialogs-official/? I have not tried this yet, so I don't know if it will work, but it might be something to consider.


Op woensdag 17 december 2014 20:35:29 UTC+1 schreef Esa Kylli:

dav...@yahoo.it

unread,
Dec 18, 2014, 5:24:49 AM12/18/14
to javafx...@googlegroups.com, jo...@lodgon.com
About the JavaFX dialogs API, I just tried to add a simple Alert to the HelloWorld sample and I get a compilation error because the java.util.Optional class cannot be found.
Should it be added to the compat jar?

Esa Kylli

unread,
Dec 21, 2014, 11:57:13 AM12/21/14
to javafx...@googlegroups.com
It was indeed a thread problem, changing to runOnUiThread() fixed it. Thanks!

The back-button still doesn't exit the app (I'm using ea3). Is there a fix in the pipeline?

I have also a strange problem inside Netbeans, it reports compile-errors on all my classes (in all 3 projects).
In the core-project it says "duplicate class" (for all classes) and in the desktop and android-project it can't find my interface defined in the core-project.
The Gradle tasks run however just fine.
Any idea of what might cause this?


Den söndagen den 7:e december 2014 kl. 17:36:31 UTC+1 skrev Esa Kylli:

gza...@gmail.com

unread,
Dec 22, 2014, 4:59:33 AM12/22/14
to javafx...@googlegroups.com
Hello, maybe there is a simpler method but I use this:

1) in start() method:
            scene.addEventHandler(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>() {

               
@Override
               
public void handle(final KeyEvent event) {

                   
if (event.getCode().equals(KeyCode.ESCAPE)) {

                       
CtrMain.getInstance().close();
                   
}
               
}
           
});

2) in CtrMain method close():
    public void close() {

       
Main.runAndWait(new Runnable() {

           
@Override
           
public void run() {

                stage
.hide();
           
}
       
});
   
}

3) in CtrMain you have to remember your Stage in a variable that you set after creating the stage


Stefan Fuchs

unread,
Jan 5, 2015, 1:09:23 PM1/5/15
to dav...@yahoo.it, javafx...@googlegroups.com, jo...@lodgon.com
Hi,

I managed to configure my javafxports eclipse workspace to compile
against android.jar and our compat.jar. So no jdk classes are involved.
This uncovered some compile problems including the problem mentioned
below. All of this should be fixed now in the source repository.

I updated the Ensemble8 sample app as well. The latest version includes
some samples that use the new dialogs API.
The new version however has some issues:
1. SoftwareKeyboard does not open. A NPE is thrown, when the view is
closed.
2. Multitouch does not work (8u20 version was fine)

Stefan

Johan Vos

unread,
Jan 9, 2015, 2:24:44 PM1/9/15
to javafx...@googlegroups.com, dav...@yahoo.it, jo...@lodgon.com
Hi Stefan,

How do you build the ensemble app now? The gradle/ant mix in OpenJFX makes it a bit confusing to me... ;)

- Johan

Jörg Wille

unread,
Jan 9, 2015, 3:05:18 PM1/9/15
to javafx...@googlegroups.com, dav...@yahoo.it, jo...@lodgon.com
Hi Johan,
I just have build the ensemble app as a regular gradle build and tried it on device. Just works!

Johan Vos

unread,
Jan 9, 2015, 3:12:15 PM1/9/15
to Jörg Wille, javafx...@googlegroups.com, Davide Sessi, Joeri Sykora
Nice.
What about the MultiTouch sample? It is working for me, but apparently not for Stefan?

Thanks,

- Johan

--
You received this message because you are subscribed to the Google Groups "JavaFXAndroid" group.
To unsubscribe from this group and stop receiving emails from it, send an email to javafxandroi...@googlegroups.com.
To post to this group, send email to javafx...@googlegroups.com.
Visit this group at http://groups.google.com/group/javafxandroid.
To view this discussion on the web visit https://groups.google.com/d/msgid/javafxandroid/5d5acf1b-976a-4035-998b-5882508dca89%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jörg Wille

unread,
Jan 9, 2015, 3:21:38 PM1/9/15
to javafx...@googlegroups.com, joerg...@gmail.com, dav...@yahoo.it, jo...@lodgon.com
The MultiTouch example (with the 3 animals) is not working for me as well.
I can move the pictures but cannot rotate or size them with 2-finger-gestures.
Nor is the gesture example working as expected.

Jörg

Johan Vos

unread,
Jan 9, 2015, 3:24:20 PM1/9/15
to Jörg Wille, javafx...@googlegroups.com, Davide Sessi, Joeri Sykora
Strange, it works fine for me. But I did some tricks to build it from the source, so I'm wondering how exactly you have built it? From the OpenJFX source?

- Johan

Stefan Fuchs

unread,
Jan 9, 2015, 5:19:08 PM1/9/15
to Johan Vos, javafx...@googlegroups.com, dav...@yahoo.it, jo...@lodgon.com
Hi Johan,

it should be quite straight forward. You should be able to build the Ensemble8.jar by executing "gradle apps" with the same parameters as you would use to build the sdk.
This will build Ensemble8.jar after the sdk and put it into /samples/Ensemble8/dist

I have still two minor uncommited changes though:
1. Remove unused import of java.awt.Color in ensemble.samples.language.fxml.LoginController line 35 -> Upstream bug
2. Comment line 143 in ensemble.compiletime.search.DocumentationIndexer -> usage of new files api in exception handling code

You can now replace Ensemble8.jar in  8u-dev-build/samples/Ensemble8/ensemble/ and execute gradle installDebug

Stefan


--
You received this message because you are subscribed to the Google Groups "JavaFXAndroid" group.
To unsubscribe from this group and stop receiving emails from it, send an email to javafxandroi...@googlegroups.com.
To post to this group, send email to javafx...@googlegroups.com.
Visit this group at http://groups.google.com/group/javafxandroid.

davebaol

unread,
Jan 14, 2015, 11:28:12 AM1/14/15
to javafx...@googlegroups.com, johan...@gmail.com, dav...@yahoo.it, jo...@lodgon.com
I can confirm multitouch issue. Also looks like screen rotation makes the app crash.

Stefan Fuchs

unread,
Jan 14, 2015, 5:30:46 PM1/14/15
to javafx...@googlegroups.com
Perhaps it does not work, because of https://javafx-jira.kenai.com/browse/RT-37476 .

'davebaol' via JavaFXAndroid wrote:

Johan Vos

unread,
Jan 15, 2015, 9:08:16 AM1/15/15
to javafx...@googlegroups.com, johan...@gmail.com, dav...@yahoo.it, jo...@lodgon.com
When I use the Ensemble8.jar that is in our 8u-dev-build repository, it works fine.
When I build the Ensemble app from 8u40-rt/samples, it works but not smooth and it picks the wrong touch points.
Interesting, I'll try to look deeper into this tomorrow.

- Johan
To unsubscribe from this group and stop receiving emails from it, send an email to javafxandroid+unsubscribe@googlegroups.com.

Johan Vos

unread,
Jan 15, 2015, 3:49:56 PM1/15/15
to javafx...@googlegroups.com, johan...@gmail.com, dav...@yahoo.it, jo...@lodgon.com
Ah, I should read messages better. I was building the Ensemble with the old ant system. When using the gradle build, the multitouch failed as well. I noticed the javafx.platform.properties in the assets directory did not contain the 

com.sun.javafx.gestures.zoom=true

and similar properties, hence gesture support was disabled. I added those properties, so I think it might work now?

- Johan

davebaol

unread,
Jan 15, 2015, 4:34:13 PM1/15/15
to javafx...@googlegroups.com, johan...@gmail.com, dav...@yahoo.it, jo...@lodgon.com
Good catch, Johan. I can confirm that now zoom and rotate are working properly. :)
Not sure how to test scroll, though.
To unsubscribe from this group and stop receiving emails from it, send an email to javafxandroi...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages