FlutterFlow中Agora UI Kit编译失败,调整依赖版本无效求助
问题:FlutterFlow中Agora视频通话组件构建APK失败
问题背景
在FlutterFlow开发应用,自定义VideoCall组件此前运行正常,今日执行flutter build apk时出现类型未找到及参数不匹配错误,同时agora_uikit在Pub.dev显示异常。当前依赖配置:agora_uikit: ^1.3.7、agora_rtc_engine: ^6.2.2。
自定义VideoCall组件代码
// Automatic FlutterFlow imports import '/flutter_flow/flutter_flow_theme.dart'; import '/flutter_flow/flutter_flow_util.dart'; import '/custom_code/widgets/index.dart'; // Imports other custom widgets import '/flutter_flow/custom_functions.dart'; // Imports custom functions import 'package:flutter/material.dart'; // Begin custom widget code // DO NOT REMOVE OR MODIFY THE CODE ABOVE! import 'package:agora_uikit/agora_uikit.dart'; import 'package:agora_rtc_engine/agora_rtc_engine.dart'; import 'dart:async'; class VideoCall extends StatefulWidget { const VideoCall({ super.key, this.width, this.height, }); final double? width; final double? height; @override State<VideoCall> createState() => _VideoCallState(); } class _VideoCallState extends State<VideoCall> { final AgoraClient client = AgoraClient( agoraConnectionData: AgoraConnectionData( appId: "2416802168934ee69b03279b26c91b4f", channelName: FFAppState().callID, ), agoraEventHandlers: AgoraRtcEventHandlers( onUserOffline: (connection, remoteUid, reason) => update(), ), ); Timer? statusCheckTimer; // Initialize the Agora Engine @override void initState() { super.initState(); initAgora(); startStatusCheck(); } void initAgora() async { await client.initialize(); } void startStatusCheck() { statusCheckTimer = Timer.periodic(Duration(seconds: 1), (timer) { print("Checking status... ${FFAppState().status}"); if (FFAppState().status == 3) { print("Status is 3, leaving channel..."); timer.cancel(); client.engine.leaveChannel(); Navigator.of(context).pop(); } }); } @override void dispose() { // Always cancel the timer to prevent memory leaks statusCheckTimer?.cancel(); client.engine.leaveChannel(); super.dispose(); } @override Widget build(BuildContext context) { return Container( child: Stack(children: [ AgoraVideoViewer(client: client), AgoraVideoButtons(client: client), ]), ); } } Future update() async { FFAppState().update(() { FFAppState().status = 3; }); }
构建错误信息
Error: Command failed: flutter build apk --no-pub --no-version-check /opt/.pub-cache/hosted/pub.dev/agora_uikit-1.3.7/lib/models/agora_rtc_event_handlers.dart:189:7: Error: Type 'LocalVideoStreamError' not found. LocalVideoStreamError error)? onLocalVideoStateChanged; ^^^^^^^^^^^^^^^^^^^^^ /opt/.pub-cache/hosted/pub.dev/agora_uikit-1.3.7/lib/models/agora_rtc_event_handlers.dart:354:40: Error: Type 'RhythmPlayerErrorType' not found. RhythmPlayerStateType state, RhythmPlayerErrorType errorCode)? ^^^^^^^^^^^^^^^^^^^^^ /opt/.pub-cache/hosted/pub.dev/agora_uikit-1.3.7/lib/models/agora_rtc_event_handlers.dart:446:7: Error: Type 'LocalAudioStreamError' not found. LocalAudioStreamError error)? onLocalAudioStateChanged; ^^^^^^^^^^^^^^^^^^^^^ /opt/.pub-cache/hosted/pub.dev/agora_uikit-1.3.7/lib/models/agora_rtc_event_handlers.dart:521:7: Error: Type 'RtmpStreamPublishErrorType' not found. RtmpStreamPublishErrorType errCode)? onRtmpStreamingStateChanged; ^^^^^^^^^^^^^^^^^^^^^^^^^^ /opt/.pub-cache/hosted/pub.dev/agora_uikit-1.3.7/lib/models/agora_rtc_event_handlers.dart:554:23: Error: Type 'ChannelMediaRelayEvent' not found. final void Function(ChannelMediaRelayEvent code)? onChannelMediaRelayEvent; ^^^^^^^^^^^^^^^^^^^^^^ /opt/.pub-cache/hosted/pub.dev/agora_uikit-1.3.7/lib/models/agora_rtc_event_handlers.dart:189:7: Error: 'LocalVideoStreamError' isn't a type. LocalVideoStreamError error)? onLocalVideoStateChanged; ^^^^^^^^^^^^^^^^^^^^^ /opt/.pub-cache/hosted/pub.dev/agora_uikit-1.3.7/lib/models/agora_rtc_event_handlers.dart:354:40: Error: 'RhythmPlayerErrorType' isn't a type. RhythmPlayerStateType state, RhythmPlayerErrorType errorCode)? ^^^^^^^^^^^^^^^^^^^^^ /opt/.pub-cache/hosted/pub.dev/agora_uikit-1.3.7/lib/models/agora_rtc_event_handlers.dart:446:7: Error: 'LocalAudioStreamError' isn't a type. LocalAudioStreamError error)? onLocalAudioStateChanged; ^^^^^^^^^^^^^^^^^^^^^ /opt/.pub-cache/hosted/pub.dev/agora_uikit-1.3.7/lib/models/agora_rtc_event_handlers.dart:521:7: Error: 'RtmpStreamPublishErrorType' isn't a type. RtmpStreamPublishErrorType errCode)? onRtmpStreamingStateChanged; ^^^^^^^^^^^^^^^^^^^^^^^^^^ /opt/.pub-cache/hosted/pub.dev/agora_uikit-1.3.7/lib/models/agora_rtc_event_handlers.dart:554:23: Error: 'ChannelMediaRelayEvent' isn't a type. final void Function(ChannelMediaRelayEvent code)? onChannelMediaRelayEvent; ^^^^^^^^^^^^^^^^^^^^^^ /opt/.pub-cache/hosted/pub.dev/agora_uikit-1.3.7/lib/controllers/rtc_event_handlers.dart:146:6: Error: No named parameter with the name 'onChannelMediaRelayEvent'. }, onChannelMediaRelayEvent: (code) { ^^^^^^^^^^^^^^^^^^^^^^^^ /opt/.pub-cache/hosted/pub.dev/agora_rtc_engine-6.3.0/lib/src/agora_rtc_engine.dart:1576:9: Context: Found this candidate, but the arguments don't match. const RtcEngineEventHandler({ ^^^^^^^^^^^^^^^^^^^^^
解决方案
锁定兼容的依赖版本
错误根源是agora_uikit:1.3.7与自动升级的agora_rtc_engine:6.3.0不兼容,需指定官方验证的匹配组合:
修改pubspec.yaml中的依赖:agora_uikit: 1.3.6 agora_rtc_engine: 6.2.2注意:避免使用
^符号,防止自动升级到不兼容版本。清理缓存并重新获取依赖
执行以下命令清除旧缓存,重新下载指定版本的包:flutter clean flutter pub get验证FlutterFlow环境配置
在FlutterFlow的"Dependencies"页面手动指定版本号,取消自动更新选项,确保平台配置与本地pubspec.yaml一致。替代方案:升级到最新稳定版
如果上述方法无效,可尝试升级到agora_uikit最新稳定版(需确认与agora_rtc_engine版本兼容),例如:agora_uikit: ^1.4.0 agora_rtc_engine: ^6.3.0同时检查自定义组件代码是否需要适配新版本的API变化。
内容的提问来源于stack exchange,提问作者FlutterflowDev
相关产品推荐
相关产品推荐

