我正在尝试根据说明创建一个运行 TexturePacker 的 gradle 任务 here . (请注意,我使用的是 Android Studio 及其目录结构,而不是 Eclipse。)我首先将以下内容添加到 Android Studio 项目的 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])
}
}
这给出了错误
unable to resolve class com.badlogic.gdx.tools.texturepacker.TexturePacker
将 texturePacker
任务移动到桌面项目中的 build.gradle
会产生相同的错误。根据http://www.reddit.com/r/libgdx/comments/2fx3vf/could_not_find_or_load_main_class_texturepacker2/ ,我还需要将 compile "com.badlogicgames.gdx:gdx-tools:$gdxVersion"
添加到桌面项目依赖项下的根 build.gradle
中。当我这样做时,我仍然遇到同样的错误。
所以我有几个问题:
texturePacker
任务的正确位置在哪里?我应该把它放在哪个build.gradle
中?如何解决依赖问题和
unable to resolve class...
错误?在使用 gradle 运行时,如何指定输入和输出目录以及图集文件? (假设前两个问题都解决了。)
最佳答案
我通过将 gdx-tools 添加到我的构建脚本依赖项来让它工作:
buildscript{
dependencies {
...
classpath 'com.badlogicgames.gdx:gdx-tools:1.5.4'
}
}
通过这样做,我桌面的 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])
}
}
请注意,您的桌面项目的 ext 需要定义 texturePacker:
project.ext {
mainClassName = "your.game.package.DesktopLauncher"
assetsDir = new File("../android/assets");
texturePacker = ["../images/sprites", "../android/assets", "sprites"]
}
关于android - LibGDX 的 TexturePacker 与 gradle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30856278/