I try to run a simple JavaFX application on Android. Therefore I read the javafxports Getting Started Guide using gradle to build the app, but I got stuck somewhere. I'm able to build and install the app on an Android device using the installDebug
task of gradle within Eclipse, however, when I start the app I get a black screen. When I extract the .apk
file it does not contain the jar file of the JavaFX application. I assume the apk should contain the JavaFX application jar-file, but I have no idea how to include it into the .apk
.
I also tried to use gradle to build the JavaFX application itself (jar-file), which works fine. However, I don't know where to put this jar-file that it can be included into the apk-file. I read I've to put it into a dist
directory, but I assume this would only be used in Netbeans right? I'm using the Eclipse gradle integration to build the project.
Here is what I tried. Since the JavaFX application is as simple as the HelloWorld sample app and works like a charm, I expect a missconfiguration within my gradle build file.
build.gradle - to build the apk
apply plugin: 'me.tatarka.retrolambda'
apply plugin: 'android'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'me.tatarka:gradle-retrolambda:2.5.0'
classpath 'com.android.tools.build:gradle:1.0.1'
}
}
repositories {
jcenter()
}
ext {
dalvikSdkHome = getProjectProperty('dalvikSDK')
dalvikSdkLib = dalvikSdkHome + '/rt/lib'
}
android {
compileSdkVersion 21
buildToolsVersion "21.1.1"
dexOptions {
preDexLibraries = false
}
sourceSets {
main {
jniLibs.srcDir file("${dalvikSdkLib}/")
assets.srcDirs = ['assets']
}
}
lintOptions {
abortOnError false
}
}
dependencies {
compile files ("${dalvikSdkLib}/ext/jfxrt.jar",
"${dalvikSdkLib}/ext/jfxdvk.jar",
"${dalvikSdkLib}/ext/compat-1.0.0.jar")
}
project.tasks.withType(com.android.build.gradle.tasks.Dex) {
additionalParameters=['--core-library']
}
String getProjectProperty(String propertyName) {
project.hasProperty(propertyName) ? project.property(propertyName) : null
}
build.gradle - to build the jar
// Declares binary plugin and its required JavaFX classpath
apply from: "http://dl.bintray.com/content/shemnon/javafx-gradle/0.4.0/javafx.plugin"
// Configures plugin
javafx {
// Points to JDK and its JavaFX libraries, also declares target runtime JDK
javaRuntime = getProjectProperty('javaJDKPath')
// Application name and ID presented by target OS
appID 'HelloWorldApp'
appName 'Hello World Application'
// Main class of application
mainClass 'helloworld.HelloWorld'
// JVM arguments, system properties, application command line arguments
jvmArgs = ['-XX:+AggressiveOpts', '-XX:CompileThreshold=1']
systemProperties = ['prism.disableRegionCaching':'true']
arguments = ['-l', '--fast']
// Keystore credentials for signing JAR
// Generate key: keytool -genkey -alias release -keyalg RSA -keystore keystore.jks -keysize 2048
releaseKey {
alias = 'release'
keyStore = file(getProjectProperty('keystoreJKSFile')) // keyStore = file("${System.properties['user.home']}/keystore/keystore.jks")
keyPass = getProjectProperty('keyStorePassword')
storePass = getProjectProperty('storePassword')
}
signingMode 'release'
// ...
}
String getProjectProperty(String propertyName) {
project.hasProperty(propertyName) ? project.property(propertyName) : null
}
gradle.properties
javaJDKPath=D:/Java/jdk1.8.0_20
dalvikSDK=D:/Java/dalvik-sdk-8u20b3/dalvik-sdk
keystoreJKSFile=D:/Java/jre1.8.0_20/bin/keystore.jks
keyStorePassword=password
storePassword=password
local.properties
sdk.dir=D:/programme/Android/adt-bundle-windows-x86_64-20130917/sdk
And this is my project structure
HelloWorld
-- src\main
-- java\helloworld\HelloWorld.java
-- res\
-- AndroidManifest.xml
-- assets\
-- javafx.platform.properties
-- javafx.properties
-- build.gradle
-- gradle.properties
-- local.properties
Do I need to use a dist
directory? Where would I put the jar-file of my JavaFX application that it will be included into the apk-file?