Android utilize V8 without WebView

后端 未结 5 860
甜味超标
甜味超标 2020-12-12 13:55

I\'m exercising executing javascript from Java. Rhino works very well for this on desktop, but has to fall back to (slow) interpreted mode on Android (due to dalvik being u

5条回答
  •  心在旅途
    2020-12-12 14:17

    You can create a new V8 Context via its API and use that to execute your JavaScript, look into https://android.googlesource.com/platform/external/v8 include directory which contains two C++ header files. Link against the libwebcore.so (compiled from https://android.googlesource.com/platform/external/webkit) library via the NDK, nothing special.

    v8::Persistent context = v8::Persistent::New(v8::Context::New());
    context->Enter();
    

    Refer to https://developers.google.com/v8/get_started which will work on Android. Just make sure the device actually ships with V8 (some older devices ship with JSC [JavaScript Core]).

提交回复
热议问题