8

I am attempting to create a gradle task which runs TexturePacker according to the instructions here. (Note that I am using Android Studio and its directory structure rather than Eclipse.) I first added the following to the Android Studio project's build.gradle:

import com.badlogic.gdx.tools.texturepacker.TexturePacker
task texturePacker << {
  if (project.ext.has('texturePacker')) {
    logger.info "Calling TexturePacker: "+texturePacker
    TexturePacker.process(texturePacker[0], texturePacker[1], texturePacker[2])
  }
}

This gave the error

unable to resolve class com.badlogic.gdx.tools.texturepacker.TexturePacker

Moving the texturePacker task to build.gradle in the desktop project produces the same error. According to http://www.reddit.com/r/libgdx/comments/2fx3vf/could_not_find_or_load_main_class_texturepacker2/, I also need to add compile "com.badlogicgames.gdx:gdx-tools:$gdxVersion" to the root build.gradle under the desktop project's dependencies. When I do so, I still get the same error.

So I have several questions:

  1. Where is the correct place for the texturePacker task? Which build.gradle do I put this in?

  2. How do I solve the dependency issue and the unable to resolve class... error?

  3. How do I specify the input and output directories and the atlas file when running this with gradle? (Assuming the first two questions are solved.)

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268

1 Answers1

11

I got it working by adding gdx-tools to my buildscript dependencies:

buildscript{
    dependencies {
       ...
       classpath 'com.badlogicgames.gdx:gdx-tools:1.5.4'
    }
}

by doing this, my desktop's build.gradle was able to import the texture packer class:

import com.badlogic.gdx.tools.texturepacker.TexturePacker
task texturePacker << {
    if (project.ext.has('texturePacker')) {
        logger.info "Calling TexturePacker: "+ texturePacker
        TexturePacker.process(texturePacker[0], texturePacker[1], texturePacker[2])
    }
}

please note that your desktop project's ext will need to have texturePacker defined:

project.ext {
    mainClassName = "your.game.package.DesktopLauncher"
    assetsDir = new File("../android/assets");
    texturePacker = ["../images/sprites", "../android/assets", "sprites"]
}
Xavier Guzman
  • 460
  • 3
  • 11
  • This is working but i had to change " to ' in the input/output path. Now how do i set the maxWidth and maxHeight? i tried def settings = new TexturePacker.Settings() settings.maxHeight = 4096 settings.maxWidth = 2048, but it failes with general error. – Shirane85 Apr 18 '16 at 08:35
  • 1
    I usually just [add a pack.json](https://github.com/libgdx/libgdx/wiki/Texture-packer#configuration) in my folders – Xavier Guzman May 10 '16 at 18:00
  • An improvement to this solution would be to name the Strings in `texturePacker` more meaningfully rather than using an array. – Code-Apprentice Sep 17 '16 at 23:03