Gradle如何添加原生依赖?[Libgdx]

2022-01-12 00:00:00 windows gradle java libgdx maven

我有一个默认的 Libgdx Gradle 设置,我需要向其中添加我的简单文本渲染库.它由一个 .jar 文件和本机 lib 文件组成.

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.

这行 build.gradle 脚本似乎可以正常工作,它的作用是将 jfreetype.jar java 库添加到我的构建路径中.

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')

是否有像这样的魔术命令来添加我的文件系统上可用且未 Maven 化的本机库(准确地说是 .dll)?

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"

这行代码只是给了我一个错误,说在某个 repo 中找不到某些东西.我想应该有一条像 .jar 文件这样的神奇行来添加仅在我的文件系统上可用而不在某些 repo 上可用的本机文件.

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.

推荐答案

Gradle Natives 插件应该做你想做的事.您可以指定指向包含本机 dll/so 的 jar 文件的配置.然后,一个 gradle 任务unpackNatives"会将 dll/so 解压到构建目录中.

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.

根据您启动应用程序的方式,您可能仍需要告诉 Java 运行时在哪里可以找到 dll/so.在项目网站上有一些关于它是如何工作的信息:

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

相关文章