1

I am trying to make my application run on an android device by using the jfxmobile-plugin.

When I do a

gradle android

on my project I get

Execution failed for task ':dex'.
> UNEXPECTED TOP-LEVEL EXCEPTION:
  com.android.dex.DexException: Too many classes in --main-dex-list, main dex capacity exceeded
        at com.android.dx.command.dexer.Main.processAllFiles(Main.java:546)
        at com.android.dx.command.dexer.Main.runMultiDex(Main.java:366)
        at com.android.dx.command.dexer.Main.run(Main.java:275)
        at com.android.dx.command.dexer.Main.main(Main.java:245)
        at com.android.dx.command.Main.main(Main.java:106)

My gradle file is this

buildscript {
    repositories {
        jcenter()
    }

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

apply plugin: 'org.javafxports.jfxmobile'

mainClassName = 'de.package.of.application.ClientApp'

dependencies {

    compile 'com.annimon:stream:1.0.1'
    compile 'com.jakewharton.threetenabp:threetenabp:1.0.4'
    compile 'com.gluonhq:charm:4.2.0'

    androidRuntime 'com.gluonhq:charm-android:3.0.0'
    iosRuntime 'com.gluonhq:charm-ios:3.0.0'
    desktopRuntime 'com.gluonhq:charm-desktop:3.0.0'   

    compile fileTree(dir: 'target/dependencies', include: '*.jar')
    runtime fileTree(dir: 'target/dependencies', include: '*.jar')    
}

repositories {
    jcenter()
    maven {
        url 'http://nexus.gluonhq.com/nexus/content/repositories/releases'
    }
}

jfxmobile {
    ios {
        forceLinkClasses = ['ensemble.**.*']
    }
    android {
        //manifest = 'AndroidManifest.xml'
        compileSdkVersion = '24'
        androidSdk='C:/Tools/android-sdk-windows'

        packagingOptions {
        exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        //... some more excludes

    }

        dexOptions {
            javaMaxHeapSize '3g'

            // keepRuntimeAnnotatedClasses false
        }
    }
}

I found some similar questions about the exception logged by the gradle build but non brought a real solution for me so far especially in combination with the usage of the javafxports-plugin.

  • Some suggested to set the compileSdkVersion to a minumum of 21-> I use 24 -> this does not help.
  • Using keepRuntimeAnnotatedClasses=false is not an option because the application is build on some Reflection/injection-logic (spring-framework).
  • As I understand the build process takes those classes into account to put in the main-dex-file which are required to initially start up the application. So I stripped down the application to an absolut minimum with no other dependencies (direct or transitive) to the other libraries of my application (no imports of classes from other libraries, except to java/javafx). The other libraries are included by the 'runtime fileTree...' part of the gradle-file but are not really used at startup. Idea was to create a 2-phase startup of the application: First a minimum-app and then, when the minimum app is loaded, start the real application code. -> no success, it seems all libraries are taken into account for the main-dex-file.

I do not see how to solve it together with javafxports. Does anyone have suggestions?

GR1975
  • 11
  • 2
  • You can remove the platform dependencies for Charm 3.0.0, no longer necessary with Charm 4.3.0. Can you add `minSdkVersion '24'` and test again? Do you have the Android Support Library installed? Maybe you can remove it and use the multidex-1.0.1 support (see [here](http://stackoverflow.com/questions/41133317/javafxports-android-gradle-task-requires-android-support-library-which-is-re)) – José Pereda Jan 22 '17 at 17:33
  • Sounds promising: So I reinstalled the Android SDK (to be sure the Android Support Library is not available any more), this time even with version 25. compileSdkVersion and minSdkVersion is set to 25 now. The platform dependencies are removed. The error did not go away... Did a build with the --debug-switch now and scrolled a bit throught the output and found a line about an outputfile maindexlist.txt. Browsed to this file and found many classes listed where really many of them are far away from being required for startup of the application. Why are these classes are taken into account? – GR1975 Jan 23 '17 at 08:41
  • It seems you have many transitive dependencies. You can run `./gradlew dependencies` and see the tree of dependencies. I haven't tried this [solution](http://stackoverflow.com/a/17821193/3956070), but maybe you can give it a try? – José Pereda Jan 23 '17 at 19:52

0 Answers0