https://kotlinlang.org logo
#android
Title
# android
a

alle.iacob

04/05/2019, 8:46 AM
Hi, can someone recommend me a library that can execute Javascript code in android outside webview?
g

gumil

04/05/2019, 9:00 AM
Are you planning to use javascript code to use in android natively?
a

alle.iacob

04/05/2019, 9:04 AM
yes
I need to be able to call javascript functions from android application outside a webview
k

Kris Wong

04/05/2019, 12:49 PM
j

jw

04/05/2019, 1:42 PM
We package Duktape for Android: https://github.com/square/duktape-android/
👍 2
👀 1
k

Kris Wong

04/05/2019, 1:52 PM
even better!
a

alle.iacob

04/05/2019, 2:29 PM
the issue with duktape is that it doesn’t support object data transfer
and the javascript will be common for both android and ios apps
and the ios team want’s to have this functionality
a

adams2

04/05/2019, 4:32 PM
is duktape better than a plain headless webview
j

jw

04/05/2019, 4:32 PM
depends what you're doing. it's certainly less resource intensive.
o

oleksandr

04/05/2019, 6:04 PM
the issue with duktape is that it doesn’t support object data transfer
Not sure what that means, but in our project we have following setup: duktape-android (thanks Square for a nice wrapper) on Android and JSCore on iOS. Original JS code is written in ES6 for Web, we transpile it to ES5 (duktape and JSCore before iOS 10 do not support ES6) and run it in native apps. We have built a bit more functionality on top of duktape-android, things like JsonObjectWrapper which reflectively converts between Kotlin classes and JSON, transparent JS<->Kotlin Promise support with coroutines and Deferred, a bit stricter memory deallocation, and convenient debugger attachment process. We plan to open source this small addon at some point. On iOS Safari connects to JSCore for debugging automatically. It works pretty good so far, so I can recommend this approach. Alternatively, either WebView or JSCore on both platforms.
6 Views