LibGdx 与 Android Studio 有多个错误
Posted
技术标签:
【中文标题】LibGdx 与 Android Studio 有多个错误【英文标题】:LibGdx having multiple errors with Android Studio 【发布时间】:2019-01-02 05:08:38 【问题描述】:一个多星期以来,我一直在尝试通过关注this tutorial 使用 android Studio 学习 LibGDX。我永远无法为桌面配置构建和运行。我在互联网上浏览了许多解决方案,但没有找到解决方案。下面我将展示有关我的项目和文件的所有详细信息。
很抱歉解释太长,但为了更好地分析,我必须显示所有错误和细节。
我对所有相关内容的版本是:
-
Android Studio 版本:3.1.3
SDK 工具:26.1.1
Android 平台版本:API 28 修订版 4
等级:4.6
Android 插件版本:3.1.0
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?
我选择NO,然后它告诉我:
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?
我再次选择NO,然后它说:
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.
我选择了“明天提醒我”。 同步成功!我通过在我的安卓手机上运行它来测试它,一切都很好,除了 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手机上运行时,每一个工作都很好,但选择桌面时,这是我得到的错误。现在我从互联网上跟踪了许多解决方案,但每个解决方案都进一步给出了其他错误,每个解决方案都给出了不同的错误,所以我不能把所有的分支都放在这里。
我现在非常需要帮助,谢谢。
【问题讨论】:
禁用按需配置 org.gradle.configureondemand=false,默认设置为false 【参考方案1】:希望您使用的是 gdx-setup.jar
或 latest build。
按需禁用配置
在您的gradle.properties
文件中禁用按需配置,如下所示:
org.gradle.configureondemand=false
要在 Android Studio 设置中禁用按需配置,请选择 File > Settings(在 Mac 上为 Android Studio > Preferences),在左窗格,然后清除 按需配置 复选框。
我目前正在为 LibGDX 使用以下版本组合,建议您更新其中的一些。
buildToolsVersion "27.0.3"
Android Gradle Plugin version: 3.1.3
Gradle 4.6
Android API 28
Android Studio 3.1.3
编辑
您也可以使用gradle
任务运行您的desktop module
使用终端
在 Android Studio 中使用 View=>
Tool Window =>
Terminal 选择终端
在终端 (Windows) 上使用 gradlew desktop:run
使用运行/调试配置
添加新配置 选择 Gradle Gradle 项目:=>
选择您项目的:desktop
模块
任务: =>
输入 run
确定和应用
选择你的配置并运行
【讨论】:
好的,所以我遵循了您的解决方案并清除了按需配置复选框,现在当我按下运行时,我收到以下消息“C:\Program Files\Android\Android Studio\jre\bin\ java" "-javaagent:C:\Program Files\Android\Android Studio\lib\... 错误:无法找到或加载主类 com.saad.game.desktop.DesktopLauncher 进程以退出代码 1 结束 再次尝试运行 嘿,我不知道,但我再次点击运行,它成功了!非常感谢雅利安 :) 我的荣幸 :) 你也可以使用 gradle 配置运行 哦,再次感谢伙计。我在互联网上阅读了其他解决方案,人们说他们可以从终端运行,但我无法理解,但现在我知道了:D以上是关于LibGdx 与 Android Studio 有多个错误的主要内容,如果未能解决你的问题,请参考以下文章
如何在Android Studio中调试“桌面”libgdx应用程序
LibGDX - 无法从 Android Studio 运行 destop 版本
LibGDX 文件未在 Android Studio 上首次加载
libGDX - Android Studio 中的 Google Play 游戏服务