Gradle Glion Mobile-主索引列表中的类太多,超出了主索引容量

Gradle Glion Mobile-主索引列表中的类太多,超出了主索引容量,gradle,javafx,gluon-mobile,Gradle,Javafx,Gluon Mobile,我正在使用GluonHQ的JavaFX为Android创建移动应用程序。我使用的是OpenJDK 8和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-B

我正在使用GluonHQ的JavaFX为Android创建移动应用程序。我使用的是OpenJDK 8和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$ 
当我生成一个android应用程序时,我编写这个命令

asus@asus-pc:~/Dokument/Eclipse-Workspace/Deeplearning2C$ ./gradlew android
但我得到了这个错误。我不明白它是什么,我以前从来没有得到过

> 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$
根据这个问题,答案中的建议是:

  • (最简单的解决方案,但不适用于大多数应用程序)将MinSDK版本更改为21
  • 收缩应用程序代码。这一点之前已经讨论过很多次(参见此处和此处)
  • 如果上述解决方案都不适用于您,您可以尝试使用我的解决方案解决这个问题-我正在修补Android gradle插件,使其不在主索引中包含活动类。这有点老套,但对我来说很管用

我的项目非常小,我根本不使用很多依赖项。所以我不能缩减我的代码。那对我来说是不可能的。我无法更改SDK版本,因为我运行的是最低的Java8版本。最后一个建议我不想尝试,因为我不喜欢项目的“快速破解”

你认为它与Deeplearning4J依赖有关吗

我的gradle.build文件如下所示:

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.**.*'
        ]
    }
}
我的项目可以从这里下载:

编辑:

我试图用
dexOptions
编译gradle.build文件。下面是Se和错误

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.**.*'
        ]
    }
}
错误输出:

> 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$ 

看看它是如何以类似的方式解决的。@JoséPereda,谢谢。如果我从那里借几句话,这可能会给我一个解决办法。为什么要在gradle文件中排除leptonica、opencv和hdf5?他们在移动环境中不工作吗?这个项目不需要这些,我们试图缩小apk的尺寸,这已经足够大了。@JoséPereda我更新了我的问题。发现另一个错误。请查看如何以类似的方式解决它。@JoséPereda谢谢。如果我从那里借几句话,这可能会给我一个解决办法。为什么要在gradle文件中排除leptonica、opencv和hdf5?他们在移动环境中不工作吗?这个项目不需要这些,我们试图缩小apk的尺寸,这已经足够大了。@JoséPereda我更新了我的问题。发现另一个错误。