简体   繁体   中英

JavaFX on Android - Gradle can't find JDK

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:

在此处输入图片说明

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).

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM