Can't add gdx-tools to libgdx gradle project

北城余情 提交于 2019-12-10 02:39:46

问题


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?


回答1:


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.




回答2:


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!




回答3:


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

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




回答4:


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



来源:https://stackoverflow.com/questions/23742328/cant-add-gdx-tools-to-libgdx-gradle-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!