2017-07-14 29 views
0

私はkotlinで初心者ですが、私はAndroidスタジオ(kotlinなし)でNDKを正常に設定しました。Androidスタジオ3.0でKotlinでNDKを設定する方法

現在、Googleではkotlinを導入していますので、NDKサポートで既存のプロジェクトをkotlinに変更したいと考えています。

これは私のJavaコード

static 
{ 
    System.loadLibrary("native-lib"); 
} 
public native String stringFromJNI(int i); 

であるあなたはミディアムでこの記事を読むことができkotlin

+0

あなたは他にKotlinを設定してみてくださいましたNDK?その間に何か問題が発生しましたか? – zsmb13

+0

あなたはお読みください:https://developer.android.com/kotlin/faq.html –

+0

@ zsmb13はい私はエラーなしでセットアップしました – jarvis

答えて

0

で同じコードを実行する方法を、私を助けてください:この記事ではAndroid NDK: Interaction of Kotlin and C/C++

を、著者はどのように見ましたKotlinをC/C++と通信させる。例については

Kotlinコード:

class Store { 

    companion object { 
     init { 
      System.loadLibrary("Store") 
     } 
    } 

    @Throws(IllegalArgumentException::class) 
    external fun getString(pKey: String): String 
} 

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'; 
    } 
} 

サンプル:https://github.com/KucherenkoIhor/KotlinWithAndroidNdk

関連する問題