Kiss My Score
Kiss My Score allows you to easily join Facebook friends’…
Our Android developers explain how we can call native code from Kotlin when working with the Android NDK, and that can create a simple app.
The Previous article was mostly about the theoretical concepts that come handy when working with the Android NDK.
In this article, we are going to see how we can call native code from Kotlin.
I created a KotlinJniSample Application that has a simple
HelloWorldexample to showcase how native code is called from Kotlin.
I created a class NativeStore to encapsulate the native methods.
The definition of the native function
stringFromJNI() is available in
MainActivity Class where we show
TextView with text from the native code( A little DI magic can also be added to extract the initialization.
Now that we have everything ready its time to take a look at our
Although Android creates the
CMake file for us with all the relevant functions, a little information comes in handy if we change the library name or so.
add_library function is used to add the path to the source code(in our case
There are a lot of CMake functions at our disposal.Let’s look at some of the core functions from the configuration:
SHARED, and provides the relative paths to its source code.
This part is handled in Android by default. We see a path to the
cpp flags added to the gradle file.
Now that we have everything ready, we are good to run the app using NDK.
In this article, we learned how to create a simple App using Kotlin and NDK. In part 3 we will see how to use callbacks from c++ to Kotlin.
init block of companion objectinstead of
externalkeyword instead of