【问题标题】:How to add dependencies to libgdx project?如何将依赖项添加到 libgdx 项目?
【发布时间】:2016-04-05 17:30:00
【问题描述】:

我创建了一个没有 freetype 字体扩展的 Libgdx 项目,后来意识到我需要它。

我将依赖项添加到 build.gradle 文件并重新刷新了 gradle 构建(在 eclipse 中,对于每个项目,右键单击->Gradle->Refresh Gradle Project)但仍然无法使用该库。尝试导入某些内容时,我得到“无法解析导入 com.badlogic.gdx.graphics.g2d.freetype”。

我做错了什么或错过了什么?

这是我的 build.gradle 文件:

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

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

    version = '1.0'
    ext {
        appName = "X"
        gdxVersion = '1.9.0'
        roboVMVersion = '1.12.0'
        box2DLightsVersion = '1.4'
        ashleyVersion = '1.7.0'
        aiVersion = '1.7.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-freetype-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"

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

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


    dependencies {
        compile "com.badlogicgames.gdx:gdx:$gdxVersion"

        compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
    }
}

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

谢谢!

【问题讨论】:

  • 你的构建看起来不错,我也有同样的效果,它可以工作。我想问题出在eclipse上。尝试运行 clean 并再次重建您的项目。

标签: eclipse gradle libgdx dependencies


【解决方案1】:

需要刷新 Gradle 依赖

    Right click on your project -> Gradle -> Refresh All

【讨论】:

  • 我没有那个选项。我必须在每个项目中配置 -> 转换为 Gradle 项目才能出现第二个 Gradle 菜单(!)。然后在第二个菜单中刷新 gradle 依赖项。 Eclipse 很奇怪。谢谢。
猜你喜欢
  • 2015-07-27
  • 2023-03-19
  • 2017-03-27
  • 1970-01-01
  • 1970-01-01
  • 2015-02-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多