I found this, but it is not working if I try to change things dynamically. E.G. calling js(“something”), this “something” must be a non-changeable string. I need to use interpolation and this is not acceptable in js().
The first thing to learn about is JavaScript modules. You need to put your Javascript function into a Javascript module. However there are many different module standards in JavaScript. The first thing you should do is learning how to use them.
Search for tutorials describing JavaScript modules. Learn how to use them. Write your own small JavaScript project that imports JavaScript modules.
Once you have learned about JavaScript modules, you can search for Kotlin tutorials that describe how to use and import JavaScript modules into Kotlin code.
Hi alzomins,
did you then find a solution? I have the same problem, I don’t know how to invoke from my kotlin main activity a function that I have defined inside a .js file. I am a newbie to android studio. I don’t know how to import the .js file into the kotlin project I don’t know how to make my function visible from the kotlin code.
If you have already found a solution and can share it I would be very grateful.
Thanks, see you soon
I am also learning kotlinjs and want to directly use a json and js file from resources at compile time.
Found method kotlinx.js.import and playing with this method now.
Currently, I can console the content of imported files using absolute path.
I think we need to configure webpack so the files are included in the build directory, then we can import using relative path.