LibGdx Android Studio 出现多个错误

LibGdx having multiple errors with Android Studio

一个多星期以来,我一直在尝试通过 Android Studio 跟随 this tutorial 学习 LibGDX。我永远无法为桌面配置构建和 运行。我在互联网上浏览了很多解决方案,但没有找到任何解决方案。下面我将显示有关我的项目和文件的所有详细信息。

很抱歉解释得太长,但我必须显示所有错误和细节以便更好地分析。

我对所有相关内容的版本是:

  1. Android工作室版本:3.1.3
  2. SDK 工具:26.1.1
  3. Android平台版本:API28修订版4
  4. Gradle: 4.6
  5. Android插件版本:3.1.0
  6. Java: Java 8 更新 171

这是我在 libgdx 项目设置中选择的设置: LibGdx Project Setup

这是高级选项(只选择Eclipse):Advance option

我遇到了两个警告对话框,第一个是:

You have a more recent version of android build tools than the recommended.
Do you want to use your more recent version?

我选择了否,然后它告诉我:

Using build tools: 27.0.3

第二个说:

You have a more recent Android API than the recommended.
Do you want to use your more recent version?

我再次选择否,然后它说:

Using API level: 27

成功完成设置后,消息显示:

Generating app in C:\AndroidStudioWorkspace\FlappyDemo
Executing 'C:\AndroidStudioWorkspace\FlappyDemo/gradlew.bat clean --no-daemon eclipse afterEclipseImport'
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
:android:clean UP-TO-DATE
:core:clean UP-TO-DATE
:desktop:clean UP-TO-DATE
:eclipseProject
:eclipse
:android:eclipseClasspath
:android:eclipseJdt
:android:eclipseProject
:android:eclipse
:core:eclipseClasspath
:core:eclipseJdt
:core:eclipseProject
:core:eclipse
:desktop:eclipseClasspath
:desktop:eclipseJdt
:desktop:eclipseProject
:desktop:eclipse
:desktop:afterEclipseImport

Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.
See https://docs.gradle.org/4.6/userguide/command_line_interface.html#sec:command_line_warnings

BUILD SUCCESSFUL in 14s
15 actionable tasks: 12 executed, 3 up-to-date
Done!
To import in Eclipse: File -> Import -> General -> Existing Projects into Workspace
To import to Intellij IDEA: File -> Open -> YourProject.ipr

我启动了 Android Studio 并导入了我使用 LibGdx 项目设置创建的这个项目。

在 Android Studio 中打开项目时遇到的第一个错误是:

Configuration 'compile' is obsolete and has been replaced with 'implementation'.
It will be removed at the end of 2018

我的主要 build.gradle 文件是这样的:

buildscript {


    repositories {
        mavenLocal()
        mavenCentral()
        maven { url "https://plugins.gradle.org/m2/" }
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.0'


    }
}

allprojects {
    apply plugin: "eclipse"
    apply plugin: "idea"

    version = '1.0'
    ext {
        appName = "FlappyDemo"
        gdxVersion = '1.9.8'
        roboVMVersion = '2.3.3'
        box2DLightsVersion = '1.4'
        ashleyVersion = '1.7.0'
        aiVersion = '1.8.0'
    }

    repositories {
        mavenLocal()
        mavenCentral()
        google()
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
        maven { url "https://oss.sonatype.org/content/repositories/releases/" }
    }
}

project(":desktop") {
    apply plugin: "java"


    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"

    }
}

project(":android") {
    apply plugin: "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.gdx:gdx-box2d:$gdxVersion"
        natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi"
        natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi-v7a"
        natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-arm64-v8a"
        natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-x86"
        natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-x86_64"

    }
}

project(":core") {
    apply plugin: "java"


    dependencies {
        compile "com.badlogicgames.gdx:gdx:$gdxVersion"
        compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"

    }
}

tasks.eclipse.doLast {
    delete ".project"
}

我的gradle-wrapper.properties是这样的:

#Fri Jun 09 23:06:52 EDT 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-bin.zip

我的gradle.properties是:

org.gradle.daemon=true
org.gradle.jvmargs=-Xms128m -Xmx1500m
org.gradle.configureondemand=false

所以我将所有编译更改为实现,我的文件变为:

buildscript {


    repositories {
        mavenLocal()
        mavenCentral()
        maven { url "https://plugins.gradle.org/m2/" }
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.0'


    }
}

allprojects {
    apply plugin: "eclipse"
    apply plugin: "idea"

    version = '1.0'
    ext {
        appName = "FlappyDemo"
        gdxVersion = '1.9.8'
        roboVMVersion = '2.3.3'
        box2DLightsVersion = '1.4'
        ashleyVersion = '1.7.0'
        aiVersion = '1.8.0'
    }

    repositories {
        mavenLocal()
        mavenCentral()
        google()
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
        maven { url "https://oss.sonatype.org/content/repositories/releases/" }
    }
}

project(":desktop") {
    apply plugin: "java"


    dependencies {
        implementation project(":core")
        implementation "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
        implementation "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
        implementation "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-desktop"

    }
}

