jonataslaw / jonataslaw/VideoCompress

[Android] deleteAllCache causes kotlin.Unit IllegalArgumentException and "Reply already submitted"

Open
#327 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Swift
Stars
262
Forks
344
PR merge metrics
No merged PRs in 30d

Description

## Description

On Android, calling `VideoCompress.deleteAllCache()` triggers native MethodChannel errors. The app usually does not crash, but logcat shows repeated errors on every invocation.

## Steps to Reproduce

1. Add `video_compress: ^3.1.4` to a Flutter project
2. Call `await VideoCompress.deleteAllCache()` from Dart (e.g. on screen/cubit init)
3. Run on Android device or emulator
4. Check logcat

## Logs
E/MethodChannel#video_compress( 5117): Failed to handle method call
E/MethodChannel#video_compress( 5117): java.lang.IllegalArgumentException: Unsupported value: 'kotlin.Unit' of type 'class kotlin.Unit'
E/MethodChannel#video_compress( 5117): at io.flutter.plugin.common.StandardMessageCodec.writeValue(StandardMessageCodec.java:297)
E/MethodChannel#video_compress( 5117): at io.flutter.plugin.common.StandardMethodCodec.encodeSuccessEnvelope(StandardMethodCodec.java:61)
E/MethodChannel#video_compress( 5117): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler$1.success(MethodChannel.java:272)
E/MethodChannel#video_compress( 5117): at com.example.video_compress.VideoCompressPlugin.onMethodCall(VideoCompressPlugin.kt:66)
E/MethodChannel#video_compress( 5117): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:267)
E/MethodChannel#video_compress( 5117): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:292)
E/MethodChannel#video_compress( 5117): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319)
E/MethodChannel#video_compress( 5117): at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(D8$$SyntheticClass:0)
E/MethodChannel#video_compress( 5117): at android.os.Handler.handleCallback(Handler.java:959)
E/MethodChannel#video_compress( 5117): at android.os.Handler.dispatchMessage(Handler.java:100)
E/MethodChannel#video_compress( 5117): at android.os.Looper.loopOnce(Looper.java:232)
E/MethodChannel#video_compress( 5117): at android.os.Looper.loop(Looper.java:317)
E/MethodChannel#video_compress( 5117): at android.app.ActivityThread.main(ActivityThread.java:8705)
E/MethodChannel#video_compress( 5117): at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#video_compress( 5117): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:580)
E/MethodChannel#video_compress( 5117): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:886)

## Expected Behavior

`deleteAllCache` should complete once and return a boolean to Dart without native errors.

## Actual Behavior

Native side throws:
- `IllegalArgumentException: Unsupported value: 'kotlin.Unit'`
- `IllegalStateException: Reply already submitted`

## Environment

- Package: `video_compress` 3.1.4
- Platform: Android
- Flutter version: 3.35.1

## Root Cause

`deleteAllCache` replies twice to the same MethodChannel call:

**`VideoCompressPlugin.kt` :**
```kotlin
"deleteAllCache" -> {
result.success(Utility(channelName).deleteAllCache(context, result));
}

Utility.kt

fun deleteAllCache(context: Context, result: MethodChannel.Result) {
val dir = context.getExternalFilesDir("video_compress")
result.success(dir?.deleteRecursively())
}

Utility.deleteAllCache already calls result.success(...). The outer result.success(...) in the plugin tries to send kotlin.Unit, which StandardMessageCodec cannot serialize.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.