Java Android JNI中后台线程上的v8
我试图从后台线程调用android应用程序中的JNI调用来调用v8。它导致运行时崩溃,并抱怨v8::ObjectTemplate::New(v8::Handle) 要复制,请调用以下jniJava Android JNI中后台线程上的v8,java,android,java-native-interface,v8,libv8,Java,Android,Java Native Interface,V8,Libv8,我试图从后台线程调用android应用程序中的JNI调用来调用v8。它导致运行时崩溃,并抱怨v8::ObjectTemplate::New(v8::Handle) 要复制,请调用以下jni void JSfunc() { v8::Isolate* currentIsolate = v8::Isolate::GetCurrent(); if(!currentIsolate) { currentIsolate = v8::Isolate
void JSfunc() {
v8::Isolate* currentIsolate = v8::Isolate::GetCurrent();
if(!currentIsolate) {
currentIsolate = v8::Isolate::New();
}
v8::HandleScope handle_scope(currentIsolate);
v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New();
}
如果您直接从UI线程或可运行线程调用该函数,它将正常工作
有什么想法吗?问题是缺少生成隔离的代码
currentIsolate->Enter();
因此正确的JNI函数是
void JSfunc() {
v8::Isolate* currentIsolate = v8::Isolate::GetCurrent();
if(!currentIsolate) {
currentIsolate = v8::Isolate::New();
currentIsolate->Enter();
}
v8::HandleScope handle_scope(currentIsolate);
v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New();
}
void JSfunc(){
v8::Isolate*currentIsolate=v8::Isolate::GetCurrent();
如果(!currentIsolate){
currentIsolate=v8::Isolate::New();
currentIsolate->Enter();
}
v8::手柄示波器手柄(电流隔离);
v8::Handle global=v8::ObjectTemplate::New();
}
如果你在那里崩溃了,我想我们可以正确地假设在jni代码片段中,为了我们的利益,你遗漏了JSFunc的长jni头声明?(不要怪你…)是的,我遗漏了外部“C”{JNIEXPORT void Java_com_example_app_class_JSFunc(JNIEnv*env,jobject thiz){JSFunc()}
void JSfunc() {
v8::Isolate* currentIsolate = v8::Isolate::GetCurrent();
if(!currentIsolate) {
currentIsolate = v8::Isolate::New();
currentIsolate->Enter();
}
v8::HandleScope handle_scope(currentIsolate);
v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New();
}