在我的 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.<init>(GroundHandler.kt)
at com.mygdx.physics.Physics.createGround(Physics.kt:60)
at com.mygdx.physics.Physics.create(Physics.kt:31)
Physics 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 {}
最佳答案
只需像这样在 indo desktop.gradle 中添加 jar{} 部分:
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) } }
}
关于java.lang.NoClassDefFoundError : kotlin/jvm/internal/Intrinsics in libgdx 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46872254/