java.lang.NoClassDefFoundError:kotlin / jvm / internal / intrinsics in libgdx

在我的libgdx gradle应用程序中,我有一个GroundHandler类:

package com.mygdx.physics import com.badlogic.gdx.ApplicationAdapter import com.badlogic.gdx.Gdx import com.badlogic.gdx.math.Vector2 import com.badlogic.gdx.physics.box2d.Fixture import com.badlogic.gdx.physics.box2d.Body import com.badlogic.gdx.physics.box2d.BodyDef import com.badlogic.gdx.graphics.OrthographicCamera import com.badlogic.gdx.physics.box2d.PolygonShape import com.badlogic.gdx.physics.box2d.World class GroundHandler(val world: World, val camera: OrthographicCamera) { private var groundBodyDef: BodyDef = BodyDef() private var groundBox: PolygonShape = PolygonShape() private var groundBody: Body? = null fun createGround() { groundBodyDef.position.set(Vector2(0f, 10f)) groundBody = world.createBody(groundBodyDef) groundBox.setAsBox(camera.viewportWidth, 10.0f) groundBody?.createFixture(groundBox, 0.0f) groundBox.dispose() } } 

用于不同的课程。 起初它编译得很好,但是当应用程序窗口开始我得到

 Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: java.lang.NoClassDefFoundError: kotlin/jvm/internal/Intrinsics at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:133) Caused by: java.lang.NoClassDefFoundError: kotlin/jvm/internal/Intrinsics at com.mygdx.physics.GroundHandler.(GroundHandler.kt) at com.mygdx.physics.Physics.createGround(Physics.kt:60) at com.mygdx.physics.Physics.create(Physics.kt:31) 

物理31是一个线,我打电话createGround()

更新:

build.gradle按要求(没有jar {}部分没有工作)

 buildscript { ext.kotlin_version = '1.1.51' repositories { mavenLocal() mavenCentral() maven { url "https://oss.sonatype.org/content/repositories/snapshots/" } jcenter() } dependencies { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } allprojects { apply plugin: "eclipse" apply plugin: "idea" version = '1.0' ext { appName = "physics game" gdxVersion = '1.9.6' roboVMVersion = '2.3.1' box2DLightsVersion = '1.4' ashleyVersion = '1.7.0' aiVersion = '1.8.0' } repositories { mavenLocal() mavenCentral() maven { url "https://oss.sonatype.org/content/repositories/snapshots/" } maven { url "https://oss.sonatype.org/content/repositories/releases/" } } } project(":core") { apply plugin: "kotlin" dependencies { compile "com.badlogicgames.gdx:gdx:$gdxVersion" compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion" compile "com.badlogicgames.gdx:gdx-bullet:$gdxVersion" compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion" compile "com.badlogicgames.gdx:gdx-controllers:$gdxVersion" compile "com.badlogicgames.box2dlights:box2dlights:$box2DLightsVersion" compile "com.badlogicgames.gdx:gdx-ai:$aiVersion" compile "com.badlogicgames.ashley:ashley:$ashleyVersion" } } project(":desktop") { apply plugin: "kotlin" dependencies { compile project(":core") compile "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion" compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop" compile "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-desktop" compile "com.badlogicgames.gdx:gdx-bullet-platform:$gdxVersion:natives-desktop" compile "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop" compile "com.badlogicgames.gdx:gdx-tools:$gdxVersion" compile "com.badlogicgames.gdx:gdx-controllers-desktop:$gdxVersion" compile "com.badlogicgames.gdx:gdx-controllers-platform:$gdxVersion:natives-desktop" } } tasks.eclipse.doLast { delete ".project" } 

我所做的只是把“java”更改为“kotlin”两次,并将kotlin依赖项添加到buildscript {}

只需添加jar {}部分indo desktop.gradle就像这样:

 apply plugin: "kotlin" sourceCompatibility = 1.6 sourceSets.main.java.srcDirs = [ "src/" ] project.ext.mainClassName = "com.your.class.name" project.ext.assetsDir = new File("../android/assets"); jar { manifest {} from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } }