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'
This is what the exception your receive indicates:
(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.