繁体   English   中英

无法在Netbeans上编译libGDX

[英]Can't compile libGDX on Netbeans

我正在尝试使用Netbeans建立一个简单的libGDX项目。 不幸的是,我的编译器似乎无法找到任何链接到的libGDX jar。 是不是Gradle应该自动为您找到并安装所有依赖项? 无论如何,当我尝试“运行”桌面项目时,编译器会给我这个:

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 jar放在我的类路径上,但我不确定这些罐子是什么或在哪里找到它们。

我记得大约一年半前做过这件事而没有遇到任何问题。 我不确定我做错了什么。


所以我能够通过修补我的build.gradle文件来解决我的问题,该文件的代码取自早期版本的setup插件生成的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项目给了我关于“依赖性解析失败”的错误消息,我不知道如何修复。 我有点好奇为什么设置工具没有生成任何依赖信息。


我刚刚尝试使用最新版本的安装插件再次生成项目,这次工作正常。 不确定为什么我的依赖项第一次都是空白的。

我也有同样的问题。

尝试在我的计算机上添加第三方扩展时,libgdx安装程序导致运行时异常。 异常发生后,通常显示的常用生成器对话框之一无法显示。

  • 我生成了一个新项目而没有尝试添加任何第三方扩展,我得到了一个成功的项目,我现在可以很好地导入到eclipse中。

暂无
暂无

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

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