使用ffmpeg_kit_flutter生成视频遇重复类错误,求解决方案
问题描述
我使用ffmpeg_kit_flutter库实现图片列表转视频功能,但App无法正常运行。实现代码如下:
Future<void> createVideoFromImages(List<Uint8List> images) async { final tempDir = await getTemporaryDirectory(); final videoPath = '${tempDir.path}/output_${DateTime.now().millisecondsSinceEpoch}.mp4'; final imagePaths = <String>[]; for (int i = 0; i < images.length; i++) { final imagePath = '${tempDir.path}/image$i.png'; await File(imagePath).writeAsBytes(images[i]); imagePaths.add(imagePath); } final ffmpegCommand = [ '-framerate', '7', '-i', '${tempDir.path}/image%d.png', '-c:v', 'libx264', '-pix_fmt', 'yuv420p', videoPath, ]; final session = await FFmpegKit.executeWithArguments(ffmpegCommand); final logs = await session.getLogs(); // Get the logs for (final log in logs) { print(log.getMessage()); // Print each log message } if (ReturnCode.isSuccess(await session.getReturnCode())) { await GallerySaver.saveVideo(videoPath); ScaffoldMessenger.of(context).showSnackBar( const SnackBar( content: Text('Video saved to gallery'), ), ); } else { print('Error: Video creation failed'); } }
错误日志显示依赖包存在重复类:
Execution failed for task ':app:checkDebugDuplicateClasses'. > A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable > Duplicate class com.arthenica.ffmpegkit.Abi found in modules jetified-ffmpeg-kit-https-6.0-runtime (com.arthenica:ffmpeg-kit-https:6.0) and jetified-ffmpeg-kit-https-gpl-5.1-runtime (com.arthenica:ffmpeg-kit-https-gpl:5.1) Duplicate class com.arthenica.ffmpegkit.AbiDetect found in modules jetified-ffmpeg-kit-https-6.0-runtime (com.arthenica:ffmpeg-kit-https:6.0) and jetified-ffmpeg-kit-https-gpl-5.1-runtime (com.arthenica:ffmpeg-kit-https-gpl:5.1) Duplicate class com.arthenica.ffmpegkit.AbstractSession found in modules jetified-ffmpeg-kit-https-6.0-runtime (com.arthenica:ffmpeg-kit-https:6.0) and jetified-ffmpeg-kit-https-gpl-5.1-runtime (com.arthenica:ffmpeg-kit-https-gpl:5.1)
请问该如何处理这个错误?
解决方案
这个错误是因为项目中同时引入了不同版本/变体的ffmpeg-kit依赖(6.0的https版本和5.1的https-gpl版本),导致类重复冲突。按以下步骤解决:
统一ffmpeg_kit_flutter版本:打开
pubspec.yaml,确保只引入了一个版本的ffmpeg_kit_flutter(或其变体,比如ffmpeg_kit_flutter_gpl),删除多余的依赖项。比如如果需要GPL功能,就统一用:dependencies: ffmpeg_kit_flutter_gpl: ^6.0.0不需要GPL的话就用标准版本:
dependencies: ffmpeg_kit_flutter: ^6.0.0强制覆盖冲突依赖:如果是其他第三方包间接引入了旧版本的ffmpeg-kit,在
pubspec.yaml中添加dependency_overrides,强制使用统一版本:dependency_overrides: ffmpeg_kit_flutter: ^6.0.0 # 如果用的是gpl变体,替换成对应包名 ffmpeg_kit_flutter_gpl: ^6.0.0清理项目缓存:执行以下命令清理旧的依赖缓存,重新拉取依赖:
flutter clean flutter pub get检查Android Gradle配置:打开
android/app/build.gradle,确保没有手动添加com.arthenica:ffmpeg-kit-*相关依赖,避免和flutter插件自带的依赖冲突。
内容的提问来源于stack exchange,提问作者Touseef khattak
相关产品推荐
相关产品推荐

