Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flutter | On Android only - Unhandled Exception: MissingPluginException (No implementation found for method getLogLevel on channel flutter.arthenica.com/ffmpeg_kit) #461

Closed
orenagiv opened this issue Jun 15, 2022 · 23 comments
Labels
flutter Affect flutter platform needs-analysis We don't know that this is. It must be investigated further v4.5.1 Affects v4.5.1 release

Comments

@orenagiv
Copy link

orenagiv commented Jun 15, 2022

Hello there :)

I'm working on a Flutter plugin which allows to use the DJI SDK for drones.
I'm receiving a raw H264 byte-stream from the DJI SDK > listens to it on the Flutter side > and streams it into the ffmpeg-kit input-pipe to convert into HLS to MP4 format.

It works amazingly well on iOS (thanks @tanersener for this amazing plugin!)

For some reason, when I try to run my example on Android, I get the following error:

Unhandled Exception: MissingPluginException (No implementation found for method getLogLevel on channel flutter.arthenica.com/ffmpeg_kit)

It's probably somehow related to this one:
https://github.com/tanersener/ffmpeg-kit/issues/367
But I'm not using 'isolates' (as far as I know :)
However, I AM using "pigeon" to generate the code between Flutter and the host platform:
https://pub.dev/packages/pigeon

My plugin can be found here:
https://pub.dev/packages/dji

And the example code which uses the plugin with the ffmpeg-kit can be found here:
https://github.com/DragonX-cloud/dji_flutter_plugin/blob/main/example/lib/example.dart

Any ideas would be most welcome 🙏

@tanersener
Copy link
Collaborator

Logs are needed to be able to make a comment about it.

@orenagiv
Copy link
Author

orenagiv commented Jun 16, 2022

Hi @tanersener

Logs from the Android Studio logcat:

