Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: 3 months 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 (about 7 years ago)
- Default Branch: mpp-gradle
- Last Pushed: 2022-12-07T18:06:42.000Z (about 2 years ago)
- Last Synced: 2023-08-19T10:10:58.002Z (over 1 year ago)
- Topics: android, jni-android, kotlin, kotlin-native
- Language: Kotlin
- Homepage:
- Size: 197 KB
- Stars: 68
- Watchers: 5
- Forks: 16
- 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:
![](images/screen-shot.png)
Logcat :
![](images/log.png)