gpt4 book ai didi

android - 在libgdx游戏中配置groovy时出错

转载 作者:行者123 更新时间:2023-12-03 06:06:53 25 4
gpt4 key购买 nike

我几天前开始学习ligdx。我试图将groovy配置为可以在游戏的核心项目中使用,但是每次运行该应用程序时,都会遇到以下异常:

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


我的代码是:
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();


}
}
class testClass {

def scddsds(){
println('scddsds')
}
}
全局gradle文件为:
    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"
}
核心项目的构建是:
   apply plugin: "java"

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

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


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


我正在使用Android Studio。

最佳答案

最终,我设法使其正常运行。
首先必须配置全局build.gradle:

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'

}
}

我仅将groovy添加到了核心项目中,并且看起来工作正常。

然后添加到核心项目的gradle构建中:
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 {
}

有关带有源集的“魔术”的更多信息,请参见 this答案。

顺便说一句,我为groovy类创建了单独的文件夹,因此项目结构如下:
src   
--main
--java
--groovy

关于android - 在libgdx游戏中配置groovy时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38285929/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com