Skip to content

tjmtic/CBindingKMP

Repository files navigation

C-Binding KMP Library Automation

Kotlin License Documentation

This project provides a unified and automated way to include and call native C code from Kotlin Multiplatform (KMP).



🎯 Goal

The goal is to allow developers to maintain a single C/C++ codebase (e.g., src/native/c) and automatically wire it up to:

  • Android: Via JNI (Java Native Interface) using CMake.
  • iOS / Native: Via Kotlin/Native CInterop.
  • Desktop (JVM): Via JNI (shared library).

✨ Key Features

  • 🚀 Zero Glue Code: Automatically generate JNI wrappers and Kotlin bindings.
  • 🛠 Unified Source: All C code lives in native/c. No more multiple glue layers.
  • 📱 Multi-Platform: Support for Android, iOS, JVM, and Native targets out-of-the-box.
  • ⚙️ Gradle Integrated: Custom generateJni task fits seamlessly into your build workflow.

📁 Project Structure

  • native/c: Contains your C source code (mylib.c, mylib.h).
  • shared: The KMP library, wired to use the generated bindings.
  • plugin: The Gradle plugin module containing the automation logic.
  • docs: Full documentation set for users and developers.

🚀 Quick Start

1. Define your C function

// native/c/mylib.h
int add_numbers(int a, int b);

2. Build the project

./gradlew :shared:assemble

3. Call from Kotlin

import com.abyxcz.cbindingkmp.shared.generated.add_numbersJNI

val result = add_numbersJNI(10, 20)

For more details, see the Getting Started Guide.

📘 Documentation Index

📜 License

This project is licensed under the MIT License - see the LICENSE file for details.

About

C Bindings for Kotlin Multiplatform

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors