如何使用 Java 8 在 Android 和桌面 (IntelliJ 2018 CE/Gradle) 上使用 libGDX 进行开发 [英] How to develop with libGDX on both Android and Desktop (IntelliJ 2018 CE /Gradle) with Java 8

查看:36
本文介绍了如何使用 Java 8 在 Android 和桌面 (IntelliJ 2018 CE/Gradle) 上使用 libGDX 进行开发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

慢慢学习gradle.(对我而言)排除 IDE 错误并从命令行运行我的项目至关重要.这让我发现我的路径指的是 JRE 而不是 JDK;我收到一条错误消息,指出 tools.jar 不在路径上,就是这样.

Slowly learning gradle. It is essential (to me) to rule out IDE bugs and run my project from the command line. This lead me to discover my path was referring to a JRE instead of JDK; I got an error message stating that tools.jar was not on the path and that was that.

但是,当我执行 gradlew desktop:debug 时,我仍然无法超过大约 80%.

However I still cannot get past about 80-something percent when I execute gradlew desktop:debug.

因此,这个问题与我最近升级到 2018 版本的 IntelliJ 有关.2017 版运行良好,有一个很大的免责声明,我不是,实际上当时使用的是 Java8 lambda.搬到 2018 年,我觉得创建一个新的 libGDX(我知道的针对多个平台的最佳方式)项目将我的所有文件转储到而不是调试我得到的所有(通常无用的)堆栈跟踪更容易.

Hence this question is concerned with IntelliJ that I recently upgraded to the 2018 version. Version 2017 was working fine, with a big disclaimer that I wasn't, in fact using Java8 lambda's at that time. Moving to 2018 I felt it easier to create a new libGDX (best way I know to target multiple platforms) project to dump all my files into rather than debug all the (often unhelpful) stack traces I was getting.

开箱即用,我对 gradle 进行了最少的进一步修改,以使桌面版本正常工作.我真的不想重复这一点,因为我选择了一个新名称,这意味着大量的编辑和破坏.在 Android 上部署时,我陷入了困境.

Out of the box I performed minimal further modifications to gradle to get the desktop version working. I really don't want to repeat that as I opt for a new name which means a lot of editing and breaking. When it came to deploying on Android I got stuck.

需要对 Gradle 版本和 gradle 文件进行哪些修改才能使 Android 构建工作?对于加分,为什么显然涉及 4 个不同版本的 gradle?

What are the modifications needed to Gradle versions and gradle files to get Android builds working? For bonus points, why are there apparently 4 different versions of gradle involved?

推荐答案

我花了很多时间让libgdx在java8中编译.我做到了.对我和我的朋友有用.如果您想尝试它并立即失败,请给 Intellij 几次重新启动和缓存失效.可能需要从 %userdir% 中删除 .gradle(不一定),但最终它工作稳定.

I spent a lot of time to make libgdx compile in java8. And I did it. Works to me and my friends. If you wish to try it and it fails right away, give Intellij a couple of restarts and cache invalidations. Might need to delete .gradle from %userdir% (not necessarily), but in the end it worked stable.

这是我的配置:

Intellij IDEA 18+ 或 Android studio 3.0+

Intellij IDEA 18+ or Android studio 3.0+

wrapper.properties:

wrapper.properties:

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https://services.gradle.org/distributions/gradle-4.5-bin.zip

项目 build.gradle:

Project build.gradle:

repositories {
    google() //add google repo
}
dependencies {
    classpath 'com.android.tools.build:gradle:3.0.1' //higher versions were not compiling right
}

Andoird build.gradle:

Andoird build.gradle:

android{
    buildToolsVersion "27.0.3"
    compileSdkVersion 27

    defaultConfig {
        minSdkVersion 16 //16 is good enough for 2018
        targetSdkVersion 27
        //Forget about Jack if you were using it. 
    }

    compileOptions {
        sourceCompatibility = 1.8
        targetCompatibility = 1.8
    }
}
eclipse { 

    jdt {
        sourceCompatibility = 1.8
        targetCompatibility = 1.8
    }
}

对于桌面 build.gradle

and for the Desktop build.gradle

sourceCompatibility = 1.8

这篇关于如何使用 Java 8 在 Android 和桌面 (IntelliJ 2018 CE/Gradle) 上使用 libGDX 进行开发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