title: How to run JavaFX on Android
body: <p>I try to run a simple JavaFX application on Android. Therefore I read the <a href="http://javafxports.org/page/Getting_Started" rel="noreferrer">javafxports Getting Started Guide</a> 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 <code>installDebug</code> task of gradle within Eclipse, however, when I start the app I get a black screen. When I extract the <code>.apk</code> 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 <code>.apk</code>. </p>
  
  <p>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 <code>dist</code> directory, but I assume this would only be used in Netbeans right? I'm using the Eclipse gradle integration to build the project.</p>
  
  <p>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.</p>
  
  <p><strong>build.gradle - to build the apk</strong></p>
  
  <pre><code>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
  }
  </code></pre>
  
  <p><strong>build.gradle - to build the jar</strong></p>
  
  <pre><code>// 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
  }
  </code></pre>
  
  <p><strong>gradle.properties</strong></p>
  
  <pre><code>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
  </code></pre>
  
  <p><strong>local.properties</strong></p>
  
  <pre><code>sdk.dir=D:/programme/Android/adt-bundle-windows-x86_64-20130917/sdk
  </code></pre>
  
  <p><strong>And this is my project structure</strong></p>
  
  <pre><code>HelloWorld
  -- src\main
      -- java\helloworld\HelloWorld.java
      -- res\
      -- AndroidManifest.xml
  -- assets\
      -- javafx.platform.properties
      -- javafx.properties
  -- build.gradle
  -- gradle.properties
  -- local.properties
  </code></pre>
  
  <p>Do I need to use a <code>dist</code> directory? Where would I put the jar-file of my JavaFX application that it will be included into the apk-file?</p>