集成
在Android Studio的Android工程中,需要在build.gradle文件内容里添加依赖指令,然后gradle构建就会自动化集成J2V8引擎
dependencies {
implementation 'com.eclipsesource.j2v8:j2v8:5.0.103@aar'
}
使用示例
示例摘自https://eclipsesource.com/blogs/tutorials/getting-started-with-j2v8/
import com.eclipsesource.v8.V8;
public static void main(String[] args) {
V8 runtime = V8.createV8Runtime();
int result = runtime.executeIntegerScript(""
+ "var hello = 'hello, ';\n"
+ "var world = 'world!';\n"
+ "hello.concat(world).length;\n");
System.out.println(result);
runtime.release();
}
访问JavaScript对象(Object)
假设有这样一段JS脚本
var jsobj = {};
jsobj.hello = "world";
在J2V8中可以直接访问jsobj对象
import com.