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

Java-side code calls channel.invokeMethod, but Flutter-side channel's methodCallHandler does not trigger #198

Closed
SkycladObserver opened this issue Jan 21, 2020 · 2 comments

Comments

@SkycladObserver
Copy link

SkycladObserver commented Jan 21, 2020

Version of flutter_sound

2.0.1

flutter doctor

[v] Flutter (Channel stable, v1.12.13+hotfix.5, on Microsoft Windows [Version 10.0.16299.15], locale en-US)
• Flutter version 1.12.13+hotfix.5 at C:\flutter
• Framework revision 27321ebbad (6 weeks ago), 2019-12-10 18:15:01 -0800
• Engine revision 2994f7e1e6
• Dart version 2.7.0

[v] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at C:\Users\BANONAS\AppData\Local\Android\Sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-29, build-tools 29.0.2
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)
• All Android licenses accepted.

[v] Android Studio (version 3.5)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin version 42.1.1
• Dart plugin version 191.8593
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)

[v] VS Code (version 1.41.1)
• VS Code at C:\Users\BANONAS\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.7.1

[v] Connected device (2 available)
• SM G9250 • 02157df25d9bbb0c • android-arm64 • Android 7.0 (API 24)
• Android SDK built for x86 • emulator-5554 • android-x86 • Android 10 (API 29) (emulator)

Platforms you faced the error (IOS or Android or both?)

Android

Expected behavior

On tap of record, recorder should start recording in the Android side. While recording, some added logs to check if recorder is running should show. channel.invokeMethod("updateRecorderProgress", json.toString()); should be called every tick.

Actual behavior

On tap of record, the recorder starts. Logs do show. It's assumed that channel.invokeMethod("updateRecorderProgress", json.toString()); is called. In the flutter side however, channel's methodCallHandler doesn't trigger.

Tested environment (Emulator? Real Device?)

  • Emulators with Android SDK 28 and 29
  • Samsung Galaxy S6 Edge (Android version 7.0)

Steps to reproduce the behavior

I've tried the example, and I've tried using flutter_sound in isolation, and flutter sound works well with no hiccups. When integrating with my project though, it doesn't work. My guess is it might clash with other dependencies?

here's a snippet from my pubspec.yaml:

environment:
  sdk: ">=2.4.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter

  background_fetch: ^0.2.0
  circular_profile_avatar: ^1.0.2
  cupertino_icons: ^0.1.2
  flutter_local_notifications: ^0.8.4
  flutter_range_slider: ^0.0.4
  rxdart: ^0.21.0
  logger: ^1.0.2
  intl: ^0.16.0 
  package_info: 0.4.0+4
  easy_localization: ^1.3.1
  equatable: ^0.2.6
  path_provider: ^1.4.0
  permission_handler: ^4.0.0
  provider: ^3.0.0
  synchronized: ^2.1.0
  archive: ^2.0.8
  flutter_email_sender: ^2.0.3
  flutter_linkify: ^2.1.0
  flutter_sound: 2.0.1
  auto_size_text: ^1.1.2
  vhcbloc: ^1.0.4
  indexed_list_view: ^1.0.7
  faker: ^1.1.0
  tuple: ^1.0.2
  overlay_support: ^1.0.2
  respect_24_hour: ^0.0.2
  url_launcher: ^5.1.2
  linkify: ^1.0.1
  uuid: ^2.0.2
  
dev_dependencies:
  flutter_test:
    sdk: flutter
  flutter_driver:
    sdk: flutter
@SkycladObserver
Copy link
Author

SkycladObserver commented Jan 21, 2020

I've found a solution, but I'm not too sure why it works: Registrar reg and MethodChannel channel should not be static. These are my changes to the code:

  private Registrar reg;
  private MethodChannel channel;

  private FlutterSoundPlugin(Registrar registrar){
    channel = new MethodChannel(registrar.messenger(), "flutter_sound");
    channel.setMethodCallHandler(this);
    reg = registrar;
  }

    /** Plugin registration. */
  public static void registerWith(Registrar registrar) {
    FlutterSoundPlugin plugin = new FlutterSoundPlugin(registrar);
  }

Again, not so sure why using statics messes it up. I tried this solution because channel of channel.invokeMethod might have a different value for channel, so invokeMethod might be calling a different method handler in the flutter side.

I hope this change could be implemented, it's quite the big blocker :( Thank you so much!

@hyochan
Copy link
Collaborator

hyochan commented Jan 24, 2020

I guess this is why the flutter team provided such migration as @bsutton stated in #203. I'll update the code and release this in 2.0.3. Thanks for sharing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants