Cannot install JavaFX app on Android x86_64

2019-08-23 01:49发布

问题:

I managed to build a JavaFX app using gradle and javafxport but the apk fail to install on my device.

Here is my build.gradle:

task wrapper(type: Wrapper) {
    gradleVersion = '2.4'
}

buildscript {
    repositories {
        jcenter()
    }

    dependencies {
        classpath 'org.javafxports:jfxmobile-plugin:1.0.0-b10'
    }
}

apply plugin: 'org.javafxports.jfxmobile'

mainClassName = 'java.Main'

repositories {
    jcenter()
}

jfxmobile {
    ios {
        forceLinkClasses = ['java.**.*']
    }
    android {
        applicationPackage = 'com.superflush.java'
    androidSdk = 'C:/Users/USERNAME/AppData/Local/Android/android-sdk'
    }
}

My device is a Asus Zenfone2 running stock Android 5.0

It is a x86_64 so I suspect that might be an issue but im not sure how to diagnose. Any suggestion how to solve this problem?

I managed to get my hands on standard 4.4.2 ARM phone so it installs but it wont run (blackscreen) and here is the logcat error output at execution:

E/DalvikLauncher(12088): java.lang.ClassNotFoundException: Didn't find class "application.Main" on path: DexPathList[[zip file "/data/app/com.superflu
sh.java-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.superflush.java-2, /vendor/lib, /system/lib]]
E/DalvikLauncher(12088):        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
E/DalvikLauncher(12088):        at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
E/DalvikLauncher(12088):        at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
E/DalvikLauncher(12088):        at javafxports.android.DalvikLauncher.resolveApplicationClass(DalvikLauncher.java:232)
E/DalvikLauncher(12088):        at javafxports.android.DalvikLauncher.launchApp(DalvikLauncher.java:134)
E/DalvikLauncher(12088):        at javafxports.android.FXDalvikEntity.getLauncherAndLaunchApplication(FXDalvikEntity.java:118)
E/DalvikLauncher(12088):        at javafxports.android.FXDalvikEntity.surfaceCreated(FXDalvikEntity.java:144)
E/DalvikLauncher(12088):        at android.view.SurfaceView.updateWindow(SurfaceView.java:572)
E/DalvikLauncher(12088):        at android.view.SurfaceView.access$000(SurfaceView.java:86)
E/DalvikLauncher(12088):        at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:175)
E/DalvikLauncher(12088):        at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:847)
E/DalvikLauncher(12088):        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1871)
E/DalvikLauncher(12088):        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000)
E/DalvikLauncher(12088):        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5670)
E/DalvikLauncher(12088):        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
E/DalvikLauncher(12088):        at android.view.Choreographer.doCallbacks(Choreographer.java:574)
E/DalvikLauncher(12088):        at android.view.Choreographer.doFrame(Choreographer.java:544)
E/DalvikLauncher(12088):        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
E/DalvikLauncher(12088):        at android.os.Handler.handleCallback(Handler.java:733)
E/DalvikLauncher(12088):        at android.os.Handler.dispatchMessage(Handler.java:95)
E/DalvikLauncher(12088):        at android.os.Looper.loop(Looper.java:136)
E/DalvikLauncher(12088):        at android.app.ActivityThread.main(ActivityThread.java:5149)
E/DalvikLauncher(12088):        at java.lang.reflect.Method.invokeNative(Native Method)
E/DalvikLauncher(12088):        at java.lang.reflect.Method.invoke(Method.java:515)
E/DalvikLauncher(12088):        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
E/DalvikLauncher(12088):        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
E/DalvikLauncher(12088):        at dalvik.system.NativeStart.main(Native Method)

Here is my project structure, Main.java being the main:

回答1:

First of all, under mainClassName you should add the name of you main class (let say JavaFXApp), including the package. something like this:

mainClassName = 'com.superflush.java.JavaFXApp'

Inside android, you don't need the applicationPackage line.

Once you have successfully built your apk, if you install it on your device, try to run it. Keep it connected, and run adb logcat on the command line to see all the output and find any possible exception, if it doesn't work.

EDIT

Based on the last changes on the OP answer, this is a more proper answer.

For starters, the Main java class should be inside a package properly named. You must follow Android package name convention rules, so something like this will work:

package com.julioqc.superflush;

Also note, you will find your main class under these folders:

src/main/java/com/julioqc/superFlush/Main.java

(Note main/java is not part of the name of the package).

Accordingly, you should have your resources under the same structure of folders:

src/main/resources/com/julioqc/superFlush/application.css
src/main/resources/com/julioqc/superFlush/Image.jpg ...

Finally, this should be the Build.gradle file:

buildscript {
    repositories {
        jcenter()
    }

    dependencies {
        classpath 'org.javafxports:jfxmobile-plugin:1.0.0-b10'
    }
}

apply plugin: 'org.javafxports.jfxmobile'

mainClassName = 'com.julioqc.superflush.Main'

repositories {
    jcenter()
}

jfxmobile {
    ios {
        forceLinkClasses = ['com.julioqc.superflush.**.*']
    }
    android {
        androidSdk = 'C:/Users/<user>/AppData/Local/Android/android-sdk'
    }
}


回答2:

It is a x86_64 so I suspect that might be an issue but im not sure how to diagnose.

To diagnose why an app is not installing, execute an install using the adb via the command prompt

adb install myapp.apk

You will get output indicating if the install on the device has failed with a reason for the failure.

If your app is installing correctly on ARM devices but not x86 devices then it is likely your adb is not shipping all the required native libraries. If this is the case then the adb install command will return the error INSTALL_FAILED_NO_MATCHING_ABIS