Gradle how to add native dependency? [Libgdx]

与世无争的帅哥 提交于 2019-12-10 15:57:10

问题


I have a default Libgdx Gradle setup, and I need to add my simple text rendering library to it. It consists of a .jar file and native lib file.

This line of build.gradle script seems to work as I would expect, and what it does is add jfreetype.jar java library to my build path.

compile files('../local_lib/jfreetype.jar')

Is there a magic command like this to add native library (.dll to be exact) that is available on my file system and is not Mavenized?

natives "../local_lib/jfreetype32.dll"

This line of code just gives me an error saying that something cannot be found at some repo. I guess there should be a magical line like with .jar file to add native files that are available only on my file system and not on some repo.


回答1:


You can add a flat directory as a repository in this way, as mentioned in the dependency-management section in the Gradle User Guide.

repositories {
    flatDir {
        dirs '../local_lib'
    }
}

If you want to create your own dependency-configuration natives, create it like this (more info on the same page):

configurations {
    natives
}

Hope that helps.




回答2:


The Gradle Natives plugin should do what you want. You can specify a configuration that points at jar files that contain native dll/so. A gradle task "unpackNatives" will then unpack the dll/so into the build dirs.

Depending upon how you launch your application, you may still need to tell the Java runtime where to find the dll/so. There is some info about how this works at the project website:

https://github.com/cjstehno/gradle-natives



来源:https://stackoverflow.com/questions/28264221/gradle-how-to-add-native-dependency-libgdx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!