1

Everybody!

I'm a newb in game development. And I'm following the tutorial in "Learning Libgdx Game Development" to create cross-platform 2D games. However, I'm using IntelliJ instead of Eclipse because IntelliJ seems like to help me out with my coding style.

My problem is: When I import a libgdx project to IntelliJ (using "gdx-setup"), everything works fine. Until I need an extension of libgdx called TexturePacker in "extensions/gdx-tools". I think I can add this .jar file as a normal library but it does not work.

Here is the errors I have got:

  • Error:(5, 44) Gradle: error: package com.badlogic.gdx.tools.texturepacker does not exist

I will appreciate your help. Thanks!

donfuxx
  • 11,277
  • 6
  • 44
  • 76
ntviet18
  • 752
  • 1
  • 10
  • 26

2 Answers2

2

Since your libgdx project is now built with gradle you will have to add the tools extension as a gradle dependency of your desktop project:

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

otherwise gradle won't compile (..and find) it.

This is explained in more detail at the libgdx project page

BTW: While setting up your project with the gdx-setup jar you can check the "tools" checkbox and it will generate a project that already has the tools dependency in the build.gradle file.

donfuxx
  • 11,277
  • 6
  • 44
  • 76
  • 1
    Thank you very much! When I followed the tutorial I didn't notice that useful options. – ntviet18 Jun 29 '14 at 18:26
  • seems like this is no longer relevant for Android, or am I missing something? https://github.com/libgdx/libgdx/wiki/Dependency-management-with-Gradle#tools-gradle – Yoav Feuerstein May 13 '15 at 20:16
  • @yoav85 I fear I am not understanding your question. What is no longer relevant, and why? – donfuxx May 13 '15 at 20:33
  • @donfuxx the link says that you shouldn't add this line to gradle files in Android enviroment - or did I misunderstood? – Yoav Feuerstein May 13 '15 at 20:49
  • 1
    Exactly. That is why I said in the answer that the _texturepacker_ dependency should only be added to the **desktop** project. It is not compatible with android and it does not need to be. It is just a tool for developers to conveniently create textureAtlases. – donfuxx May 13 '15 at 21:08
  • BTW. This question was only about the libgdx gradle files not the android-studio project ones. I assume this was the reason of the confusion. @yoav85 – donfuxx May 13 '15 at 21:51
-1

You have to add .jar file to all project files(android/desktop/html and source).Also try to use this one instead:

import com.badlogic.gdx.tools.texturepacker.TexturePacker;

AcarX
  • 289
  • 2
  • 10
  • Hi, thank you for your fast answer. But I already did exactly what you say before asked the question. However, IntellJ still reject all my efforts. Every time I refresh my project and then look back for the dependencies. All I have is unchecked library or worse is missing the library I added. – ntviet18 Jun 29 '14 at 18:03
  • I've googled your problem and saw that you are not the only one who suffers from IntellJ building problems.I would recommend Eclipse. You said you prefer IntellJ but there are a lot of editor settings that you can play with in Eclipse so you might be able to make it work for your own style of coding. – AcarX Jun 29 '14 at 18:07
  • Thank for your recommendations. But have spent sometimes with Eclipse since I was started programming in the university. I just switched to IntelliJ formally for a week (so I didn't read many documentations about it). It gives me more experiences and errors than Eclipse. So, I just like it :) – ntviet18 Jun 29 '14 at 18:32
  • Dont switch back to eclipse : that is really bad advice especially since google are backing intellij with their AS branch AND badlogic have moved to gradle builds. Also this answer above is plain wrong : you ONLY add the tools as a dependency on the Desktop build NOT the others. – RichieHH Nov 10 '14 at 21:34