简体   繁体   中英

Can't add gdx-tools to libgdx gradle project

I'm new in Gradle. I'm trying to add gdx-tools to my project:

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"   
        compile "com.badlogicgames.gdx:gdx-tools:$gdxVersion"
    }
}

I open my Desktop project, folder "Gradle Dependecies" and see "gdx-tools-1.0.1.jar". As I try to open it - nothing shows.

So, when I try to use it ( I want to try pack images to atlas) - I can't import com.badlogic.gdx.tools...

What I do wrong?

I had the same problem. So I put "com.badlogicgames.gdx:gdx-tools:1.9.2" into my browser to see where it took me. (1.9.2 being my gdxVersion) Sure enough it did not take me to a page but to a search result. I followed the first one:

http://mvnrepository.com/artifact/com.badlogicgames.gdx/gdx-tools/1.5.2

Which says there is a new version - 1.9.2 (well, duh - that's what I'm trying to reach. Thankfully, there's a link and I follow it.)

http://mvnrepository.com/artifact/com.badlogicgames.gdx/gdx-tools/1.9.2

Now, in the upper center of the page you'll see a tabbed box with code in the middle. Select Gradle and copy that code.

Back in your Gradle file add:

compile (paste)

Or, in my particular case:

compile 'com.badlogicgames.gdx:gdx-tools:1.9.2'

Now hit sync. This worked but I was worried about hard coding the gdxVersion number so I played around. If you replace the 1.9.2 with $gdxVersion and the single quotes (') with double quotes (") it should sync. So now my Gradle line looks like this:

compile "com.badlogicgames.gdx:gdx-tools:$gdxVersion"

Why? This seems identical to the version I tried first. I don't know. But these are the steps that led to a successful sync for me.

On this site they give you a detailed explanation on how to update your dependencies.

https://github.com/libgdx/libgdx/wiki/Dependency-management-with-Gradle#tools-gradle

After you put in what they say in the gradle, right click on your project and do gradle -> refresh dependencies.

I don't know if it really helps, but hopefully it can help someone!

If you use modern IDEA or Android Studio, then any time you need new dependency to be downloaded, just add

compile "group:artifact:version"

inside dependencies {} section (like you've done), click“将项目与 gradle 文件同步”

and wait for gradle build/indexing to finish.

Also, in your case, check that $gdxVersion is correct. You must have something like:

buildscript {
    ext {
        gdxVersion = '1.6.0'
    }
}

You can also create a task in your project just to print it:

task someName << {
  println $gdxVersion
}

then call it from command line:

./gradlew -q someName

Also you can check out that repo - it has optimized gradle files, so it builds somewhat faster. At least it was so, I don't watch what the libgdx guys were doing for some time

I got the same problem. My solution is - go Project/Structure, search gdx library by name "gdx", add this library to your project, and then you'll be able to add gdx-tools to your build.gradle.

Did you use the gdx-setup.jar file to create your project ? You can find it in the wiki, it is the official way to create a new project

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