【问题标题】:How does one resolve: Gradle task assembleDebug failed with exit code 1 error? for video compress如何解决:Gradle 任务 assembleDebug failed with exit code 1 error?用于视频压缩
【发布时间】:2025-12-27 18:20:23
【问题描述】:

尝试在模拟器上运行我的应用程序,但不断收到此错误:

e: C:\flutter.pub-cache\hosted\pub.dartlang.org\video_compress-2.0.0\android\src\main\kotlin\com\example\video_compress\VideoCompressPlugin.kt: (25, 7 ): 重新声明:VideoCompressPlugin e: C:\flutter.pub-cache\hosted\pub.dartlang.org\video_compress-2.1.0\android\src\main\kotlin\com\example\video_compress\VideoCompressPlugin.kt: (28, 7): 重新声明: 视频压缩插件 e: C:\flutter.pub-cache\hosted\pub.dartlang.org\video_compress-2.1.0\android\src\main\kotlin\com\example\video_compress\VideoCompressPlugin.kt: (184, 28): 不能访问“”:它在“VideoCompressPlugin”中是私有的 e: C:\flutter.pub-cache\hosted\pub.dartlang.org\video_compress-2.1.0\android\src\main\kotlin\com\example\video_compress\VideoCompressPlugin.kt: (184, 48): 否为参数“活动”传递的值 e: C:\flutter.pub-cache\hosted\pub.dartlang.org\video_compress-2.1.0\android\src\main\kotlin\com\example\video_compress\VideoCompressPlugin.kt: (184, 48): 否为参数“上下文”传递的值 e: C:\flutter.pub-cache\hosted\pub.dartlang.org\video_compress-2.1.0\android\src\main\kotlin\com\example\video_compress\VideoCompressPlugin.kt: (184, 48): 否为参数“通道”传递的值 e: C:\flutter.pub-cache\hosted\pub.dartlang.org\video_compress-2.1.0\android\src\main\kotlin\com\example\video_compress\VideoCompressPlugin.kt: (185, 22): 未解决参考:初始化

FAILURE:构建失败并出现异常。

  • 出了什么问题: 任务 ':video_compress:compileDebugKotlin' 执行失败。

编译错误。查看日志了解更多详情

到目前为止我所做的尝试:

  • 运行 Flutter Doctor 没有问题。
  • 向下和向上更改视频压缩依赖项的版本没有变化(video_compress:^2.1.0)
  • 将 Flutter 更新到最新版本(当前为 51.0.2)
  • 将 flutter_svg: ^0.18.0 添加到 pubspec
  • 颤抖干净
  • 使 Android Studio 中的缓存失效

可能的罪犯?

_submit() async {
if (videoList.isEmpty || outputPath.isEmpty) return;

if (!isLoading) {
  setState(() {
    isLoading = true;
  });
}
print('LOG: outputPath: $outputPath');
var outPutFileExists = await File(outputPath).exists();
print('LOG: output file exists $outPutFileExists');

videoUrl = await StorageService.uploadVideo(File(outputPath));
imageUrl = await StorageService.uploadVideoThumbnail(File(outputPath));

Post post = Post(
    imageUrl: imageUrl,
    videoUrl: videoUrl,
    likeCount: 0,
    authorId: Provider.of<UserData>(context).currentUserId,
    timestamp: Timestamp.fromDate(DateTime.now()),
    viewCount: 0,
    mode: 'Beginner',
    cardId: widget.card.card[0],
    category: widget.card.category,
    flagged: false,
    flags: []);

另一种可能性:

 static Future<MediaInfo> compressVideo(File file) async {
    final info = await VideoCompress.compressVideo(
      file.path,
      quality: VideoQuality.HighestQuality,
      deleteOrigin: false,
    );

    return info;
  }

第三次尝试:

    static Future<String> uploadVideo(File videoFile) async {
    String videoId = Uuid().v4();
    MediaInfo videoInfo = await compressVideo(videoFile);
    StorageUploadTask uploadTask =
        storageRef.child('videos/video_$videoId.mp4').putFile(videoInfo.file);

    StorageTaskSnapshot storageSnap = await uploadTask.onComplete;
    String downloadUrl = await storageSnap.ref.getDownloadURL();
    return downloadUrl;
  }

  static Future<String> uploadVideoThumbnail(File videoFile) async {
    String photoId = Uuid().v4();
    final thumbnailFile = await VideoCompress.getFileThumbnail(videoFile.path,
        quality: 100, // default(100)
        position: -1 // default(-1)
        );
    StorageUploadTask uploadTask = storageRef
        .child('images/thumbnails/image_$photoId.jpg')
        .putFile(thumbnailFile);
    StorageTaskSnapshot storageSnap = await uploadTask.onComplete;
    String downloadUrl = await storageSnap.ref.getDownloadURL();
    return downloadUrl;
  }

非常感谢您的指导。

汤姆

【问题讨论】:

  • 嘿,通过您的错误消息,您的方法通道有问题,您提供的任何信息都不够,请提供定义通道的 mainActivity 代码以及相关颤振代码跨度>
  • 嘿 Atul,MainActivity 文件中没有太多信息。您是否需要查看整个页面代码才能看到错误在哪里?
  • 您是否使用方法通道来访问某些特定于平台的功能??如果是,则共享与您访问方法通道的主要活动和颤动代码相关的所有代码
  • 嘿阿图尔,请看上面。希望对您有所帮助。

标签: flutter gradle build


【解决方案1】:

尝试在 pubsec.yaml 中添加此包 flutter_svg: ^0.18.0,然后重试。

并尝试这些给定的步骤 https://nabil6391.medium.com/solutions-to-flutter-error-gradle-task-assembledebug-failed-with-exit-code-1-1d2c36b2001a

【讨论】:

  • 嘿 Mohammad,感谢在将 flutter_svg: ^0.18.0 添加到 pubspec 时没有改变 :(
  • @nerdMonkey 然后是尝试另一个视频压缩包的更好选择
【解决方案2】:

对我来说,答案是由于各种原因,我的 main.dart 文件位于 lib 文件夹之外。我把它移回了 lib。

除此之外,我从 Android Studio 项目选项卡中删除了 gradle 文件,然后重新构建。我还归档 > 无效缓存。现在似乎可以解决问题了。

【讨论】:

    最近更新 更多