1

I'm using GluonHQ's JavaFX to create mobile applications for Android. I'm using OpenJDK 8 and OpenJFX 8.

asus@asus-pc:~/Dokument/Eclipse-Workspace/Deeplearning2C$ java -version
openjdk version "1.8.0_222"
OpenJDK Runtime Environment (build 1.8.0_222-8u222-b10-1ubuntu1~19.04.1-b10)
OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode)
asus@asus-pc:~/Dokument/Eclipse-Workspace/Deeplearning2C$ 

When I generate a android application, I write this command.

asus@asus-pc:~/Dokument/Eclipse-Workspace/Deeplearning2C$ ./gradlew android

But I get this error. I don't understand what it is and I have never got that before.

> Task :Deeplearning2CApp:dex FAILED
[ant:java] Java Result: 2


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':Deeplearning2CApp: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:548)
        at com.android.dx.command.dexer.Main.runMultiDex(Main.java:368)
        at com.android.dx.command.dexer.Main.runDx(Main.java:289)
        at com.android.dx.command.dexer.Main.main(Main.java:247)
        at com.android.dx.command.Main.main(Main.java:94)


* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

* Get more help at https://help.gradle.org

BUILD FAILED in 6m 57s
11 actionable tasks: 9 executed, 2 up-to-date
asus@asus-pc:~/Dokument/Eclipse-Workspace/Deeplearning2C$

According to this question, the suggestions in the answer was was:

  • (The easiest solution, but not suitable for most of the applications) Change your minSdkVersion to 21.
  • Shrink your application code. This was discussed many times previously (see here and here).
  • If none of the above solutions work for you, you can try to use my workaround for this issue - I'm patching the Android gradle plugin to not include Activity classes in main dex. It's a bit hacky, but works well for me.

Too many classes in --main-dex-list, main dex capacity exceeded

My project is very minimal and I don't use many dependencies at all. So I cannot shrink down my code. That's is impossible for me. I cannot change the SDK version because I'm running at the lowest Java 8 version. The last suggestion I don't want to try because I don't like "quick hacks" for projects.

Do you think it has something with Deeplearning4J dependency?

My gradle.build file looks like this:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'org.javafxports:jfxmobile-plugin:1.3.17'
    }
}

apply plugin: 'org.javafxports.jfxmobile'

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

mainClassName = 'se.danielmartensson.Main'

dependencies {
    compile 'com.gluonhq:charm:5.0.2'
    compile group: 'org.deeplearning4j', name: 'deeplearning4j-core', version: '1.0.0-beta4'
    compile group: 'org.nd4j', name: 'nd4j-native-platform', version: '1.0.0-beta4'
    compile group: 'org.datavec', name: 'datavec-api', version: '1.0.0-beta4'
    compile group: 'org.projectlombok', name: 'lombok', version: '1.18.8'
}

jfxmobile {
    downConfig {
        version = '3.8.6'
        // Do not edit the line below. Use Gluon Mobile Settings in your project context menu instead
        plugins 'display', 'lifecycle', 'statusbar', 'storage'
    }
    android {
        manifest = 'src/android/AndroidManifest.xml'
    }
    ios {
        infoPList = file('src/ios/Default-Info.plist')
        forceLinkClasses = [
                'se.danielmartensson.**.*',
                'com.gluonhq.**.*',
                'javax.annotations.**.*',
                'javax.inject.**.*',
                'javax.json.**.*',
                'org.glassfish.json.**.*'
        ]
    }
}

My project can be downloaded from here:

https://github.com/DanielMartensson/Deeplearning2C

Edit:

I tried to compile gradle.build file with dexOptions . Se below and the error too.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'org.javafxports:jfxmobile-plugin:1.3.17'
    }
}

apply plugin: 'org.javafxports.jfxmobile'

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

mainClassName = 'se.danielmartensson.Main'

