How can I detect which javascript engine (v8 or JSC) is used at runtime in Android?

后端 未结 3 821
小鲜肉
小鲜肉 2020-12-05 15:41

Newer versions of Android ( > 2.2) include the v8 javascript engine, while older versions only had JSC. However, according to http://blogs.nitobi.com/joe/2011/01/14/android

3条回答
  •  暖寄归人
    2020-12-05 16:12

    Although the answer above points out the best methods, I thought I'd point out another way of doing this from inside a native library.

    void *dlWebCoreHandle = dlopen("libwebcore.so", RTLD_NOW);
    void *v8GetVersion = dlsym(dlWebCoreHandle, "_ZN2v82V810GetVersionEv");
    if (v8GetVersion == NULL) {
        /* does not appear to be V8 */
    } ... etc.
    

    The exported symbols are mangled, unfortunately, so there is no 100% guarantee that the compiler used by your firmware manufacturer mangled the symbol in the same way (use nm --defined-only libwebcore.so -g on a library with symbols). One would expose this function via the JNI and check from inside Java code.

    The libwebcore.so library also lists V8_Fatal as one of the symbols, which is not susceptible to mangling.

    JSC will have some other exported symbols that you can check for from inside a native library. If both are non-existent you can fallback to other methods.

提交回复
热议问题