简体   繁体   English

无法将 gdx-tools 添加到 libgdx gradle 项目

[英]Can't add gdx-tools to libgdx gradle project

I'm new in Gradle.我是 Gradle 的新手。 I'm trying to add gdx-tools to my project:我正在尝试将 gdx-tools 添加到我的项目中:

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".我打开我的桌面项目,文件夹“Gradle Dependecies”并看到“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...因此,当我尝试使用它时(我想尝试将图像打包到图集)-我无法导入 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.所以我将“com.badlogicgames.gdx:gdx-tools:1.9.2”放入我的浏览器,看看它把我带到了哪里。 (1.9.2 being my gdxVersion) Sure enough it did not take me to a page but to a search result. (1.9.2是我gdxVersion)果然它没有带我去一个网页,而是一个搜索结果。 I followed the first one:我跟着第一个:

http://mvnrepository.com/artifact/com.badlogicgames.gdx/gdx-tools/1.5.2 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.)它说有一个新版本 - 1.9.2(好吧,呃 - 这就是我想要达到的。谢天谢地,有一个链接,我跟着它。)

http://mvnrepository.com/artifact/com.badlogicgames.gdx/gdx-tools/1.9.2 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.选择 Gradle 并复制该代码。

Back in your Gradle file add:回到您的 Gradle 文件中,添加:

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.这行得通,但我担心硬编码 gdxVersion 数字,所以我玩了一下。 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:如果你用 $gdxVersion 替换 1.9.2 并且用双引号 (") 替换单引号 (') 它应该同步。所以现在我的 Gradle 行看起来像这样:

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 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.在将他们所说的放入 gradle 后,右键单击您的项目并执行 gradle -> 刷新依赖项。

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如果您使用现代 IDEA 或 Android Studio,那么任何时候您需要下载新的依赖项,只需添加

compile "group:artifact:version"

inside dependencies {} section (like you've done), click在依赖项 {} 部分(就像您所做的那样),点击“将项目与 gradle 文件同步”

and wait for gradle build/indexing to finish.并等待 gradle 构建/索引完成。

Also, in your case, check that $gdxVersion is correct.另外,在您的情况下,请检查 $gdxVersion 是否正确。 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.您也可以查看该repo - 它优化了 gradle 文件,因此构建速度更快。 At least it was so, I don't watch what the libgdx guys were doing for some time至少是这样,我有一段时间不看 libgdx 人在做什么

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.我的解决方案是 - 转到 Project/Structure,按名称“gdx”搜索 gdx 库,将此库添加到您的项目中,然后您就可以将 gdx-tools 添加到您的 build.gradle 中。

Did you use the gdx-setup.jar file to create your project ?您是否使用 gdx-setup.jar 文件来创建您的项目? You can find it in the wiki, it is the official way to create a new project你可以在wiki中找到它,这是创建新项目的官方方式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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