dependencies {
    compile 'com.gluonhq:charm:5.0.2'
    compile group: 'org.deeplearning4j', name: 'deeplearning4j-core', version: '1.0.0-beta4'
    compile group: 'org.nd4j', name: 'nd4j-native-platform', version: '1.0.0-beta4'
    compile group: 'org.datavec', name: 'datavec-api', version: '1.0.0-beta4'
    compile group: 'org.projectlombok', name: 'lombok', version: '1.18.8'
}

jfxmobile {
    downConfig {
        version = '3.8.6'
        // Do not edit the line below. Use Gluon Mobile Settings in your project context menu instead
        plugins 'display', 'lifecycle', 'statusbar', 'storage'
    }
    android {
        manifest = 'src/android/AndroidManifest.xml'
        dexOptions {
            additionalParameters = ['--minimal-main-dex']
            keepRuntimeAnnotatedClasses = false
            javaMaxHeapSize = '4g'
        }
    }
    ios {
        infoPList = file('src/ios/Default-Info.plist')
        forceLinkClasses = [
                'se.danielmartensson.**.*',
                'com.gluonhq.**.*',
                'javax.annotations.**.*',
                'javax.inject.**.*',
                'javax.json.**.*',
                'org.glassfish.json.**.*'
        ]
    }
}

Error output:

> Task :Deeplearning2CApp:dex 
[ant:java] Java Result: 1


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':Deeplearning2CApp:dex'.
> warning: Ignoring InnerClasses attribute for an anonymous inner class
  (EDU.oswego.cs.dl.util.concurrent.FutureResult$1) that doesn't come with an
  associated EnclosingMethod attribute. This class was probably produced by a
  compiler that did not target the modern .class file format. The recommended
  solution is to recompile the class from source, using an up-to-date compiler
  and without specifying any "-target" type options. The consequence of ignoring
  this warning is that reflective operations on this class will incorrectly
  indicate that it is *not* an inner class.
..
...
.....
......
.......
  warning: Ignoring InnerClasses attribute for an anonymous inner class
  (EDU.oswego.cs.dl.util.concurrent.misc.TestLoop$1) that doesn't come with an
  associated EnclosingMethod attribute. This class was probably produced by a
  compiler that did not target the modern .class file format. The recommended
  solution is to recompile the class from source, using an up-to-date compiler
  and without specifying any "-target" type options. The consequence of ignoring
  this warning is that reflective operations on this class will incorrectly
  indicate that it is *not* an inner class.
  OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x0000000701100000, 401080320, 0) failed; error='Cannot allocate memory' (errno=12)

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

* Get more help at https://help.gradle.org

BUILD FAILED in 6m 52s
11 actionable tasks: 9 executed, 2 up-to-date
asus@asus-pc:~/Dokument/Eclipse-Workspace/Deeplearning2C$ 
euraad
  • 2,467
  • 5
  • 30
  • 51
  • See how it was solved in a similar [project](https://github.com/gluonhq/gluon-samples/blob/master/deeplearning-linearclassifier/DeepLearningLinearClassifierApp/build.gradle#L92). – José Pereda Aug 25 '19 at 20:07
  • @JoséPereda Thank you. That might give me a solution if I borrow some lines from there? – euraad Aug 25 '19 at 20:10
  • @JoséPereda By the way. Why have you exclude leptonica, opencv and hdf5 in your gradle file? Do they don't work in mobile envoriment? – euraad Aug 25 '19 at 21:01
  • These were not required for that project, and we tried to reduce a little bit the size of the apk, that was already big enough. – José Pereda Aug 25 '19 at 21:03
  • @JoséPereda I have updated my question. Found another error. – euraad Aug 25 '19 at 21:48
  • Try setting `targetSdkVersion` to 28 (AndroidManifest). – José Pereda Aug 25 '19 at 22:00
  • @JoséPereda The compile % and time was longer, but I got java.lang.OutOfMemoryError: GC overhead limit exceeded. So I think I need a better computer. – euraad Aug 25 '19 at 22:14
  • @JoséPereda Got it working now. See my build.gradle file. https://github.com/DanielMartensson/Deeplearning2C By the way! Is there any way to see what error I got if the application just stops just like that? – euraad Aug 26 '19 at 14:39

0 Answers0