You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter项目引入video_compress包后构建失败求助

问题描述

我正在开发一个需上传视频和缩略图的Flutter项目,使用video_compress包实现视频压缩与缩略图获取。将该包添加到pubspec.yaml后,构建项目时出现如下错误:

* What went wrong:
Execution failed for task ':app:checkDebugAarMetadata'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
   > Could not find com.otaliastudios:transcoder:0.9.1.
     Searched in the following locations:
       - https://dl.google.com/dl/android/maven2/com/otaliastudios/transcoder/0.9.1/transcoder-0.9.1.pom
       - https://repo.maven.apache.org/maven2/com/otaliastudios/transcoder/0.9.1/transcoder-0.9.1.pom
       - https://storage.googleapis.com/download.flutter.io/com/otaliastudios/transcoder/0.9.1/transcoder-0.9.1.pom
     Required by:
         project :app > project :video_compress

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 25s
Exception: Gradle task assembleDebug failed with exit code 1

我已尝试执行flutter clean和flutter pub get命令,但构建仍报相同错误。相关代码如下:

_compressVideo(String videoPath) async {
  final compressedVideo = await VideoCompress.compressVideo(
    videoPath,
    quality: VideoQuality.MediumQuality,
  );

  return compressedVideo!.file;
}

_getThumbnail(String videoPath) async {
  final thumbnail = await VideoCompress.getFileThumbnail(videoPath);
  return thumbnail;
}
解决方案
  • 升级video_compress到最新版本
    旧版本video_compress依赖的com.otaliastudios:transcoder:0.9.1可能已从公共Maven仓库移除。打开pubspec.yaml,将video_compress版本更新为最新稳定版,例如:

    dependencies:
      video_compress: ^3.1.1 # 请确认当前最新版本号
    

    更新后执行flutter pub get,再尝试构建项目。

  • 添加缺失的Maven仓库
    若升级版本后问题仍存在,可在项目根目录的android/build.gradle中添加JCenter仓库(部分旧依赖仍托管于此):

    allprojects {
        repositories {
            google()
            mavenCentral()
            jcenter() // 添加该行
        }
    }
    
  • 强制指定可用的transcoder版本
    如果上述方法无效,可在android/app/build.gradle中强制替换transcoder版本为仓库中存在的版本(如0.10.5):

    dependencies {
        implementation('com.otaliastudios:transcoder:0.10.5') {
            force = true
        }
    }
    

    执行flutter clean和flutter pub get后重新构建。

  • 替换为其他维护活跃的包
    若video_compress的依赖问题无法解决,可考虑使用flutter_video_compress或video_editor等替代包,这些包依赖的底层库更稳定。

内容的提问来源于stack exchange,提问作者Jabid Hasan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 12:15:31