简体   繁体   English

Android Studio-使用JAR依赖项时发生NoClassDefFoundError(一个libGDX项目)

[英]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.

相关问题 将外部jar添加到纯Java模块时出现NoClassDefFoundError,这是Android Studio中应用程序模块的依赖项 - NoClassDefFoundError when adding external jar to a pure java module, which is a dependency of the app module in Android Studio 将Github项目包含在没有jar或依赖项的Android Studio 2项目中 - Include Github Project into Android Studio 2 project without jar or dependency Android Studio | Libgdx | 添加Kryonet库 - NoClassDefFoundError - Android Studio | Libgdx | Adding Kryonet Library - NoClassDefFoundError 使用我自己的项目中的依赖项时出现NoClassDefFoundError - NoClassDefFoundError when using a dependency from my own project 使用Jar而不是源代码时的Xerces-for-Android NoClassDefFoundError - Xerces-for-Android NoClassDefFoundError When Using Jar Instead of Source Code 在Android Studio中的libgdx中导入可执行jar文件 - Importing an executable jar file in libgdx in android studio 如何制作LibGDX + Android Studio jar文件? - How to make LibGDX + Android Studio jar file? 向jar项目的Android项目添加依赖项 - Adding a dependency to Android project for jar 将现有的android studio项目与libgdx项目合并 - Merge existing android studio project with libgdx project NoClassDefFoundError使用来自其他项目的JAR - NoClassDefFoundError using JAR from other project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM