我试图将esotericsoftware“Kryo”中的库添加到我的Desktop和Android模块上的libGDX项目中。我正在使用Intellij。

我试过的

  • 将kryo-3.0文件夹添加到外部库
  • 将build.gradle中的依赖项添加到所有模块compile "com.esotericsoftware:kryo:3.0.3"
  • 运行Gradle
  • 同步项目。

  • 编译Desktop模块后我得到了什么:
    Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: java.lang.NoClassDefFoundError: org/objenesis/strategy/InstantiatorStrategy
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:131)
    Caused by: java.lang.NoClassDefFoundError: org/objenesis/strategy/InstantiatorStrategy
      at com.projectbeta.deepdarkness.screens.MenuScreen.show(MenuScreen.java:18)
      at com.badlogic.gdx.Game.setScreen(Game.java:61)
      at com.projectbeta.deepdarkness.DeepDarkness.create(DeepDarkness.java:16)
      at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:147)
      at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:124)
    Caused by: java.lang.ClassNotFoundException: org.objenesis.strategy.InstantiatorStrategy
      at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
      ... 5 more
    

    最佳答案

    经过测试,它可以正常工作,将其粘贴到项目的根gradle.build中(不在某些特定模块中)并重新同步。

    project(":core") {
        apply plugin: "java"
    
        dependencies {
            ......
            compile group: 'com.esotericsoftware', name: 'kryo', version: '3.0.3'
        }
    }
    
    project(":desktop") {
        apply plugin: "java"
    
        dependencies {
            compile project(":core")
            .......
            compile group: 'com.esotericsoftware', name: 'kryo', version: '3.0.3'
    
        }
    }
    
    project(":android") {
        apply plugin: "android"
    
        configurations { natives }
    
        dependencies {
            compile project(":core")
            ......
            compile group: 'com.esotericsoftware', name: 'kryo', version: '3.0.3'
    
        }
    }
    

    关于java - Intellij/libGDX添加lib kryo NoClassDefFoundError,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37641750/

    10-11 09:12