Hey there :wave: Is it possible to use a Go libra...
# multiplatform
s
Hey there 👋 Is it possible to use a Go library from Kotlin multiplatform code?
b
Following along here. Having a similar idea/thought about a JS library. Obviously can fully port it over but curious on options.
🤞 1
z
Theoretically yes. You can write your go code and then compile it to a shared library, Kotlin native cinterop can automatically generate binding methods from the cgo header. On JVM you'll have to use JNI to call the go functions from kotlin. I believe there are also golang libraries for js/wasm interop. Then use expect/actual to bring it all together Check out: https://go.dev/wiki/cgo and https://github.com/timob/jnigi I've actually been interested in using go for writing JNI bindings as an alternative to C++ There's a gradle plugin to compile go sources but it seems to be no longer maintained unfortunately: https://github.com/gogradle/gogradle
👀 1
s
Thanks for the answer @zt! I do not know Go or C/C++, and I am talking about a third party Go library so I might be better off porting the parts of the library that I need 🤔
z
Porting it would probably be easier depending on how much is necessary, I'm glad I could help! I think I will try to make a proof of concept project demonstrating interop between kotlin and go too
s
Ah cool @zt, please update this thread if you end up doing that 🙌 Thanks again 🙏
y
@zt does that effect the speed of the app say that i have a library in kotlin and an other library that does the same thing and its easier to use but that library is in an other langauge does that effect the speed of the app
z
It depends on what you use to interface with the library in another language https://github.com/zakgof/java-native-benchmark shows a bunch of different methods
👍 1
I'm unsure if project panama works on Android Personally I think JNI and JNI-FFR are the only reasonable options
285 Views