如何将库添加到LIBGDX项目的Gradle依赖项中

3

问题已经说得很清楚了,我尝试了所有在SO和其他网站上找到的答案,但都没有成功。这是我迄今为止尝试过的方法:

compile fileTree(dir: 'lib', include: '*.jar')添加到我的build.gradle中

compile files('lib/tween-engine-api-sources.jar')添加到build.gradle中

我想要添加的库是Tween engine

build.gradle文件:

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

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

    version = '1.0'
    ext {
        appName = 'my-gdx-game'
        gdxVersion = '1.5.4'
        roboVMVersion = '1.0.0-SNAPSHOT'
        box2DLightsVersion = '1.3'
        ashleyVersion = '1.3.1'
        aiVersion = '1.5.0'
    }

    repositories {
        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"
        compile "com.badlogicgames.gdx:gdx-box2d-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"
        compile "com.badlogicgames.gdx:gdx-controllers-desktop:$gdxVersion"
        compile "com.badlogicgames.gdx:gdx-controllers-platform:$gdxVersion:natives-desktop"


    }
}

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


    dependencies {
        compile "com.badlogicgames.gdx:gdx:$gdxVersion"
        compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
        compile "com.badlogicgames.gdx:gdx-bullet:$gdxVersion"
        compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
        compile "com.badlogicgames.gdx:gdx-controllers:$gdxVersion"
        compile "com.badlogicgames.gdx:gdx-ai:$aiVersion"
        compile "com.badlogicgames.ashley:ashley:$ashleyVersion"
        compile "com.badlogicgames.box2dlights:box2dlights:$box2DLightsVersion"

        compile fileTree(dir: 'lib', include: '*.jar')

    }
}

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

1
请将您得到的错误添加到您的问题中。 - Tim Biegeleisen
完成 @TimBiegeleisen - ZEE
你是在安卓上开发这个吗? - Tim Biegeleisen
1个回答

3
在维基文章“使用Gradle进行依赖管理”中,您可以找到所有需要的信息。甚至还有一个关于Tween Engine的额外部分。
您的方法应该可行,但是您需要通过右键单击项目-> Gradle -> 刷新依赖项来更新Eclipse。
对我而言,更好的方法是在我的本地存储库中安装依赖项,然后从那里引用它,而不是引用lib文件夹。这在这里有描述。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接