2022-06-16 19:59:05.102 1361-1425/cloud.dragonx.plugin.flutter.djiExample I/flutter: Loading ffmpeg-kit-flutter.
2022-06-16 19:59:05.285 1361-1425/cloud.dragonx.plugin.flutter.djiExample E/flutter: [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: MissingPluginException(No implementation found for method getLogLevel on channel flutter.arthenica.com/ffmpeg_kit)
    #0      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:165:7)
    <asynchronous suspension>
    #1      FFmpegKitInitializer._initialize (package:ffmpeg_kit_flutter/src/ffmpeg_kit_flutter_initializer.dart:313:22)
    <asynchronous suspension>
    #2      FFmpegKitInitializer.initialize (package:ffmpeg_kit_flutter/src/ffmpeg_kit_flutter_initializer.dart:54:7)
    <asynchronous suspension>
    #3      FFmpegKitConfig.init (package:ffmpeg_kit_flutter/ffmpeg_kit_config.dart:50:5)
    <asynchronous suspension>
    #4      FFmpegKitConfig.registerNewFFmpegPipe (package:ffmpeg_kit_flutter/ffmpeg_kit_config.dart:136:7)
    <asynchronous suspension>

Similar logs from VSCode Debug Console:

✓  Built build/app/outputs/flutter-apk/app-debug.apk.
W/FlutterActivityAndFragmentDelegate( 2236): A splash screen was provided to Flutter, but this is deprecated. See flutter.dev/go/android-splash-migration for migration steps.
Connecting to VM Service at ws://127.0.0.1:54651/CUJb4MZTpiI=/ws
D/ViewRootImpl@9ac45be[MainActivity]( 2236): ViewPostIme pointer 0
D/ViewRootImpl@9ac45be[MainActivity]( 2236): ViewPostIme pointer 1
[dji.flutter] Video Feed Start requested
I/flutter ( 2236): Loading ffmpeg-kit-flutter.

════════ Exception caught by services library ══════════════════════════════════
The following MissingPluginException was thrown while activating platform stream on channel flutter.arthenica.com/ffmpeg_kit_event:
MissingPluginException(No implementation found for method listen on channel flutter.arthenica.com/ffmpeg_kit_event)

When the exception was thrown, this was the stack
#0      MethodChannel._invokeMethod
package:flutter/…/services/platform_channel.dart:165
<asynchronous suspension>
#1      EventChannel.receiveBroadcastStream.<anonymous closure>
package:flutter/…/services/platform_channel.dart:506
<asynchronous suspension>
════════════════════════════════════════════════════════════════════════════════
E/flutter ( 2236): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: MissingPluginException(No implementation found for method getLogLevel on channel flutter.arthenica.com/ffmpeg_kit)
E/flutter ( 2236): #0      MethodChannel._invokeMethod
package:flutter/…/services/platform_channel.dart:165
E/flutter ( 2236): <asynchronous suspension>
E/flutter ( 2236): #1      FFmpegKitInitializer._initialize
package:ffmpeg_kit_flutter/src/ffmpeg_kit_flutter_initializer.dart:313
E/flutter ( 2236): <asynchronous suspension>
E/flutter ( 2236): #2      FFmpegKitInitializer.initialize
package:ffmpeg_kit_flutter/src/ffmpeg_kit_flutter_initializer.dart:54
E/flutter ( 2236): <asynchronous suspension>
E/flutter ( 2236): #3      FFmpegKitConfig.init
package:ffmpeg_kit_flutter/ffmpeg_kit_config.dart:50
E/flutter ( 2236): <asynchronous suspension>
E/flutter ( 2236): #4      FFmpegKitConfig.registerNewFFmpegPipe
package:ffmpeg_kit_flutter/ffmpeg_kit_config.dart:136
E/flutter ( 2236): <asynchronous suspension>
E/flutter ( 2236):
Lost connection to device.
Exited

@tanersener
Copy link
Collaborator

You have the same stack trace as the isolates issue. It seems like either an isolate or another background thread-like entity is created. And that entity is trying to call FFmpegKit API methods.

@tanersener tanersener added flutter Affect flutter platform needs-analysis We don't know that this is. It must be investigated further v4.5.1 Affects v4.5.1 release labels Jun 17, 2022
@orenagiv
Copy link
Author

Thanks @tanersener

I wonder why it works on iOS and not on Android.

Anyway, I'm investigating.

Will keep you posted.

@orenagiv
Copy link
Author

orenagiv commented Jun 18, 2022

Hey @tanersener

Quick update:
I've managed to temporarily workaround the issue, by manually changing the order of the Flutter plugins registration in app/java/io.flutter.plugins/GeneratedPluginRegistrant.java.
If the first one is the ffmpeg-kit - then it works, and I no longer get the error above.

Example of the GeneratedPluginRegistrant.java file after placing the ffmpeg-kit to be there first one:

package io.flutter.plugins;

import androidx.annotation.Keep;
import androidx.annotation.NonNull;
import io.flutter.Log;

import io.flutter.embedding.engine.FlutterEngine;

/**
 * Generated file. Do not edit.
 * This file is generated by the Flutter tool based on the
 * plugins that support the Android platform.
 */
@Keep
public final class GeneratedPluginRegistrant {
  private static final String TAG = "GeneratedPluginRegistrant";
  public static void registerWith(@NonNull FlutterEngine flutterEngine) {
    try {
      flutterEngine.getPlugins().add(new com.arthenica.ffmpegkit.flutter.FFmpegKitFlutterPlugin());
    } catch(Exception e) {
      Log.e(TAG, "Error registering plugin ffmpeg_kit_flutter, com.arthenica.ffmpegkit.flutter.FFmpegKitFlutterPlugin", e);
    }
    try {
      flutterEngine.getPlugins().add(new software.solid.fluttervlcplayer.FlutterVlcPlayerPlugin());
    } catch(Exception e) {
      Log.e(TAG, "Error registering plugin flutter_vlc_player, software.solid.fluttervlcplayer.FlutterVlcPlayerPlugin", e);
    }
    try {
      flutterEngine.getPlugins().add(new cloud.dragonx.plugin.flutter.dji.DjiPlugin());
    } catch(Exception e) {
      Log.e(TAG, "Error registering plugin dji, cloud.dragonx.plugin.flutter.dji.DjiPlugin", e);
    }
  }
}

Still investigating...

@orenagiv
Copy link
Author

Quick update:
Couldn't find the root cause.
For now - I'm using the above workaround (by placing manually changing the order of the plugins).

@orenagiv
Copy link
Author

orenagiv commented Jul 2, 2022

Hey @tanersener
I don't have any further insights about this one.
The change of plugin sequence as described in my previous comment is the workaround I'm using.

From my perspective you can close the issue.

Thanks 🙏

@CodeWithOz
Copy link

@orenagiv when I try this the order gets reverted once I do a new build, and the problem doesn't go away. Was there a particular way you made the change that caused it to persist?

@orenagiv
Copy link
Author

orenagiv commented Aug 8, 2022

Hey @CodeWithOz,
I've recently updated my pubspec.yaml to use the full_gpl version, and I think it might have resolved the issue:

ffmpeg_kit_flutter_full_gpl: ^4.5.1

I'm not sure, as I haven't reverted and double checked yet.
But please do, and let me know if it made any difference.

@CodeWithOz
Copy link

I was already using that actually, but with the version specified as 4.5.1-LTS rather than ^4.5.1 as you have it. I tried what you have and it didn't fix the problem 😭 .

@orenagiv
Copy link
Author

orenagiv commented Aug 8, 2022

Hey @CodeWithOz,

Please edit the sequence of plugins as I described in one of my previous comments, and then run the build from Android Studio.

Let me know if it works.

Then, build again via Flutter, and let me know if it is still successful.

@CodeWithOz
Copy link

@orenagiv I tried using Android Studio and the same thing happened, the order was reset after I ran the build and the problem didn't go away. 😢

@orenagiv
Copy link
Author

orenagiv commented Aug 9, 2022

Hey @CodeWithOz
That's probably because you used Android Studio with the Flutter framework.

Try to open the Android workspace on its own - as a pure native Android project.
And then compile it from there.

Let me know how it goes :)

@BrindaRathodB
Copy link

Why this issue has been closed, I got the same issue on an android device kindly reopen it

@BrindaRathodB
Copy link

@orenagiv @CodeWithOz have the above issue is fixed? because I did try above solutions bt it didn’t work

@CodeWithOz
Copy link

CodeWithOz commented Jan 2, 2023 via email

@BrindaRathodB
Copy link

Okay, thanks for the response @orenagiv

@zhubinsheng
Copy link

how to fix

@zhubinsheng
Copy link

loss implementation 'com.arthenica:smart-exception-java:0.2.1'
open android and start ,can see logcat error

@Esrko2905
Copy link

@zhubinsheng did you find the solution and cause of the issue?

@zhubinsheng
Copy link

@zhubinsheng您找到问题的解决方案和原因了吗?

yes。 need implementation 'com.arthenica:smart-exception-java:0.2.1'

@Esrko2905
Copy link

how to do that? is there any documentation available?

@vietnguyen312
Copy link

I encountered a similar issue while using FFmpeg in an Android background service. The problem may be due to the fact that the init() function in FFmpegKitFlutterPlugin.java is only called in onAttachedToActivity(), which is not available in a background service. To fix this, I suggest moving the init() function to onAttachedToEngine().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flutter Affect flutter platform needs-analysis We don't know that this is. It must be investigated further v4.5.1 Affects v4.5.1 release
Projects
None yet
Development

No branches or pull requests

7 participants