2016-04-04 38 views
0

我创建了一个没有freetype字体扩展的Libgdx项目,后来意识到我需要它。如何向libgdx项目添加依赖关系?

我向build.gradle文件添加了依赖关系,并重新构建了gradle build(在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" 
} 

谢谢!

+0

你构建看起来不错,我有相同的,它的工作原理。我想这个问题是与日食。尝试运行clean并重新生成你的项目。 – Enigo

回答

1

需要刷新摇篮依赖性

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

Gradle "Refresh All" in Eclipse

+0

我没有这个选项。 我必须配置 - >在每个项目中转换为Gradle Project,以显示第二个Gradle菜单(!)。然后在第二个菜单中刷新gradle依赖关系。 Eclipse很奇怪。谢谢。 – Ivan