简体   繁体   中英

Gradle how to add native dependency? [Libgdx]

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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM