我正在使用 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$
根据这个问题,答案中的建议是:
- (最简单的解决方案,但不适合大多数应用程序)将 minSdkVersion 更改为 21。
- 缩小您的应用程序代码。这在之前已经讨论过很多次(见这里和这里)。
- 如果上述解决方案都不适合您,您可以尝试使用我的解决方法来解决这个问题 - 我正在修补 Android gradle 插件,使其不在 main dex 中包含 Activity 类。这有点hacky,但对我来说效果很好。
--main-dex-list 中的类太多,超出主 dex 容量
我的项目非常小,我根本不使用很多依赖项。所以我不能缩小我的代码。这对我来说是不可能的。我无法更改 SDK 版本,因为我运行的是最低 Java 8 版本。我不想尝试的最后一个建议是因为我不喜欢项目的“快速破解”。
你认为它与 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.**.*'
]
}
}
我的项目可以从这里下载:
https://github.com/DanielMartensson/Deeplearning2C
编辑:
我试图用dexOptions. 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$