如何使用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

查看:173
本文介绍了如何使用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.

但是我仍然无法超过80 - 执行 gradlew桌面时的百分比:debug

因此这个问题与IntelliJ有关我最近升级到了2018年的版本。版本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

Project 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天全站免登陆