简体   繁体   中英

LibGDX file not loading for first time on Android Studio

So, I'm completely new to LibGDX, this is my first time creating a project. When I created it, then I set it to the regular stuff, got my SDK path and entered it, made the website be com.example.MY_COMPUTER_NAME.gametest . I generated the project, and went over to Android Studio (I made it so I'm only developing it for android BTW), imported the project from a file I made in an android file in a programming file in my desktop, and let it load. But, when synchronizing the Gradle, several errors popped up, and the ability to run the application is not working either. Here are the errors:

Error inside of 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.

Here is the code of android/build.gradle that the error is directing me to:

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')
    }
}

Also, at the top of that file, it gives a warning that says:

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

Here is the code for settings.gradle: include 'android', 'core' .

Next, there are two errors in the project's build.gradle , not the android's or core's gradle file. One is this:

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

That error, when selected to jump to source, leads to this code:

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

The other error for the project's build.gradle is:

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

That code leads to this code when jumping to the source:

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

Finally, there is this last error that leads to the project's, and not the android nor core's, local.properties file:

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

Here is the code of the entire local.properties file:

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

That last one doesn't make any sense to me since the recommended file path and set file path are the same. Anyway, I'm completely lost, and don't know any way to help the cause. Thanks in advance to anyone who may help me out, and please question me about any clarifications you may need. Thank you.

EDIT

There's also an error in the error log that says this:

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.

That's said to be an UnsupportedMethodException . BTW I'm using Android Studio version 0.8.6, and LibGDX version 1.6.4.

I hope I'm not wrong, but I'd say all your problems come mainly from the fact that you're using an obsolete version of Android Studio. Upgrade or use IntelliJ Idea , which is bascially the same thing. Also make sure your Android SDK is up to date.

And one more thing: did you try to "open" the project you already tried to "import"? I'd expect it to be broken now. Generate a new one and open that instead (in the upgraded studio!).

EDIT: And always run studio as admin.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM