作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在我的一个移动应用程序中将代码从 Java 转换为 Kotlin,在 Java 中运行的代码在 Kotlin 中停止运行。它使用JNI桥来调用C++代码。
Kotlin 方法声明:
class Converter{
companion object {
external fun convertNative(width: Int, height: Int, row: Int, input: ByteArray, ft: Int, output: ByteArray)
}
}
.cc代码:
extern "C" {
JNIEXPORT void JNICALL OBJECT_TRACKER_METHOD(convertNative)(JNIEnv* env, jobject thiz, jint width, jint height, jint row,
jbyteArray input, jint ft, jbyteArray output);
}
JNIEXPORT void JNICALL OBJECT_TRACKER_METHOD(convertNative)(
JNIEnv* env, jobject thiz, jint width, jint height, jint row,
jbyteArray input, jint ft, jbyteArray output) {...}
我得到的错误:
java.lang.UnsatisfiedLinkError:No implementation found for void com.sampleapp.Converter$Companion.convertNative(int,int,int,byte[],int,byte[])(tried Java_com_sampleapp_Converter_00024Companion_convertNative and Java_com_sampleapp_Converter_00024Companion_convertNative__III_3BI_3B) at com.sampleapp.Converter$Companion.convertNative(Native Method)...
原来的JAVA方法(这个效果很好)
protected static native void convertNative(
int width, int height, int row, byte[] input, int ft, byte[] output);
在这两种情况下,库都使用 System.loadLibrary 正确加载(我看到正确的日志输出,没有错误)。
最佳答案
如果您想避免更改 C++ 代码,您应该使用 @JvmStatic
注释 Kotlin 函数,即:
@JvmStatic external fun convertNative(width: Int, height: Int, row: Int, input: ByteArray, ft: Int, output: ByteArray)
顺便说一句,您的 C++ 函数声明在技术上是不正确的:对于静态方法,第二个参数是 jclass
,而不是 jobject
。
关于java - 伴随对象 Kotlin JNI 中的 UnsatisfiedLinkError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59068495/
我有两个伴随的仿函数,即它们成对出现如果一个是 doX() ,另一个将是 undoX()。 它们是这样声明的: template struct doSomething{
我想看看是否有任何工具或引擎可以将 Ecore(元)模型转换为合金规范? 如果它在考虑伴随的 OCL 表达式的情况下进行这种翻译,那就太好了 :) 谢谢 最佳答案 关于在 Alloy 和 UML 之间
所以我正在按照 ASP.NET 和 MVC 5 一书中的示例进行操作。这是导致错误的 View : @model SportsStore.WebUI.Models.ProductsListViewMo
我是一名优秀的程序员,十分优秀!