8

I am making an app in kotlin. But I know python a lot and made the logic in python. The kotlin is only used for the display. Is there a way to call a python function in kotlin?. A python script can call python scripts but can a Kotlin script call one?

mhsmith
  • 6,675
  • 3
  • 41
  • 58
GjdGr8
  • 133
  • 1
  • 1
  • 7

2 Answers2

4

The easiest solution – Chaquopy

https://chaquo.com/chaquopy/

Works for me

Mikhail Sharin
  • 3,661
  • 3
  • 27
  • 36
0

I think there are two normal solutions.

  1. Using Polyglot API of GraalVM (https://www.graalvm.org/sdk/javadoc/org/graalvm/polyglot/package-summary.html).

  2. Creating a C interface implemented with Python (https://www.linuxjournal.com/article/8497) and calling it with JNI (https://docs.oracle.com/javase/8/docs/technotes/guides/jni/). However, this option needs you to manage your objects and memory very carefully (dispose all C pointers properly etc.)

Commander Tvis
  • 2,244
  • 2
  • 15
  • 41