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

Plugin does not work headless (fix included) #101

Closed
mootw opened this issue Jul 6, 2019 · 2 comments
Closed

Plugin does not work headless (fix included) #101

mootw opened this issue Jul 6, 2019 · 2 comments

Comments

@mootw
Copy link

mootw commented Jul 6, 2019

Hi,

This plugin has issues when launching in headless mode using background_fetch plugin.

Here is the fix for the issue

All plugin developers need to guard themselves against the case where an App can launch Headless, where registrar.activity() == null.

Relevant error logs:
07-04 14:56:31.110 10430 10430 E AndroidRuntime: FATAL EXCEPTION: main 07-04 14:56:31.110 10430 10430 E AndroidRuntime: Process: com.noaimgames.shadowweather, PID: 10430 07-04 14:56:31.110 10430 10430 E AndroidRuntime: java.lang.RuntimeException: java.lang.IllegalStateException: registrar.activity() must not be null 07-04 14:56:31.110 10430 10430 E AndroidRuntime: at android.app.job.JobServiceEngine$JobHandler.handleMessage(JobServiceEngine.java:112) 07-04 14:56:31.110 10430 10430 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:106) 07-04 14:56:31.110 10430 10430 E AndroidRuntime: at android.os.Looper.loop(Looper.java:214) 07-04 14:56:31.110 10430 10430 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:7032) 07-04 14:56:31.110 10430 10430 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method) 07-04 14:56:31.110 10430 10430 E AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494) 07-04 14:56:31.110 10430 10430 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965) 07-04 14:56:31.110 10430 10430 E AndroidRuntime: Caused by: java.lang.IllegalStateException: registrar.activity() must not be null 07-04 14:56:31.110 10430 10430 E AndroidRuntime: at com.builttoroam.devicecalendar.DeviceCalendarPlugin$Companion.registerWith(DeviceCalendarPlugin.kt:50) 07-04 14:56:31.110 10430 10430 E AndroidRuntime: at com.builttoroam.devicecalendar.DeviceCalendarPlugin.registerWith(Unknown Source:2) 07-04 14:56:31.110 10430 10430 E AndroidRuntime: at io.flutter.plugins.GeneratedPluginRegistrant.registerWith(GeneratedPluginRegistrant.java:35) 07-04 14:56:31.110 10430 10430 E AndroidRuntime: at com.noaimgames.shadowweather.Application.registerWith(Application.java:17) 07-04 14:56:31.110 10430 10430 E AndroidRuntime: at com.transistorsoft.flutter.backgroundfetch.HeadlessTask.initFlutterView(HeadlessTask.java:133) 07-04 14:56:31.110 10430 10430 E AndroidRuntime: at com.transistorsoft.flutter.backgroundfetch.HeadlessTask.<init>(HeadlessTask.java:47) 07-04 14:56:31.110 10430 10430 E AndroidRuntime: at com.transistorsoft.flutter.backgroundfetch.HeadlessJobService.onStartJob(HeadlessJobService.java:38) 07-04 14:56:31.110 10430 10430 E AndroidRuntime: at android.app.job.JobService$1.onStartJob(JobService.java:62) 07-04 14:56:31.110 10430 10430 E AndroidRuntime: at android.app.job.JobServiceEngine$JobHandler.handleMessage(JobServiceEngine.java:108) 07-04 14:56:31.110 10430 10430 E AndroidRuntime: ... 6 more 07-04 14:57:20.079 17712 17712 E AndroidRuntime: FATAL EXCEPTION: main 07-04 14:57:20.079 17712 17712 E AndroidRuntime: Process: com.noaimgames.shadowweather, PID: 17712 07-04 14:57:20.079 17712 17712 E AndroidRuntime: java.lang.RuntimeException: java.lang.IllegalStateException: registrar.activity() must not be null 07-04 14:57:20.079 17712 17712 E AndroidRuntime: at android.app.job.JobServiceEngine$JobHandler.handleMessage(JobServiceEngine.java:112) 07-04 14:57:20.079 17712 17712 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:106) 07-04 14:57:20.079 17712 17712 E AndroidRuntime: at android.os.Looper.loop(Looper.java:214) 07-04 14:57:20.079 17712 17712 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:7032) 07-04 14:57:20.079 17712 17712 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method) 07-04 14:57:20.079 17712 17712 E AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494) 07-04 14:57:20.079 17712 17712 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965) 07-04 14:57:20.079 17712 17712 E AndroidRuntime: Caused by: java.lang.IllegalStateException: registrar.activity() must not be null 07-04 14:57:20.079 17712 17712 E AndroidRuntime: at com.builttoroam.devicecalendar.DeviceCalendarPlugin$Companion.registerWith(DeviceCalendarPlugin.kt:50) 07-04 14:57:20.079 17712 17712 E AndroidRuntime: at com.builttoroam.devicecalendar.DeviceCalendarPlugin.registerWith(Unknown Source:2) 07-04 14:57:20.079 17712 17712 E AndroidRuntime: at io.flutter.plugins.GeneratedPluginRegistrant.registerWith(GeneratedPluginRegistrant.java:35) 07-04 14:57:20.079 17712 17712 E AndroidRuntime: at com.noaimgames.shadowweather.Application.registerWith(Application.java:17) 07-04 14:57:20.079 17712 17712 E AndroidRuntime: at com.transistorsoft.flutter.backgroundfetch.HeadlessTask.initFlutterView(HeadlessTask.java:133) 07-04 14:57:20.079 17712 17712 E AndroidRuntime: at com.transistorsoft.flutter.backgroundfetch.HeadlessTask.<init>(HeadlessTask.java:47) 07-04 14:57:20.079 17712 17712 E AndroidRuntime: at com.transistorsoft.flutter.backgroundfetch.HeadlessJobService.onStartJob(HeadlessJobService.java:38) 07-04 14:57:20.079 17712 17712 E AndroidRuntime: at android.app.job.JobService$1.onStartJob(JobService.java:62) 07-04 14:57:20.079 17712 17712 E AndroidRuntime: at android.app.job.JobServiceEngine$JobHandler.handleMessage(JobServiceEngine.java:108) 07-04 14:57:20.079 17712 17712 E AndroidRuntime: ... 6 more

flutter doctor -v
[√] Flutter (Channel stable, v1.5.4-hotfix.2, on Microsoft Windows [Version 10.0.18362.175], locale en-US)
• Flutter version 1.5.4-hotfix.2 at C:\flutter\sdk\flutter
• Framework revision 7a4c33425d (10 weeks ago), 2019-04-29 11:05:24 -0700
• Engine revision 52c7a1e849
• Dart version 2.3.0 (build 2.3.0-dev.0.5 a1668566e5)

[√] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
• Android SDK at C:\Users\Spencer\AppData\Local\Android\sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-28, build-tools 28.0.3
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01)
• All Android licenses accepted.

[√] Android Studio (version 3.3)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin version 32.0.1
• Dart plugin version 182.5124
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01)

[√] Connected device (1 available)
• SM G973U • RF8M13837GY • android-arm64 • Android 9 (API 28)

• No issues found!

@MaikuB
Copy link
Contributor

MaikuB commented Jul 30, 2019

Are you able to add a git dependency (see documentation here) that would point to the 101 branch to see if it solves the problem? If it doesn't, would appreciate it if you can provide a sample app to reproduce the issue

@mootw
Copy link
Author

mootw commented Jul 31, 2019

I added the branch as a dependency and it solved the problem for me. I did find another issue which I will open a separate ticket for as it is unrelated. Thanks!

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