一个多星期以来,我一直在按照this tutorial尝试通过Android Studio学习LibGDX。我永远无法为桌面配置构建和运行。我在互联网上经历了许多解决方案,但没有解决方案。下面,我将显示有关我的项目和文件的所有详细信息。
很抱歉,我做了冗长的解释,但我必须显示所有错误和详细信息,以便进行更好的分析。
我所有相关内容的版本是:
这是我在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.
我选择了“提醒我明天”。 同步成功!我通过在我的android手机上运行它进行了测试,除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$10(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$0(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$2(MultipleBuildsView.java:163)
at com.intellij.build.MultipleBuildsView.lambda$onEvent$3(MultipleBuildsView.java:288)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:762)
at java.awt.EventQueue.access$500(EventQueue.java:98)
at java.awt.EventQueue$3.run(EventQueue.java:715)
at java.awt.EventQueue$3.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$0(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$1.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.access$500(EventQueue.java:98)
at java.awt.EventQueue$3.run(EventQueue.java:715)
at java.awt.EventQueue$3.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$4.run(EventQueue.java:737)
at java.awt.EventQueue$4.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'.
这是我遇到的问题,在Android手机上运行时,一切都可以正常工作,但是当选择“桌面”时,这是我得到的错误。现在,我遵循了许多来自Internet的解决方案,但是每个解决方案都进一步提出了其他错误,每个解决方案都提出了不同的错误,因此我无法将所有分支都放在这里。
在这一点上,我非常需要帮助,谢谢。
答案 0 :(得分:1)
希望您使用的是latest build中的gdx-setup.jar
。
按需禁用配置
按需禁用gradle.properties
文件中的配置,如下所示:
org.gradle.configureondemand=false
要在Android Studio设置中按需禁用配置,请选择文件>设置(在Mac上为Android Studio>首选项),然后在菜单中选择 Compiler 类别。左窗格,然后清除按需配置复选框。
我目前正在为LibGDX使用以下版本组合,建议您更新其中的一些。
buildToolsVersion "27.0.3"
Android Gradle Plugin version: 3.1.3
Gradle 4.6
Android API 28
Android Studio 3.1.3
编辑
您还可以使用desktop module
任务来运行gradle