Kotlin 如何设置/构建LibGDX+;科特林项目正确吗?

Kotlin 如何设置/构建LibGDX+;科特林项目正确吗?,kotlin,libgdx,Kotlin,Libgdx,我已经下载了gdx-setup.jar,并尝试使用以下设置构建空项目: 下面是我在控制台中得到的信息: Generating app in C:\Users\Divelix\Desktop\test Executing 'C:\Users\Divelix\Desktop\test/gradlew.bat clean --no-daemon idea' To honour the JVM settings for this build a new JVM will be forked. Plea

我已经下载了gdx-setup.jar,并尝试使用以下设置构建空项目:

下面是我在控制台中得到的信息:

Generating app in C:\Users\Divelix\Desktop\test
Executing 'C:\Users\Divelix\Desktop\test/gradlew.bat clean --no-daemon idea'
To honour the JVM settings for this build a new JVM will be forked. Please consider using the daemon: https://docs.gradle.org/4.6/userguide/gradle_daemon.html.
Daemon will be stopped at the end of the build stopping after processing
WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation'.
It will be removed at the end of 2018

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':android'.
> Failed to notify project evaluation listener.
   > com.android.build.gradle.internal.variant.BaseVariantData.getOutputs()Ljava/util/List;

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 22s
Done!
To import in Eclipse: File -> Import -> General -> Existing Projects into Workspace
To import to Intellij IDEA: File -> Open -> YourProject.ipr

如果我没有标记“Use Kotlin”,它构建得很好,那么这是为什么?我做错了什么?

好吧,我终于找到了如何使用Kotlin正确构建项目的方法(如果你在gradle上遇到问题,它也会帮助你)。首先,您只需在不使用“Use Kotlin”的情况下构建它,然后像这样编辑project build.gradle文件:

buildscript {
    ext.kotlinVersion = '1.1.1'

    repositories {
        mavenLocal()
        mavenCentral()
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.3'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"

    }
}
如果jcenter()之后有
google()
,也应该删除它

中:桌面
kotlin
插件替换
java
,并添加
kotlin stdlib

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-freetype-platform:$gdxVersion:natives-desktop"
        compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
    }
}
project(":android") {
    apply plugin: "android"
    apply plugin: "kotlin-android"

    configurations { natives }

    dependencies {
        compile project(":core")
        compile "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-arm64-v8a"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86_64"
        compile "com.badlogicgames.ashley:ashley:$ashleyVersion"
        compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi-v7a"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-arm64-v8a"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86_64"
        compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"

    }
}
project(":core") {
    apply plugin: "kotlin"

    dependencies {
        compile "com.badlogicgames.gdx:gdx:$gdxVersion"
        compile "com.badlogicgames.ashley:ashley:$ashleyVersion"
        compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
        compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
    }
}
:android
中添加
kotlin-android
插件和
kotlin-stdlib

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-freetype-platform:$gdxVersion:natives-desktop"
        compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
    }
}
project(":android") {
    apply plugin: "android"
    apply plugin: "kotlin-android"

    configurations { natives }

    dependencies {
        compile project(":core")
        compile "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-arm64-v8a"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86_64"
        compile "com.badlogicgames.ashley:ashley:$ashleyVersion"
        compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi-v7a"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-arm64-v8a"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86_64"
        compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"

    }
}
project(":core") {
    apply plugin: "kotlin"

    dependencies {
        compile "com.badlogicgames.gdx:gdx:$gdxVersion"
        compile "com.badlogicgames.ashley:ashley:$ashleyVersion"
        compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
        compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
    }
}
中:核心
kotlin
插件替换
java
,并添加
kotlin stdlib

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-freetype-platform:$gdxVersion:natives-desktop"
        compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
    }
}
project(":android") {
    apply plugin: "android"
    apply plugin: "kotlin-android"

    configurations { natives }

    dependencies {
        compile project(":core")
        compile "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-arm64-v8a"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86_64"
        compile "com.badlogicgames.ashley:ashley:$ashleyVersion"
        compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi-v7a"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-arm64-v8a"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86_64"
        compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"

    }
}
project(":core") {
    apply plugin: "kotlin"

    dependencies {
        compile "com.badlogicgames.gdx:gdx:$gdxVersion"
        compile "com.badlogicgames.ashley:ashley:$ashleyVersion"
        compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
        compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
    }
}
如果你有kotlin的问题,那就足够了

如果您也像我一样有gradle问题,请打开
gradle wrapper.properties
并将gradle版本修复为3.3:

distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-bin.zip

尝试在不使用“UseKotlin”的情况下构建,然后直接导入它,就像在这里一样。你运气好吗?我似乎也有类似的问题。请注意,Kotlin 1.3与gradle 2.2(默认的libgdx-gradle版本)并不匹配。如果存在构建问题,请升级gradle。