Flutter集成flutter-webrtc后构建启动前崩溃问题排查求助
Flutter WebRTC项目启动崩溃排查求助
我正在开发一个使用flutter-webrtc包实现WebRTC功能的Flutter项目,但应用构建完成后,启动前就发生崩溃。已在Android和iOS设备上测试,问题均存在。怀疑问题与flutter-webrtc包或WebRTC功能本身相关,附上相关配置及调试日志,恳请协助排查并找到解决方案。
Android build.gradle配置
def localProperties = new Properties() def localPropertiesFile = rootProject.file('local.properties') if (localPropertiesFile.exists()) { localPropertiesFile.withReader('UTF-8') { reader -> localProperties.load(reader) } } def flutterRoot = localProperties.getProperty('flutter.sdk') if (flutterRoot == null) { throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") } def flutterVersionCode = localProperties.getProperty('flutter.versionCode') if (flutterVersionCode == null) { flutterVersionCode = '1' } def flutterVersionName = localProperties.getProperty('flutter.versionName') if (flutterVersionName == null) { flutterVersionName = '1.0' } apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { compileSdkVersion 33 ndkVersion flutter.ndkVersion compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } kotlinOptions { jvmTarget = '1.8' } sourceSets { main.java.srcDirs += 'src/main/kotlin' } defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "com.example.video_call" // You can update the following values to match your application needs. // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration. minSdkVersion 23 targetSdkVersion flutter.targetSdkVersion versionCode flutterVersionCode.toInteger() versionName flutterVersionName } buildTypes { release { // TODO: Add your own signing config for the release build. // Signing with the debug keys for now, so `flutter run --release` works. signingConfig signingConfigs.debug } } } flutter { source '../..' } dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" }
调试日志(部分)
I/org.webrtc.Logging(27390): NativeLibrary: Loading native library: jingle_peerconnection_so I/org.webrtc.Logging(27390): NativeLibrary: Loading library: jingle_peerconnection_so I/org.webrtc.Logging(27390): PeerConnectionFactory: PeerConnectionFactory was initialized without an injected Loggable. Any existing Loggable will be deleted. I/org.webrtc.Logging(27390): EglBase14Impl: Using OpenGL ES version 2 D/EGL_emulation(27390): eglCreateContext: 0xf1fb5450: maj 2 min 0 rcv 2 2 I/org.webrtc.Logging(27390): WebRtcAudioManagerExternal: Sample rate is set to 44100 Hz E/org.webrtc.Logging(27390): JavaAudioDeviceModule: HW AEC not supported E/org.webrtc.Logging(27390): JavaAudioDeviceModule: HW NS not supported I/org.webrtc.Logging(27390): JavaAudioDeviceModule: createAudioDeviceModule I/org.webrtc.Logging(27390): JavaAudioDeviceModule: HW NS will not be used. I/org.webrtc.Logging(27390): JavaAudioDeviceModule: HW AEC will not be used. I/org.webrtc.Logging(27390): WebRtcAudioEffectsExternal: ctor@[name=main, id=2] I/org.webrtc.Logging(27390): WebRtcAudioRecordExternal: ctor@[name=main, id=2] I/org.webrtc.Logging(27390): WebRtcAudioTrackExternal: ctor@[name=main, id=2] I/VideoCapabilities(27390): Unsupported profile 4 for video/mp4v-es I/org.webrtc.Logging(27390): PeerConnectionFactory: onNetworkThreadReady I/org.webrtc.Logging(27390): PeerConnectionFactory: onSignalingThreadReady I/org.webrtc.Logging(27390): PeerConnectionFactory: onWorkerThreadReady I/org.webrtc.Logging(27390): EglRenderer: Initializing EglRenderer I/org.webrtc.Logging(27390): EglRenderer: EglBase.create shared context D/HostConnection(27390): HostConnection::get() New Host Connection established 0xf1fa14f0, tid 27440 D/HostConnection(27390): HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_YUV_Cache ANDROID_EMU_has_shared_slots_host_memory_allocator ANDROID_EMU_sync_buffer_data ANDROID_EMU_read_color_buffer_dma GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_gles_max_version_2 I/org.webrtc.Logging(27390): EglBase14Impl: Using OpenGL ES version 2 D/EGL_emulation(27390): eglCreateContext: 0xf1fa18e0: maj 2 min 0 rcv 2 W/Gralloc4(27390): allocator 3.x is not supported I/FlutterWebRTCPlugin(27390): getUserMedia(video): ConstraintsMap{mMap={facingMode=user}} I/CameraManagerGlobal(27390): Connecting to camera service D/FlutterWebRTCPlugin(27390): Creating video capturer using Camera2 API. D/FlutterWebRTCPlugin(27390): Create front camera 1 succeeded D/EGL_emulation(27390): eglMakeCurrent: 0xf1fa18e0: ver 2 0 (tinfo 0xf22de950) (first time) D/HostConnection(27390): HostConnection::get() New Host Connection established 0xf1fb3b60, tid 27441 D/HostConnection(27390): HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_YUV_Cache ANDROID_EMU_has_shared_slots_host_memory_allocator ANDROID_EMU_sync_buffer_data ANDROID_EMU_read_color_buffer_dma GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_gles_max_version_2 I/org.webrtc.Logging(27390): EglBase14Impl: Using OpenGL ES version 2 D/EGL_emulation(27390): eglCreateContext: 0xf1fa0290: maj 2 min 0 rcv 2 D/EGL_emulation(27390): eglMakeCurrent: 0xf1fa0290: ver 2 0 (tinfo 0xf22efad0) (first time) E/EGL_emulation(27390): eglQueryContext 32c0 EGL_BAD_ATTRIBUTE E/EGL_emulation(27390): tid 27441: eglQueryContext(2019): error 0x3004 (EGL_BAD_ATTRIBUTE) I/org.webrtc.Logging(27390): CameraCapturer: startCapture: 1280x720@30 D/FlutterWebRTCPlugin(27390): changeCaptureFormat: 1280x720@30 I/org.webrtc.Logging(27390): Camera2Session: Create new camera2 session on camera 1 I/org.webrtc.Logging(27390): Camera2Session: start D/FlutterWebRTCPlugin(27390): MediaStream id: a1f2e57a-ac2c-47ff-a5ee-6aadce72ccc1 I/org.webrtc.Logging(27390): Camera2Session: Available preview sizes: [1920x1440, 1920x1080, 1920x960, 1600x1200, 1440x1080, 1280x960, 1280x720, 1024x768, 800x600, 720x480, 640x480, 640x360, 352x288, 320x240, 176x144] I/org.webrtc.Logging(27390): Camera2Session: Available fps ranges: [[15.0:15.0], [7.0:30.0], [15.0:30.0], [30.0:30.0]] I/org.webrtc.Logging(27390): Camera2Session: Using capture format: 1280x720@[7.0:30.0] I/org.webrtc.Logging(27390): Camera2Session: Opening camera 1 D/FlutterWebRTCPlugin(27390): CameraEventsHandler.onCameraOpening: cameraName=1 I/org.webrtc.Logging(27390): Camera2Session: Camera opened. I/org.webrtc.Logging(27390): Camera2Session: Camera capture session configured. I/org.webrtc.Logging(27390): Camera2Session: Stabilization not available. I/org.webrtc.Logging(27390): Camera2Session: Using continuous video auto-focus. I/org.webrtc.Logging(27390): Camera2Session: Camera device successfully started. I/org.webrtc.Logging(27390): CameraCapturer: Create session done. Switch state: IDLE I/org.webrtc.Logging(27390): SurfaceTextureHelper: Setting listener to org.webrtc.Camera2Session$CaptureSessionCallback$$ExternalSyntheticLambda0@6de788 D/FlutterWebRTCPlugin(27390): CameraEventsHandler.onFirstFrameAvailable I/org.webrtc.Logging(27390): EglRenderer: Initializing EglRenderer I/org.webrtc.Logging(27390): EglRenderer: EglBase.create shared context D/HostConnection(27390): HostConnection::get() New Host Connection established 0xf1fa21a0, tid 27448 D/HostConnection(27390): HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_YUV_Cache ANDROID_EMU_has_shared_slots_host_memory_allocator ANDROID_EMU_sync_buffer_data ANDROID_EMU_read_color_buffer_dma GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_gles_max_version_2 I/org.webrtc.Logging(27390): EglBase14Impl: Using OpenGL ES version 2 ...
排查建议
- 版本兼容性检查:确认flutter-webrtc版本与当前Flutter SDK版本匹配,部分新版本依赖特定Flutter版本,可查看flutter-webrtc官方文档的版本适配说明。
- 权限配置验证:
- Android:确保AndroidManifest.xml中添加了相机、麦克风、网络权限:
<uses-permission android:name="android.permission.CAMERA" /> <uses-permission android:name="android.permission.RECORD_AUDIO" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-feature android:name="android.hardware.camera" /> <uses-feature android:name="android.hardware.camera.autofocus" /> - iOS:在Info.plist中添加摄像头和麦克风权限描述:
<key>NSCameraUsageDescription</key> <string>需要访问摄像头进行视频通话</string> <key>NSMicrophoneUsageDescription</key> <string>需要访问麦克风进行语音通话</string>
- Android:确保AndroidManifest.xml中添加了相机、麦克风、网络权限:
- 清理重建项目:执行以下命令清除缓存并重新构建:
flutter clean flutter pub get flutter run - 指定NDK版本:在build.gradle的android块中替换
ndkVersion flutter.ndkVersion为具体稳定版本,比如:ndkVersion "25.1.8937393" - 最小化测试:创建一个仅包含flutter-webrtc基础功能的测试项目,比如仅初始化PeerConnectionFactory或获取本地摄像头流,验证是否崩溃,排除其他业务代码干扰。
- 获取完整崩溃日志:当前日志未包含崩溃时的核心错误信息(如AndroidRuntime异常栈),需导出完整的设备日志,找到崩溃发生时的具体错误类型和调用栈,这是定位问题的关键。
内容的提问来源于stack exchange,提问作者Jeevan Shrestha
相关产品推荐
相关产品推荐

