2016-06-01 64 views
1

我正在嘗試使用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項目給了我關於'依賴性解決失敗'的錯誤消息,我不知道該如何解決。我有點好奇,爲什麼安裝工具不生成任何依賴信息。


而我只是試着再次用最新版本的安裝插件生成項目,這次它工作。不確定爲什麼我的依賴關係在第一時間都是空白的。

回答

0

我也有同樣的問題。

的libgdx安裝程序試圖在我的機器上添加第三方擴展時,引起了運行時異常。發生異常之後,通常顯示的常用生成器對話框之一未能顯示。

  • 我生成了一個新的項目,而沒有嘗試添加任何第三方擴展,我得到了一個成功的項目,我現在可以很好地導入到Eclipse中。