0

I'm working on a project that needs to hook into another project that is written in C, and it can be used by both Android and iOS. The project structure looks something like this.

├── Android
|   ├── foo1.kt
|   └── foo2.kt
├── iOS
|   ├── foo3.swift
|   └── foo4.swift
├── source
|   ├── foo5.c
|   └── foo6.c

The iOS team was able to make wrapper classes that will call the C files (since Swift isn't far removed from C), but I don't know how this would work on Android. The goal is to call foo() in my Kotlin class and somehow call foo() in the corresponding C library. By calling this function, it will trigger functionality elsewhere in the library. Is it even possible to bridge the gap between the C language and a JVM language?

example:

Kotlin class

class MyKotlinClass {

     fun fooKotlin() {
         fooC() 
     }
}

Calls C function

int fooC() {
    // do stuff in the library that is somewhere else
}
Marty Miller
  • 913
  • 2
  • 11
  • 27
  • 2
    Possible duplicate of [What is the Android Native Development Kit (NDK)?](https://stackoverflow.com/questions/6660621/what-is-the-android-native-development-kit-ndk) – Morrison Chang Sep 07 '19 at 02:29
  • Also see: https://github.com/googlesamples/android-ndk/tree/master/kotlin-app – Morrison Chang Sep 07 '19 at 02:32
  • That question is vague – Marty Miller Sep 09 '19 at 00:10
  • Your original post as written is `Is it even possible to bridge the gap between the C language and a JVM language?` and the answer is yes with the Android NDK as noted in the dup link. I've also linked to an example project for using C with Kotlin on Android. If your post acknowledges that you know about the NDK, then as written the post is too broad. If you can improve your question (or write a new one) as to what the difficulty is (auto-create wrappers?, don't under how JNI works?) but realize that most resources online are still Java/JNI/C not Kotlin/JNI/C. Research Java/JNI, then ask. – Morrison Chang Sep 09 '19 at 01:26

0 Answers0