LibGDX 文件第一次未在 Android Studio 上加载

LibGDX file not loading for first time on Android Studio

所以,我是 LibGDX 的新手,这是我第一次创建项目。当我创建它时,我将它设置为常规的东西,获取我的 SDK 路径并输入它,使网站成为 com.example.MY_COMPUTER_NAME.gametest。我生成了项目,然后转到 Android Studio(我做了它,所以我只为 android 顺便说一句开发它),从我在 android 中创建的文件导入项目文件在我的桌面上的一个编程文件中,然后让它加载。但是,在同步 Gradle 时,弹出了几个错误,并且 运行 应用程序的能力也不起作用。以下是错误:

android/build.gradle 内部错误:

Warning:An 'android' block should only appear in build files that correspond to a module and have an 'apply plugin: 'com.android.application'' or 'apply plugin: 'com.android.library'' statement.

这是 android/build.gradle 的代码,错误将我指向:

android {
    buildToolsVersion "22.0.1"
    compileSdkVersion 22
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
            jniLibs.srcDirs = ['libs']
        }

        instrumentTest.setRoot('tests')
    }
}

此外,在该文件的顶部,它给出了一条警告:

This folder does not belong to a Gradle project. Make sure it is registered in settings.gradle.

这是 settings.gradle 的代码:include 'android', 'core'

接下来,项目的 build.gradle 中有两个错误,而不是 android 或核心的 gradle 文件。一个是这样的:

Warning:(36, 4) A 'dependencies' block doesn't belong here.

选择跳到源时,该错误会导致此代码:

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-x86"
    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-x86"
}

项目 build.gradle 的另一个错误是:

Warning:(53, 4) A dependencies block doesn't belong here.

跳转到源码时该代码引出这段代码:

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

最后,最后一个错误会导致项目的,而不是 android 或核心的 local.properties 文件:

Error:(1, 8) Windows file separators () must be escaped (\); use C:/Users/MY_COMPUTER_NAME/AppData/Local/Android/android-sdk

这是整个 local.properties 文件的代码:

# Location of the android SDK
sdk.dir=C:/Users/MY_COMPUTER_NAME/AppData/Local/Android/android-sdk

最后一个对我来说没有任何意义,因为推荐的文件路径和设置的文件路径是相同的。无论如何,我完全迷路了,不知道有什么办法可以帮助这个事业。提前感谢任何可能帮助我的人,请向我询问您可能需要的任何澄清。谢谢。

编辑

错误日志中也有这样的错误:

Failed to set up Android modules in project 'LibGDXTest2': Unsupported method: BaseArtifact.getJavaCompileTaskName(). The version of Gradle you connect to does not support that method. To resolve the problem you can change/upgrade the target version of Gradle you connect to. Alternatively, you can ignore this exception and read other information from the model.

据说是 UnsupportedMethodException。顺便说一句,我使用的是 Android Studio 0.8.6 版和 LibGDX 1.6.4 版。

希望我没记错,但我要说的是,您所有的问题主要是因为您使用的是 Android Studio 的过时版本。 Upgrade or use IntelliJ Idea,这基本上是一回事。还要确保您的 Android SDK 是最新的。

还有一件事:您是否尝试 "open" 您已经尝试 "import" 的项目?我希望它现在被打破。生成一个新的并打开它(在升级的工作室中!)。

编辑:并且总是 运行 工作室作为管理员。