Hi, I have built a .so shared library in kotlin/na...
# kotlin-native
m
Hi, I have built a .so shared library in kotlin/native and I am able to use it's methods in my android app(thanks to @natario1) But now, I am using cinterop in my kotlin/native project to access tensorflow C API and i am able to access the tensorflow methods inside my kotlin/native project. But these functions are not accessibly by my android app. why?
g
Because there is no ready to use bridge between K/N and Android, you have to use JNI
m
right. below is the snapshot
Copy code
@CName("Java_com_example_android_1app_MainActivity_callInt")
fun callInt(env: CPointer<JNIEnvVar>, clazz: jclass, it: jint): jint {
    initRuntimeIfNeeded()
    Platform.isMemoryLeakCheckerActive = false


    println(kTfLiteDimDense)
    TfLiteInterpreterOptionsCreate()
    println("Native function is executed with: $it")
    return it + 1
}
I am able to access callInt() in my android app, what should I do exactly to access TfLiteInterpreterOptionsCreate() in my android app.
m
@Mananpoddarm is there a reason why are you not using official java library ?
m
@Michal Harakal yes, because, I am writing a wrapper in kotlin/native and the wrapper needs tensorflow library. The usecase is, I would like to use kotlin multiplatform to write code for multiple platforms, but meanwhile I also need the support of third party libraries. Since, Ktor is one of the only few library supported by mpp, we moved to kotlin/.native. We thought, since it's possible to use all the c libraries via cinterops in kotlin/native, we can write a wrapper in kotlin/native and use it across platforms. Did I answer your question? Do you have a better way of doing it?
m
Sorry I didn't see a mentioning of multiplatform in previous messages. I have understood, that you waht to talk to so from Android directly ... Yes, this seems to be also a way for me (via KMP with kotlin-native). I don't have much experience with native, but I have done some work with KMP already and having Android background and learning Tensorflow, your project sounds very interesting for me. Also there is something similira here https://tensorflow-kotlin.dev/ But its also doesn't mention KMP either.
m
@Michal Harakal since you have worked with KMP, have you also come around the usecase where you needed a third party library? If so, how did you handle it
m
I have either used existing KMP capable library like e.g.
ktor-utils
for datetime or apllied
expected/actuall
and
alias
mechanism. I have to admit, the app is quite a basic (conference planner app, supporting various backends ...) https://github.com/dukecon/dukecon_mobile
@Mananpoddarm did you find a solution for your problem? BTW, I have discovered that, here is a channel related to #tensorflow
m
@Michal Harakal I think, the tensorflow is not packaged with the final .so file that kotlin native is building. It's able to compile successfully just because header files are present but the actual definitions are not there. I read somewhere that cinterop libraries are directly not transferrable. Hence, now I am trying to include tensorflowlite.so separately in android project and let's see if kotlin native .so file can get the definitions from tensorflowlite.so directly. Btw, thanks for mentioning the channel.
m
Thank you for sharing your findings …
👍 1