project(":android") {
    apply plugin: "android"

    configurations { natives }

    dependencies {
        implementation project(":core")
        implementation "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"
        implementation "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
        natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi"
        natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi-v7a"
        natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-arm64-v8a"
        natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-x86"
        natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-x86_64"

    }
}

project(":core") {
    apply plugin: "java"


    dependencies {
        implementation "com.badlogicgames.gdx:gdx:$gdxVersion"
        implementation "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"

    }
}

tasks.eclipse.doLast {
    delete ".project"
}

此外,当我在更新文件后进行同步时,我看到了这条消息:

To take advantage of all the latest features (such as Instant Run), improvements and
security fixes, we strongly recommend that you update the Android Gradle plugin to
version 3.1.3 and Gradle to version 4.4.

You can learn more about this version of the plugin from the release notes.

我选择了"remind me tommorow"。 同步成功!我通过 运行 在我的 android phone 上对其进行测试,一切正常,除了 1 个警告:

warning: [options] bootstrap class path not set in conjunction with -source 1.6

我还看到了一个 IDE 错误,它是:

Editor of class com.intellij.openapi.editor.impl.EditorImpl hasn't been released:
com.intellij.openapi.util.TraceableDisposable.ObjectNotDisposedException: See stack trace responsible for creation of unreleased object below 
    at com.intellij.openapi.editor.impl.EditorImpl.<init>(EditorImpl.java:146)
    at com.intellij.openapi.editor.impl.EditorFactoryImpl.createEditor(EditorFactoryImpl.java:220)
    at com.intellij.openapi.editor.impl.EditorFactoryImpl.createViewer(EditorFactoryImpl.java:190)
    at com.intellij.execution.impl.ConsoleViewUtil.setupConsoleEditor(ConsoleViewUtil.java:68)
    at com.intellij.execution.impl.ConsoleViewImpl.doCreateConsoleEditor(ConsoleViewImpl.java:903)
    at com.intellij.execution.impl.ConsoleViewImpl.lambda$createConsoleEditor(ConsoleViewImpl.java:880)
    at com.intellij.openapi.application.ReadAction.compute(ReadAction.java:47)
    at com.intellij.execution.impl.ConsoleViewImpl.createConsoleEditor(ConsoleViewImpl.java:879)
    at com.intellij.execution.impl.ConsoleViewImpl.initConsoleEditor(ConsoleViewImpl.java:452)
    at com.intellij.execution.impl.ConsoleViewImpl.getComponent(ConsoleViewImpl.java:431)
    at com.intellij.build.BuildTreeConsoleView$DetailsHandler.<init>(BuildTreeConsoleView.java:634)
    at com.intellij.build.BuildTreeConsoleView.<init>(BuildTreeConsoleView.java:222)
    at com.intellij.build.BuildView.onStartBuild(BuildView.java:128)
    at com.intellij.build.BuildView.lambda$onEvent[=24=](BuildView.java:87)
    at com.intellij.openapi.application.impl.ApplicationImpl.invokeAndWait(ApplicationImpl.java:653)
    at com.intellij.openapi.application.impl.ApplicationImpl.invokeAndWait(ApplicationImpl.java:666)
    at com.intellij.build.BuildView.onEvent(BuildView.java:86)
    at com.intellij.build.MultipleBuildsView.lambda$onEvent(MultipleBuildsView.java:163)
    at com.intellij.build.MultipleBuildsView.lambda$onEvent(MultipleBuildsView.java:288)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:762)
    at java.awt.EventQueue.access0(EventQueue.java:98)
    at java.awt.EventQueue.run(EventQueue.java:715)
    at java.awt.EventQueue.run(EventQueue.java:709)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:732)
    at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:822)
    at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:650)
    at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:366)
    at com.intellij.ide.IdeEventQueue.pumpEventsForHierarchy(IdeEventQueue.java:924)
    at com.intellij.openapi.progress.util.ProgressWindow.startBlocking(ProgressWindow.java:217)
    at com.intellij.openapi.progress.util.ProgressWindow.startBlocking(ProgressWindow.java:203)
    at com.intellij.openapi.application.impl.ApplicationImpl.runProcessWithProgressSynchronously(ApplicationImpl.java:589)
    at com.intellij.openapi.progress.impl.CoreProgressManager.runProcessWithProgressSynchronously(CoreProgressManager.java:409)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.runProcessWithProgressSynchronously(ProgressManagerImpl.java:117)
    at com.intellij.openapi.progress.impl.CoreProgressManager.runSynchronously(CoreProgressManager.java:318)
    at com.intellij.openapi.progress.impl.CoreProgressManager.run(CoreProgressManager.java:303)
    at com.intellij.openapi.progress.Task.queue(Task.java:115)
    at com.intellij.openapi.externalSystem.util.ExternalSystemUtil.refreshProject(ExternalSystemUtil.java:621)
    at com.intellij.openapi.externalSystem.util.ExternalSystemUtil.refreshProject(ExternalSystemUtil.java:381)
    at com.android.tools.idea.gradle.project.sync.idea.IdeaGradleSync.sync(IdeaGradleSync.java:169)
    at com.android.tools.idea.gradle.project.sync.GradleSyncInvoker.sync(GradleSyncInvoker.java:241)
    at com.android.tools.idea.gradle.project.sync.GradleSyncInvoker.lambda$requestProjectSync[=24=](GradleSyncInvoker.java:128)
    at com.intellij.openapi.application.TransactionGuardImpl.runSyncTransaction(TransactionGuardImpl.java:88)
    at com.intellij.openapi.application.TransactionGuardImpl.submitTransactionAndWait(TransactionGuardImpl.java:153)
    at com.android.tools.idea.gradle.project.sync.GradleSyncInvoker.requestProjectSync(GradleSyncInvoker.java:145)
    at com.android.tools.idea.gradle.project.importing.GradleProjectImporter.openOrImportProject(GradleProjectImporter.java:210)
    at com.android.tools.idea.gradle.project.importing.GradleProjectImporter.openOrImportProject(GradleProjectImporter.java:110)
    at com.android.tools.idea.gradle.project.importing.GradleProjectImporter.importProject(GradleProjectImporter.java:96)
    at com.android.tools.idea.actions.AndroidImportProjectAction.createImportWizard(AndroidImportProjectAction.java:201)
    at com.android.tools.idea.actions.AndroidImportProjectAction.selectFileAndCreateWizard(AndroidImportProjectAction.java:163)
    at com.android.tools.idea.actions.AndroidImportProjectAction.selectFileAndCreateWizard(AndroidImportProjectAction.java:143)
    at com.android.tools.idea.actions.AndroidImportProjectAction.actionPerformed(AndroidImportProjectAction.java:102)
    at com.intellij.ui.components.labels.ActionLink.linkSelected(ActionLink.java:66)
    at com.intellij.ui.components.labels.LinkLabel.doClick(LinkLabel.java:156)
    at com.intellij.ui.components.labels.ActionLink.doClick(ActionLink.java:79)
    at com.intellij.ui.components.labels.LinkLabel$MyMouseHandler.mouseReleased(LinkLabel.java:338)
    at java.awt.Component.processMouseEvent(Component.java:6541)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
    at java.awt.Component.processEvent(Component.java:6306)
    at java.awt.Container.processEvent(Container.java:2237)
    at java.awt.Component.dispatchEventImpl(Component.java:4897)
    at java.awt.Container.dispatchEventImpl(Container.java:2295)
    at java.awt.Component.dispatchEvent(Component.java:4719)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4889)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4526)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4467)
    at java.awt.Container.dispatchEventImpl(Container.java:2281)
    at java.awt.Window.dispatchEventImpl(Window.java:2746)
    at java.awt.Component.dispatchEvent(Component.java:4719)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:764)
    at java.awt.EventQueue.access0(EventQueue.java:98)
    at java.awt.EventQueue.run(EventQueue.java:715)
    at java.awt.EventQueue.run(EventQueue.java:709)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:90)
    at java.awt.EventQueue.run(EventQueue.java:737)
    at java.awt.EventQueue.run(EventQueue.java:735)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:734)
    at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:822)
    at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:646)
    at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:366)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

