Wrap JavaScript Library

Android provides WebView, I can use it to call the JavaScript function in Java program.

public void loadUrl (String url)

I have encountered a more complicated situation. I have to call the JavaScript library that building with Node.js. And I want to write the adapter for it, so that I can have clean and pure Java interface.

I would like to use J2V8 to execute JavaScript programs. J2V8 bundles Chrome V8 JavaScript engine as a dynamic library and provides a Java API for the engine through the Java Native Interface (JNI).

  • add J2V8 dependency in Gradle
dependencies {
    ......
    compile 'com.eclipsesource.j2v8:j2v8:4.8.0@aar'
}

WebView document of Android Developer

Node.js

J2V8 GitHub

results matching ""

    No results matching ""