java.lang.NoClassDefFoundError: javafxports.android.FXDalvikEntity$2

205 views Asked by At

Getting the following error when starting my application on Android Phone

FATAL EXCEPTION: main
Process: ie.murphysoftware.games.magnatron, PID: 17378
java.lang.NoClassDefFoundError: javafxports.android.FXDalvikEntity$2
    at javafxports.android.FXDalvikEntity.jfxEventsLoop(FXDalvikEntity.java:484)
    at javafxports.android.FXDalvikEntity.<init>(FXDalvikEntity.java:118)
    at javafxports.android.FXActivity.onCreate(FXActivity.java:140)
    at android.app.Activity.performCreate(Activity.java:5426)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2269)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
    at android.app.ActivityThread.access$900(ActivityThread.java:161)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:157)
    at android.app.ActivityThread.main(ActivityThread.java:5356)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
    at dalvik.system.NativeStart.main(Native Method)

This error shows when running the app on Android Version KitKat API Level 19 and possibly lower versions of Android.

There are 2 dex classes in the APK

  • classes.dex
  • classes2.dex

The problem seems to be that the primary dex file classes.dex contains the class FXDalvikEntity and classes2.dex contains it's sub-classes which are

  • FXDalvikEntity$1
  • FXDalvikEntity$2
  • FXDalvikEntity$InternalSurfaceView
  • FXDalvikEntity$InternalTextureView
  • FXDalvikEntity$SurfaceDetails

When the application starts the classes contained in classes.dex are loaded but the classes from classes2.dex are not and this causes the error.

Is there a way to force dex to only create one dex file?

My build environment is

Eclipse - Neon
Gradle 3.1
compileSdkVersion = 25
minSdkVersion = 17
buildToolsVersion = "25.0.0"
applicationPackage = 'org.javafxports.ensemble'
2

There are 2 answers

2
Ray On

This is what the exception your receive indicates:

Thrown if the Java Virtual Machine or a ClassLoader instance tries to load in the definition of a class (as part of a normal method call or as part of creating a new instance using the new expression) and no definition of the class could be found.

(source: https://docs.oracle.com/javase/7/docs/api/java/lang/NoClassDefFoundError.html)

This means, that the class being accessed (directly or indirectly) in your app does not exist in the runtime environment. So probably, you need to choose a newer version as your runtime environment. An alternative cause might be that dependencies you use are not there (I am not sure how Android applications deal with 3rd party dependencies) and you need to include them to your application.

1
Mike Murphy On

Don't have a solution yet but the cause of the issue is.

  1. The size of the application requires 2 dex files.
  2. Android SDK version 20 or less does not support multidex files naturally and requires an additional android library "multidex.jar". Implementing the multidex library requires additional code which is documented in detail at this link Using multidex when minSdkVersion is set to 20 or lower
  3. These detailed instructions do not consider the javafxports hierarchy and require that the class needed to implement the multidex functionality extends android.support.multidex.MultiDexApplication or overrides the Application.attachBaseContext(...).

So the solution now seems to be to find a way to have the javafx.application.Application call the Multidex.install(this); leading to a new questioon on stackoverflow javafxports multidex minSdkVersion is set to 20 or less