https://github.com/bennyhuo/hello-kni
Demo for Jni call Kotlin-Native lib.
https://github.com/bennyhuo/hello-kni
android jni-android kotlin kotlin-native
Last synced: about 1 year ago
JSON representation
Demo for Jni call Kotlin-Native lib.
- Host: GitHub
- URL: https://github.com/bennyhuo/hello-kni
- Owner: bennyhuo
- License: apache-2.0
- Created: 2018-01-28T23:10:25.000Z (over 8 years ago)
- Default Branch: mpp-gradle
- Last Pushed: 2022-12-07T18:06:42.000Z (over 3 years ago)
- Last Synced: 2025-04-14T22:54:12.792Z (about 1 year ago)
- Topics: android, jni-android, kotlin, kotlin-native
- Language: Kotlin
- Homepage:
- Size: 197 KB
- Stars: 96
- Watchers: 5
- Forks: 19
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Hello KNI
=========
This is a Demo of Jni calling Kotlin Native originated from Google's jni demo.
### Contents
Kotlin Native can interop with C directly. In order to call Kotlin Native functions from Java, we should use `CName` to annotated the functions with a proper name:
```kotlin
@CName("Java_com_example_hellojni_HelloJni_stringFromJNI")
fun stringFromJNI(env: CPointer, thiz: jobject): jstring {
memScoped {
return env.pointed.pointed!!.NewStringUTF!!.invoke(env, "This is from Kotlin Native!!".cstr.ptr)!!
}
}
```
What's in the demo:
* Uses of Android Log
* Return a Java String
* Call Java methods from Kotlin Native
### How to Build
Simply Build and run your app. Dependencies are carefully managed by gradle.
### Preview
Screen shot:

Logcat :
