How to use Kotlin compiler on Android


#1

Hello! I want to use kotlin compiler in my app to compile .kt files. Is that possible? If so what library do I need.
Thanks.


#3

@fvasco
Hey, I think you understood me wrong, I want to make my android app compile a .kt file like an IDE does


#4

You can try packaging the Kotlin compiler as an Android app, and this could work, but there is no ready-made library that you can simply plug in into your app. Also note that the Kotlin compiler has fairly high CPU and memory requirements, which means that compiling even small files on old Android devices could take minutes.

I don’t know what problem you’re trying to solve, but I’m pretty sure that running the Kotlin compiler on the user’s phone is not the optimal way to do that.


#5

@yole Thanks, I wasn’t going to make my app in the google play store anyway, its just for me, I thought since there are mobile apps that can compile java, c/c++ and even Python why not make one for kotlin, but I think its harder than I thought. Thanks though.


#6

@MohamedWS Did you manage to make it? I also have to compile runtime Kotlin code on Android, but kotlin-compiler dependency gives me several problems on compile time.
If you made it please show me how, thanks.


#8

@arabello Yup I did find a way to compile and run kotlin files on my phone just last week after several hours of searching, its not that much slow, it takes about 1-2 seconds for 1 file to compile (I have mid-range phone Galaxy J7 Prime). I still havent tried to make this process in an app though, I’ve only done it on terminal emulator and it did require me root access. I can give you instructions on my WhatsApp number +212611020351


#9

@MohamedWS Thank you so much for your response. Unfortunately the conditions (terminal simulator and root access) are not possible for my project. I will make it somehow.


#10

@arabello yeah unfortunately since running kotlin compiler requires jre I had to transfer a script to /system/bin to get it to work