我在我的游戏中使用 libGDX,它与另一个项目共享一些代码。我将此代码放入一个 .jar 库中,该库已添加到根 build.gradle 中。
在桌面上一切正常,但当我在 Android 上启动游戏时,它崩溃并出现 ClassNotFound 异常。它找不到我的库的类。
谁能帮帮我吗?我不知道是什么导致了这个问题。
编辑:对 build.gradle 的更改:
project(":core") {
apply plugin: "java"
dependencies {
compile "com.badlogicgames.gdx:gdx:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
compile fileTree(dir: '../libs', include: '*.jar')
}
}
最佳答案
您需要直接在 android
模块中添加相同的 fileTree
依赖项,因为 Android Gradle 插件目前无法处理传递性平面文件依赖项。
project(":core") {
...
compile fileTree(dir: '../libs', include: '*.jar')
...
}
// And also
project(":android") {
...
compile fileTree(dir: '../libs', include: '*.jar')
...
}
Source .
关于java - Android 上的 LibGDX ClassNotFound,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39112498/