我正在尝试使用Netbeans设置一个简单的libGDX项目。不幸的是,我的编译器似乎无法找到任何libGDX jar链接。 Gradle是否应该自动为您找到并安装所有依赖项?在任何情况下,编译器给我这个当我尝试“运行”中的桌面项目:无法在Netbeans上编译libGDX
Executing: gradle run
Arguments: [-c, C:\dev\starling2\game\2016\fightland\libgdx\settings.gradle]
Configuration on demand is an incubating feature.
warning: [options] bootstrap class path not set in conjunction with -source 1.6
C:\dev\starling2\game\2016\fightland\libgdx\core\src\com\kitfox\fightland\FightlandGdxGame.java:3: error: package com.badlogic.gdx does not exist
import com.badlogic.gdx.ApplicationAdapter;
^
C:\dev\starling2\game\2016\fightland\libgdx\core\src\com\kitfox\fightland\FightlandGdxGame.java:4: error: package com.badlogic.gdx does not exist
import com.badlogic.gdx.Gdx;
^
C:\dev\starling2\game\2016\fightland\libgdx\core\src\com\kitfox\fightland\FightlandGdxGame.java:5: error: package com.badlogic.gdx.graphics does not exist
import com.badlogic.gdx.graphics.GL20;
^
C:\dev\starling2\game\2016\fightland\libgdx\core\src\com\kitfox\fightland\FightlandGdxGame.java:6: error: package com.badlogic.gdx.graphics does not exist
import com.badlogic.gdx.graphics.Texture;
^
C:\dev\starling2\game\2016\fightland\libgdx\core\src\com\kitfox\fightland\FightlandGdxGame.java:7: error: package com.badlogic.gdx.graphics.g2d does not exist
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
^
C:\dev\starling2\game\2016\fightland\libgdx\core\src\com\kitfox\fightland\FightlandGdxGame.java:9: error: cannot find symbol
public class FightlandGdxGame extends ApplicationAdapter {
^
symbol: class ApplicationAdapter
C:\dev\starling2\game\2016\fightland\libgdx\core\src\com\kitfox\fightland\FightlandGdxGame.java:10: error: cannot find symbol
SpriteBatch batch;
^
symbol: class SpriteBatch
location: class FightlandGdxGame
C:\dev\starling2\game\2016\fightland\libgdx\core\src\com\kitfox\fightland\FightlandGdxGame.java:11: error: cannot find symbol
Texture img;
^
symbol: class Texture
location: class FightlandGdxGame
C:\dev\starling2\game\2016\fightland\libgdx\core\src\com\kitfox\fightland\FightlandGdxGame.java:13: error: method does not override or implement a method from a supertype
@Override
^
C:\dev\starling2\game\2016\fightland\libgdx\core\src\com\kitfox\fightland\FightlandGdxGame.java:15: error: cannot find symbol
batch = new SpriteBatch();
^
symbol: class SpriteBatch
location: class FightlandGdxGame
C:\dev\starling2\game\2016\fightland\libgdx\core\src\com\kitfox\fightland\FightlandGdxGame.java:16: error: cannot find symbol
img = new Texture("badlogic.jpg");
^
symbol: class Texture
location: class FightlandGdxGame
C:\dev\starling2\game\2016\fightland\libgdx\core\src\com\kitfox\fightland\FightlandGdxGame.java:19: error: method does not override or implement a method from a supertype
@Override
^
C:\dev\starling2\game\2016\fightland\libgdx\core\src\com\kitfox\fightland\FightlandGdxGame.java:21: error: package Gdx does not exist
Gdx.gl.glClearColor(1, 0, 0, 1);
^
C:\dev\starling2\game\2016\fightland\libgdx\core\src\com\kitfox\fightland\FightlandGdxGame.java:22: error: cannot find symbol
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
^
symbol: variable GL20
location: class FightlandGdxGame
C:\dev\starling2\game\2016\fightland\libgdx\core\src\com\kitfox\fightland\FightlandGdxGame.java:22: error: package Gdx does not exist
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
^
15 errors
1 warning
:core:compileJava FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':core:compileJava'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 2.246 secs
Build failure (see the Notifications window for stacktrace): gradle run
这是从libGDX项目设置实用程序刚生成的代码。我没有做任何改变。我尝试将根项目中的源代码级别更改为1.6,但这没有帮助。
另一篇文章我读建议对libGDX罐子上我的类路径,但我不知道这些罐子或在哪里可以找到他们。
我记得做这个大约一年半前,并没有遇到任何问题。我不确定我做错了什么。
所以我能够修补我的build.gradle文件,通过安装插件的早期版本生成的libGDX项目采取代码有所解决我的问题。基本上,由最新版本的gdx-setup.jar生成的build.gradle具有完全空的“依赖性”子句。我重写他们看起来像
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-bullet-platform:$gdxVersion:natives-desktop"
compile "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop"
compile "com.badlogicgames.gdx:gdx-tools:$gdxVersion"
}
}
project(":android") {
apply plugin: "android"
configurations { natives }
dependencies {
compile project(":core")
compile "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
compile "com.badlogicgames.gdx:gdx-bullet:$gdxVersion"
natives "com.badlogicgames.gdx:gdx-bullet-platform:$gdxVersion:natives-armeabi"
natives "com.badlogicgames.gdx:gdx-bullet-platform:$gdxVersion:natives-armeabi-v7a"
natives "com.badlogicgames.gdx:gdx-bullet-platform:$gdxVersion:natives-x86"
compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi"
natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi-v7a"
natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86"
compile "com.badlogicgames.gdx:gdx-ai:$aiVersion"
}
}
project(":ios") {
apply plugin: "java"
apply plugin: "robovm"
dependencies {
compile project(":core")
compile "org.robovm:robovm-rt:$roboVMVersion"
compile "org.robovm:robovm-cocoatouch:$roboVMVersion"
compile "com.badlogicgames.gdx:gdx-backend-robovm:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-ios"
compile "com.badlogicgames.gdx:gdx-bullet-platform:$gdxVersion:natives-ios"
compile "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-ios"
}
}
project(":html") {
apply plugin: "gwt"
apply plugin: "war"
dependencies {
compile project(":core")
compile "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion"
compile "com.badlogicgames.gdx:gdx:$gdxVersion:sources"
compile "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion:sources"
compile "com.badlogicgames.gdx:gdx-ai:$aiVersion:sources"
}
}
project(":core") {
apply plugin: "java"
dependencies {
compile "com.badlogicgames.gdx:gdx:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-bullet:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-ai:$aiVersion"
}
}
现在桌面项目将编译和运行。还没有试过android呢。 ios项目给了我关于'依赖性解决失败'的错误消息,我不知道该如何解决。我有点好奇,为什么安装工具不生成任何依赖信息。
而我只是试着再次用最新版本的安装插件生成项目,这次它工作。不确定为什么我的依赖关系在第一时间都是空白的。