[英]Android Studio - NoClassDefFoundError when using a JAR dependency (a libGDX project)
So, I've coded a plain Java project that I'd like to use in my Android project. 因此,我已经编写了一个我想在Android项目中使用的普通Java项目。 The project to be imported was written in Eclipse, so I've exported it as a (runnable) JAR file and added it to the dependencies of my project. 要导入的项目是用Eclipse编写的,因此我将其导出为(可运行的)JAR文件,并将其添加到项目的依赖项中。 However, the program fails when I try to run it with this message: 但是,当我尝试使用此消息运行程序时,该程序失败:
FATAL EXCEPTION: GLThread 20499
Process: com.mkcode.droidrogue, PID: 29039
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/mkcode/dmg/Generator;
I'm new to Android Studio. 我是Android Studio的新手。 I know that in Eclipse I could edit the project's run configuration and add the JAR there, but I haven't found anything like that in Android Studio. 我知道在Eclipse中我可以编辑项目的运行配置并在其中添加JAR,但我在Android Studio中找不到类似的东西。 I've added the JAR as both a compile-time and runtime dependency like this: 我已经将JAR添加为编译时和运行时依赖项,如下所示:
The project is a libGDX project divided into sub-projects (core, Android, iOS, desktop). 该项目是一个libGDX项目,分为子项目(核心,Android,iOS,桌面)。 Every launcher project includes the core project into itself. 每个启动器项目都将核心项目包含到自身中。
What could I do to make this work? 我该怎么做才能使这项工作?
I got it to work, I added the following to the build.gradle
file of the root project: 我成功了,将以下内容添加到根项目的build.gradle
文件中:
project(":core") {
apply plugin: "java"
dependencies {
...
compile files('libs/DungeonMapGenerator.jar') // ADDED THIS LINE
}
} }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.