https://kotlinlang.org logo
Title
a

arunshaik432

03/28/2023, 3:24 AM
Hi all, I have a question regarding creating kotlin library. I want to wrap already created javascript library (available on npm) in a kotlin library and consume it in android native projects. How can i do so? please anyone help on this? Thank You
e

efemoney

03/28/2023, 3:28 AM
That is impossible.
a

arunshaik432

03/28/2023, 3:31 AM
Hi @efemoney, do you know any other way to achieve it?
p

Pablichjenkov

03/28/2023, 3:38 AM
You will have to add a JavaScript engine into your code. The other alternative, it depends on your requirements, is using a WebView, there is an API to call functions from kotlin/java to the JavaScript code running in the WebView. Take a look into the Cordova project. Back to the engine alternative, you can check https://github.com/cashapp/zipline, Check what they do.
But yeah any path is a heavy alternative if you just want to execute one library code. I believe it would be much easier trying to find the kotlin version of that library.
a

arunshaik432

03/28/2023, 3:47 AM
@Pablichjenkov I will check the zipline and cordova github repos. Thank You
p

Pablichjenkov

03/28/2023, 3:59 AM
Those are big projects, for the case you plan to run a full JavaScript app or something of that magnitude. But again, for one single use library it would be easier just finding the kotlin equivalent of that library.
a

arunshaik432

03/28/2023, 4:01 AM
ok got it.
j

Joffrey

03/28/2023, 7:28 AM
Or the java equivalent, which you could use from Kotlin
What library did you have in mind specifically? What did you intend to do with it?
a

arunshaik432

03/28/2023, 10:58 AM
not any specific js lib
y

Youssef Shoaib [MOD]

03/28/2023, 3:36 PM
You could also, as long as the library isn't js-specific, try to rewrite the library in Kotlin. It's quite a difficult undertaking, but it could be easier if there's typescript definitions for the library already
j

Joffrey

03/28/2023, 10:35 PM
@arunshaik432 I thought your question was about a library you wanted to use. Was it just a theoretical question without a concrete need?
a

arunshaik432

03/29/2023, 4:05 AM
i need it in one my contract work. they want me to build a kotlin wrapper on top of their crypto js library that kotlin lib will be used in android native projects. that is why i asked this question