0

I'm trying to get JavaFX applications to run on Android by using the Dalvik JavaFX-Android SDK (provided by the JavaFX Android porting team). So I downloaded the samples provided by the JavaFX Android porting team and have been trying to run one of them on Android without much success.

Using Eclipse with the Gradle plugin I imported the "HelloWorldFxml" sample project. Then I ran the Gradle task "./gradlew androidInstall" on the project like the README file told me. But unfortunately the task cannot execute because Gradle cannot locate my JDK:


(source: forumbilder.se)

Even though my JAVA_HOME system variable is correctly set and I havn't had a problem with it before:


(source: forumbilder.se)

Anyone that can provide some insight as to how I can fix this?

Versions: Eclipse Luna Service Release 1a (4.4.1), Gradle 2.2, dalvik-sdk-8u40-ea3, Android SDK Build-tools 21.1.2, Android SDK Tools 24.0.2

Edit: The console output when running "gradlew androidinstall" on a sample project:

enter image description here

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Just some guy
  • 1,909
  • 4
  • 21
  • 32

4 Answers4

0

Even though the error message doesn't specify it, maybe it's looking for javac in your PATH? In case it's not in there try adding ;%JAVA_HOME%\bin to the end of your PATH variable (and restart Eclipse afterwards, I've had the problem of running processes not getting changes to environment variables before).

kjosh
  • 587
  • 4
  • 11
0

Basic Note

Since the release of dalvik-sdk-8u40-ea3, and in very short time, the JavaFXPorts team has released a few new versions, all of them simplifying all the process of porting a JavaFX application to Android or iOS.

They released dalvik-sdk-8u40-ea4 and they announced the release of a new plugin, that will simplify to the minimum the steps to create a mobile application from JavaFX.

While this answer may not help the OP in his particular problem, definitely it will help him and others, since everything is really simplified.

New approach

With this plugin, there's a new way of creating the HelloWorldFxml application for Android.

The new javafxmobile-plugin allows you to generate the apk with a single 'build.gradle' file.

You can find this an other basic samples here, and download the repository here.

You won't need to edit a single line, just type this on the command line, on the root of the sample, with your device connected:

gradlew androidInstall

As for previous releases, you will need JDK8u40 and Android SDK installed. No need for dalvik-sdk though, it's retrieved by the plugin.

Notice that you can open these samples from your IDE, so you will be able to modify them, and run them locally or build again the apk for your device.

José Pereda
  • 44,311
  • 7
  • 104
  • 132
  • I'm not sure this answers the question - maybe you can clarify why you think it does? – Jolta Feb 17 '15 at 22:48
  • @Jolta Edited my answer. Many problems from previous releases are solved with this new plugin, as I've already tested myself. – José Pereda Feb 17 '15 at 22:59
  • This new approach sounds like what I'm doing, just downloading the sample and then running the "gradlew androidinstall" task on it. It's working now though, but only in Eclipse and not using the command line like I mention in another comment. The next thing I want to do now is create my own JavaFX Gradle projects; should I copy my code into a sample project or how do I do this? Yes, I'm not very experienced with these things, and I'm not finding a whole lot of documentation or tutorials. – Just some guy Feb 18 '15 at 13:38
  • Have you been able to build/install the apk? If you run from Eclipse you are running a desktop version. You need to do it from command line, so you can build and install the apk. Once you've done this you can create your own samples. First I suggest you modify the code of one of them, and then try for yourself. It depends on the Gradle plugin for the IDE... – José Pereda Feb 18 '15 at 13:43
  • I connect my phone, run the "androidinstall" task and the app gets installed on my phone. Is that equivalent to "building/installing the apk"? – Just some guy Feb 18 '15 at 14:16
  • Yes, first is built in your system with all the tools you have installed, and finally it's transfered to the device. If the app runs fine also, that means you are done successfully all the process. – José Pereda Feb 18 '15 at 14:19
  • Now I tried importing another of the sample projects into Eclipse and run the "androidinstall" task on it, and it's giving me that same error I posted a picture of above. So now I have two of the sample projects in Eclipse, and one of them runs fine when I try to install it on my phone, while the other can't find my JDK. What's happening? :( – Just some guy Feb 18 '15 at 16:49
  • I can't tell without further details. Could you post the console logs when running the task from the commnad line? – José Pereda Feb 18 '15 at 17:17
0

Check the Java setting in Eclipse:

Window -> Preferences
Java -> Installed JREs

Make sure that your JDK 1.8 is listed there. If it's not, add it using the Add... button.

Once the JDK is known to Eclipse, make sure that your project's settings use that JDK as a compiler, and the Gradle plugin should be able to pick up the setting from there.

In a pinch, you should also be able to run Gradle from the command line, and it should work fine since you already set the %JAVA_HOME% variable.

Jolta
  • 2,620
  • 1
  • 29
  • 42
  • You mean JRE, right? I don't think you can list your JDK under "installed JREs" in Eclipse. But anyway, today Gradle accepts my JAVA_HOME variable and I can execute the task successfully in Eclipse, even though I havn't changed it since yesterday. But if I try to execute the same task from the command line I have to remove the ";%JAVA_HOME%\bin" part or else it claims JAVA_HOME is set to an invalid directory. It's rather confusing. – Just some guy Feb 18 '15 at 13:27
  • I have listed my JDK under the "installed JREs" in Eclipse, so I'm sure it can be done. =) – Jolta Feb 18 '15 at 16:14
-1

Had this problem, too.
My proberties:

-Windows 7
-Dalvik SDK (dalvik-sdk-8u60-b5)
-JDK 8 (newest Version 8_60 / IMPORTANT: JDK not JRE)
-And I tried also the HelloAndroid project provided by the Dalvik-SDK-download.


So i execute the command line: gradlew installDebug
My probelm was nearly the same. "Fail to find JDK. Please make sure there is a JAVA_HOME or JAVA8_HOME systemvariable."

#1
Created these proberties. Just like described in this post:
How to set java_home on Windows 7?
So to make everything sure, I created both with the same path. Cause I don't know exactly which one is used by gradle.

#2
This is really the hack that helps me out. Found this also in StackOverflow. Write in your build.gradle under the android{..} stuff this line:

  retrolambda {
     jdk 'C:/Program Files/Java/jdk1.8.0_60'              //<--your JDK-path
  }

it looks like that


Then execute the same command line again and it worked for me. I think only the 2. steps was the solution, cause I guess gradle don't look for the variable if there is a direct path to the jdk.

Community
  • 1
  • 1
  • @Peanut Read more carefully, this is a complete answer not a new question as it presents a solution that worked for the author. – runDOSrun Oct 13 '15 at 13:50
  • Lorenzo, the way you've worded your answer makes it sound a lot like a "I'm having this problem, too" comment, and your answer is getting flagged and showing up in the low-quality queue. Please consider re-wording your answer to make it more directly address the OP's question. (e.g. instead of "I also had this problem, I fixed it like this", say something like "you can fix your problem by doing this") – azurefrog Oct 13 '15 at 17:25
  • thanks @runDOSrun cause this should be an answer not a question. I solved the problem in my situation. – Lorenzo_Matterhorn Oct 13 '15 at 17:48