我从同一个教程配置桌面 运行,图片如下:Desktop Configuration

完成后,我运行选择了桌面的程序,得到这个错误:

Could not execute build using Gradle distribution 'https://services.gradle.org/distributions/gradle-4.6-bin.zip'.

This is where I am stuck, everythin works fine when 运行 on android phone but when Desktop is selected this is the error I get.现在我遵循了互联网上的许多解决方案,但每个解决方案都进一步给出了其他错误,每个解决方案给出了不同的错误,所以我不能把所有的分支都放在这里。

此时我非常需要帮助,谢谢。

希望您正在使用 latest build 中的 gdx-setup.jar

按需禁用配置

  • 在您的 gradle.properties 文件中按需禁用配置,如下所示:

    org.gradle.configureondemand=false

  • 要在 Android Studio 设置中禁用按需配置,请选择 文件 > 设置(Android Studio > 首选项 Mac), select 左窗格中的 Compiler 类别,并清除 Configure on demand 复选框。


我目前为 LibGDX 使用以下版本组合,建议您更新其中的一些。

  1. buildToolsVersion "27.0.3"
  2. Android Gradle Plugin version: 3.1.3
  3. Gradle 4.6
  4. Android API 28
  5. Android Studio 3.1.3

编辑

您还可以 运行 您的 desktop module 使用 gradle 任务

  1. 使用终端

    • Select 使用视图的终端 => 工具窗口 => Android Studio 中的终端
    • 在终端上使用 gradlew desktop:run (Windows)
  2. 使用Run/Debug配置

    • 添加新配置
    • 选择Gradle
    • Gradle 项目: => Select :desktop 你项目的模块
    • 任务:=>输入run
    • 确定应用
    • Select 你的配置和 运行