andorid webrtc native CreatePeerConnectionFactory Check failed: g_jvm

1、错误现象

程序调用webrtc在CreatePeerConnectionFactory时候老是crash

2022-02-18 14:49:31.484 17400-17694/org.webrtc.examples.androidnativeapi E/rtc: #
    # Fatal error in: ../../modules/utility/source/jvm_android.cc, line 245
    # last system error: 30
    # Check failed: g_jvm
    # 

2、原因

jvm未初始化

3、解决方法,调用webrtc::JVM::Initialize,代码如下:

extern "C" jint JNIEXPORT JNICALL JNI_OnLoad(JavaVM* jvm, void* reserved) {
  webrtc::InitAndroid(jvm);
  webrtc::JVM::Initialize(jvm);
  RTC_CHECK(rtc::InitializeSSL()) << "Failed to InitializeSSL()";
  return JNI_VERSION_1_6;
}

extern "C" void JNIEXPORT JNICALL JNI_OnUnload(JavaVM* jvm, void* reserved) {
  RTC_CHECK(rtc::CleanupSSL()) << "Failed to CleanupSSL()";
}

}  // namespace webrtc_examples

你可能感兴趣的:(webrtc,native,android)