【问题标题】:java.lang.NoClassDefFoundError: kotlin/jvm/internal/Intrinsics in libgdxjava.lang.NoClassDefFoundError:libgdx 中的 kotlin/jvm/internal/Intrinsics
【发布时间】:2017-10-22 08:59:11
【问题描述】:

在我的 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() 的一行

更新:

按要求构建.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 {}

【问题讨论】:

  • 对您有帮助吗?

标签: java gradle libgdx kotlin build.gradle


【解决方案1】:

只需像这样添加 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) } }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-05-20
    • 2018-09-03
    • 1970-01-01
    • 1970-01-01
    • 2018-12-15
    • 2017-10-12
    • 1970-01-01
    • 2021-04-16
    相关资源
    最近更新 更多