简体   繁体   English

如何将 Kotlin + JNI android 库发布到 Bintray?

[英]How to publish Kotlin + JNI android library to Bintray?

I've been developing a library to use in my project, and while it is working locally, I would like to share it and use it as an external dependency.我一直在开发一个库以在我的项目中使用,当它在本地工作时,我想共享它并将其用作外部依赖项。

How do I wrap my library so that built AAR contains both *.so native library and generated *.java classes (generated by Kotlin compiler) ?如何包装我的库,以便构建的 AAR 包含*.so本机库和生成的*.java类(由 Kotlin 编译器生成)? Because there are two-way interactions in my library: Kotlin external functions defined in C++, and some C++ code calling Kotlin classes and methods.因为我的库中有两种交互方式:C++ 中定义的 Kotlin 外部函数,以及一些调用 Kotlin 类和方法的 C++ 代码。

So, my questions are:所以,我的问题是:

  • How to correctly package Kotlin + JNI android library ?如何正确打包 Kotlin + JNI android 库?
  • How to upload said package to Bintray so users (and myself) could use it as a dependency ?如何将所述包上传到 Bintray 以便用户(和我自己)可以将其用作依赖项?

(Note: I've seen tutorials and examples, but they were either Kotlin/Android or Java/Jni/Android) (注意:我看过教程和例子,但它们要么是 Kotlin/Android 要么是 Java/Jni/Android)

If you want to package .so with your application, note that you can always put it inside JAR file.如果您想将.so与您的应用程序一起打包,请注意您始终可以将其放入JAR文件中。 Then, you can unpack it, and load it using System.load .然后,您可以解压缩它,并使用System.load加载它。

You can find sample here: https://github.com/mkowsiak/jnicookbook/tree/master/recipes/recipeNo031您可以在这里找到示例: https : //github.com/mkowsiak/jnicookbook/tree/master/recipes/recipeNo031

Note笔记

Remember that packaging .so inside application is a risky thing.请记住,在应用程序中打包.so是一件有风险的事情。 As you deal with native code, you have to be 100% sure that all native dependencies are there.在处理本机代码时,您必须 100% 确定所有本机依赖项都在那里。 You have to pay attention to architecture as well.你也必须注意架构。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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