簡體   English   中英

伴隨對象Kotlin JNI中的UnsatisfiedLinkError

[英]UnsatisfiedLinkError in companion object Kotlin JNI

我正在其中一個移動應用程序中將代碼從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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM