你可以閱讀中這個帖子:Android NDK: Interaction of Kotlin and C/C++
在這篇文章中,筆者看到了如何讓Kotlin與C/C++進行溝通。
例如:
科特林代碼:這裏
extern "C"
JNIEXPORT void JNICALL
Java_com_ihorkucherenko_storage_Store_setString(
JNIEnv* pEnv,
jobject pThis,
jstring pKey,
jstring pString) {
StoreEntry* entry = allocateEntry(pEnv, &gStore, pKey);
if (entry != NULL) {
entry->mType = StoreType_String;
jsize stringLength = pEnv->GetStringUTFLength(pString);
entry->mValue.mString = new char[stringLength + 1];
pEnv->GetStringUTFRegion(pString, 0, stringLength, entry->mValue.mString);
entry->mValue.mString[stringLength] = '\0';
}
}
樣品:
class Store {
companion object {
init {
System.loadLibrary("Store")
}
}
@Throws(IllegalArgumentException::class)
external fun getString(pKey: String): String
}
C++代碼https://github.com/KucherenkoIhor/KotlinWithAndroidNdk
你嘗試除了設立科特林NDK?這樣做時你遇到任何問題嗎? – zsmb13
你讀過了:https://developer.android.com/kotlin/faq.html –
@ zsmb13是的我已經安裝了沒有任何錯誤 – jarvis