Skip to content Skip to sidebar Skip to footer

Android: How To Call Ndk Function From Kotlin?

This code works on Java. But after migration to Kotlin, compiler higlits method native fun stringFromNative(): String as error with following text: Function without a body must

Solution 1:

Put external fun stringFromNative(): String outside of the companion object and into the MainActivity.

(I found the answer by looking at https://github.com/ligee/kotlin-ndk-samples)

Solution 2:

Kotlin :

call method from ndk file
 externalfunstringFromJNI(): String


 load c++ file
 companionobject {
        init {
            System.loadLibrary("native-lib")
        }
    }

Post a Comment for "Android: How To Call Ndk Function From Kotlin?"