2016-07-09 8 views
0

Ich begann zu lernen, ligdx vor einiger Zeit. Ich habe versucht, groovy zu konfigurieren im Kernprojekt des Spiels zu arbeiten, aber jedesmal, wenn ich die Anwendung ausführen ich erhalte diese Ausnahmen:Fehler beim Konfigurieren groovy in libgdx Spiel

Error:Gradle: Execution failed for task :core:compileJava.

Error:Cannot compile Groovy files: no Groovy library is defined for module 'core'

Compilation failed; see the compiler error output for details.

Error:(16, 23) Gradle: error: cannot find symbol class testClass

Error:(16, 23) Gradle: error: cannot find symbol class testClass

mein Code:

public class MyGdxGame extends ApplicationAdapter { 
SpriteBatch batch; 
Texture img; 

@Override 
public void create() { 
    batch = new SpriteBatch(); 
    img = new Texture("badlogic.jpg"); 
    testClass test = new testClass(); 
} 

@Override 
public void render() { 
    Gdx.gl.glClearColor(1, 0, 0, 1); 
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); 
    batch.begin(); 
    batch.draw(img, 0, 0); 
    batch.end(); 
} 

@Override 
public void dispose() { 
    batch.dispose(); 
    img.dispose(); 


} 
} 

und

class testClass { 

def scddsds(){ 
    println('scddsds') 
} 
} 

The Global gradle Datei ist:

buildscript { 
    repositories { 
     mavenLocal() 
     mavenCentral() 
     maven { url "https://oss.sonatype.org/content/repositories/snapshots/" } 
    } 
    dependencies { 
     classpath 'com.android.tools.build:gradle:2.0.0' 

    } 
} 

allprojects { 
    apply plugin: "eclipse" 
    apply plugin: "idea" 

    version = '1.0' 
    ext { 
     appName = "groovy-test" 
     gdxVersion = '1.9.3' 
     roboVMVersion = '2.1.0' 
     box2DLightsVersion = '1.4' 
     ashleyVersion = '1.7.0' 
     aiVersion = '1.8.0' 
    } 

    repositories { 
     mavenLocal() 
     mavenCentral() 
     maven { url "https://oss.sonatype.org/content/repositories/snapshots/" } 
     maven { url "https://oss.sonatype.org/content/repositories/releases/" } 
    } 
} 

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" 
    } 
} 

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-arm64-v8a" 
     natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86" 
     natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86_64" 
    } 
} 

project(":core") { 
    apply plugin: "java" 


    dependencies { 
     compile "com.badlogicgames.gdx:gdx:$gdxVersion" 
     compile 'org.codehaus.groovy:groovy:2.4.6:grooid' 
    } 
} 

tasks.eclipse.doLast { 
    delete ".project" 
} 

Der gradle Build des Kernprojektes ist:

apply plugin: "java" 

sourceCompatibility = 1.6 
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8' 

sourceSets.main.java.srcDirs = [ "src/" ] 


eclipse.project { 
    name = appName + "-core" 
} 

I Android Studio verwenden.

+0

teilen Sie Ihre 'build.gradle' – Enigo

+0

ich es geschrieben. bitte schau es dir an – RexsosTheAlien

Antwort

0

Endlich habe ich es geschafft zu arbeiten. Zum einem globalen build.gradle muss konfiguriert werden:

project(":core") { 
    apply plugin: "java" 
    apply plugin: "groovy" 

    dependencies { 
     compile "com.badlogicgames.gdx:gdx:$gdxVersion" 
     compile group: 'org.codehaus.groovy', name: 'groovy-all', version: '2.4.7' 

    } 
} 

Ich habe stark an das Kernprojekt nur und es scheint gut zu funktionieren.

Dann zum gradle Build des Kernprojektes fügte ich hinzu:

apply plugin: "java" 
apply plugin: "groovy" 
sourceCompatibility = 1.6 
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8' 
sourceSets { 
    main { 
     java { srcDirs = [] } 
     groovy { srcDir "src" } 
    } 
} 
eclipse.project { 
    name = appName + "-core" 
} 
dependencies { 
} 

Mehr Informationen zu dieser „Magie“ mit Quellensätzen in this Antwort gefunden werden können. BTW

ich erstellt separaten Ordner für groovy Klassen, so die Projektstruktur ist wie:

src 
--main 
    --java 
    --groovy 
+0

Vielen Dank für Hilfe !!! – RexsosTheAlien

+0

Als ich meinem Projekt Code hinzugefügt und es kompiliert habe, habe ich folgende Ausnahme: Error: Android Gradle Build Ziel: java.lang.StringIndexOutOfBoundsException: String-Index außerhalb des Bereichs: -92 – RexsosTheAlien

+0

ist das irgendwie mit der aktuellen Frage verbunden? Vielleicht lohnt es sich, noch einen zu fragen. – Enigo