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

AudiofileplayerPlugin breaks automatic plugin registration #63

Closed
mrhabibi opened this issue Apr 10, 2020 · 3 comments
Closed

AudiofileplayerPlugin breaks automatic plugin registration #63

mrhabibi opened this issue Apr 10, 2020 · 3 comments

Comments

@mrhabibi
Copy link

mrhabibi commented Apr 10, 2020

Hi,

I have an issue with audiofileplayer plugin registration, when this plugin is invoked automatically by the isolate, it always crashes and makes other plugins can't be loaded as well.

I've traced the exception and here's where the crash came from:

128 | private AudiofileplayerPlugin(Registrar registrar, MethodChannel methodChannel) {
129 |     this.registrar = registrar;
130 |     this.methodChannel = methodChannel;
131 |     this.mediaPlayers = new HashMap<>();
132 |     LifecycleCallbacks callbacks = new LifecycleCallbacks(this, registrar.activity().hashCode());
133 |     registrar.activity().getApplication().registerActivityLifecycleCallbacks(callbacks);

In line 132, it returned null when calling registrar.activity() and it crashed with NullPointerException when accessing hashCode(), is there no null check there? Because in ShimRegistrar, that method may return null when activityPluginBinding is a null too.

And this is my environment:

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, v1.12.13+hotfix.9, on Microsoft Windows [Version 10.0.18363.720], locale en-ID)

[√] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
[√] Android Studio (version 3.6)
[√] IntelliJ IDEA Community Edition (version 2019.3)
[√] VS Code (version 1.44.0)
[√] Connected device (1 available)

• No issues found!

I use latest plugin version 1.2.0, any workaround or a fix for this? Thanks.

@monkeyswarm
Copy link
Collaborator

I just pushed v 1.3 to pub.dev, which updates the plugin to use new Android embeddings. Please let me know if this fixes your problem.

Also, as per your bug report, what are you doing differently in your app (in comparison to the audiofileplayer example app)? Are you instantiating something while the app is backgrounded? (That could cause a null Activity) And when you say, Isolate, I assume you mean the main thread (as Plugins cannot communicate on any other thread/isolate, so if you are trying to init or communicate with a plugin on a new isolate, it is not expected to work).

@mrhabibi
Copy link
Author

Nice! it works now!

So, I used android_alarm_manager too in my app, but I didn't combine it with audiofileplayer directly.

The problem was when android alarm manager was triggered, it instantiated FlutterEngine in an isolate and found GeneratedPluginRegistrant using reflection, then it registered plenty of plugins and when it processed AudiofileplayerPlugin, it threw an exception because of trying to access hashCode() above, it didn't crash because FlutterEngine muted it with try catch and other plugins wouldn't be executed as well because of that exception.

FlutterEngine just said Tried to automatically register plugins with FlutterEngine (io.flutter.embedding.engine.FlutterEngine@c291c8d) but could not find and invoke the GeneratedPluginRegistrant., that wasn't an informative message at all, so I needed to attach debugger in java myself to find the root cause.

Well, thank you for your fast response, cheers!

@szantogab
Copy link

@monkeyswarm I can see the line in AudiofileplayerPlugin.java:142 line is still there:
LifecycleCallbacks callbacks = new LifecycleCallbacks(this, activity.hashCode());

and because we're running in an Isolate there's no activity, so the NullPointerException still applies.

Or am I missing something?

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

3 participants