Skip to content

Comments

Android fixes#25

Merged
bkonyi merged 27 commits intomasterfrom
unknown repository
Nov 1, 2019
Merged

Android fixes#25
bkonyi merged 27 commits intomasterfrom
unknown repository

Conversation

@ghost
Copy link

@ghost ghost commented Oct 30, 2019

There are a few fixes here:

  • This migrates the plugin to AndroidX
  • Upgrades gradle, google play services and kotlin version
  • It executes calls to the background channel on Android on the main thread.

@bkonyi
Copy link
Owner

bkonyi commented Oct 30, 2019

Awesome, thanks for the cleanup! A couple of questions:

  • Why do we want to explicitly execute calls to the background channel on the main thread? Is there a performance reason?
  • I see you've published this on pub. While I wasn't planning on publishing this as a production quality plugin, clearly there's demand for it so I should check with the plugins team to see if we want to support it officially. Would you mind adding me as an uploader / admin for the project in the meantime?

@ghost
Copy link
Author

ghost commented Oct 31, 2019

Why do we want to explicitly execute calls to the background channel on the main thread? Is there a performance reason?

I saw this exception on https://github.com/KarimAbdo/FlutterGeofencing:

E/AndroidRuntime(10771): Caused by: java.lang.RuntimeException: Methods marked with @UiThread must be executed on the main thread. Current thread: AsyncTask #1
E/AndroidRuntime(10771): 	at io.flutter.embedding.engine.FlutterJNI.ensureRunningOnMainThread(FlutterJNI.java:807)
E/AndroidRuntime(10771): 	at io.flutter.embedding.engine.FlutterJNI.dispatchPlatformMessage(FlutterJNI.java:697)
E/AndroidRuntime(10771): 	at io.flutter.embedding.engine.dart.DartMessenger.send(DartMessenger.java:80)
E/AndroidRuntime(10771): 	at io.flutter.embedding.engine.dart.DartExecutor.send(DartExecutor.java:187)
E/AndroidRuntime(10771): 	at io.flutter.view.FlutterNativeView.send(FlutterNativeView.java:128)
E/AndroidRuntime(10771): 	at io.flutter.plugin.common.MethodChannel.invokeMethod(MethodChannel.java:98)
E/AndroidRuntime(10771): 	at io.flutter.plugin.common.MethodChannel.invokeMethod(MethodChannel.java:84)
E/AndroidRuntime(10771): 	at io.flutter.plugins.geofencing.GeofencingService.onHandleWork(GeofencingService.kt:147)
E/AndroidRuntime(10771): 	at androidx.core.app.JobIntentService$CommandProcessor.doInBackground(JobIntentService.java:392)
E/AndroidRuntime(10771): 	at androidx.core.app.JobIntentService$CommandProcessor.doInBackground(JobIntentService.java:383)
E/AndroidRuntime(10771): 	at android.os.AsyncTask$3.call(AsyncTask.java:378)
E/AndroidRuntime(10771): 	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
E/AndroidRuntime(10771): 	... 3 more

I can see that this is not an issue on your project. So I removed that change again.

I see you've published this on pub. While I wasn't planning on publishing this as a production quality plugin, clearly there's demand for it so I should check with the plugins team to see if we want to support it officially. Would you mind adding me as an uploader / admin for the project in the meantime?

I am not the one who published it. From what I can see this: https://pub.dev/packages/geofencing was published by axella.gerald@gmail.com. Furthermore the fork from https://github.com/KarimAbdo/FlutterGeofencing seems to be published as well: https://pub.dev/packages/flutter_geofencing

I have reverted a few extra minor things to minimize the diff.

@ghost
Copy link
Author

ghost commented Oct 31, 2019

I tried registering a geofence again. After a little time I got the exception below. I will add the change that executes on the main thread again:

E/AndroidRuntime(12533): Process: io.flutter.plugins.geofencingexample, PID: 12533
E/AndroidRuntime(12533): java.lang.RuntimeException: An error occurred while executing doInBackground()
E/AndroidRuntime(12533): 	at android.os.AsyncTask$4.done(AsyncTask.java:399)
E/AndroidRuntime(12533): 	at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
E/AndroidRuntime(12533): 	at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
E/AndroidRuntime(12533): 	at java.util.concurrent.FutureTask.run(FutureTask.java:271)
E/AndroidRuntime(12533): 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
E/AndroidRuntime(12533): 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
E/AndroidRuntime(12533): 	at java.lang.Thread.run(Thread.java:919)
E/AndroidRuntime(12533): Caused by: java.lang.RuntimeException: Methods marked with @UiThread must be executed on the main thread. Current thread: AsyncTask #1
E/AndroidRuntime(12533): 	at io.flutter.embedding.engine.FlutterJNI.ensureRunningOnMainThread(FlutterJNI.java:807)

LICENSE Outdated
@@ -1 +1,5 @@
TODO: Add your license here.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove this license? I'll need to update this to match the licenses in the actual source (whatever the Flutter project uses).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have removed it.

@@ -1 +1,3 @@
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really nitpicky request, but can you ensure this file is sorted alphabetically?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure - that is a minor fix.

@bkonyi
Copy link
Owner

bkonyi commented Oct 31, 2019

Why do we want to explicitly execute calls to the background channel on the main thread? Is there a performance reason?

I saw this exception on https://github.com/KarimAbdo/FlutterGeofencing:

E/AndroidRuntime(10771): Caused by: java.lang.RuntimeException: Methods marked with @UiThread must be executed on the main thread. Current thread: AsyncTask #1
E/AndroidRuntime(10771): 	at io.flutter.embedding.engine.FlutterJNI.ensureRunningOnMainThread(FlutterJNI.java:807)
E/AndroidRuntime(10771): 	at io.flutter.embedding.engine.FlutterJNI.dispatchPlatformMessage(FlutterJNI.java:697)
E/AndroidRuntime(10771): 	at io.flutter.embedding.engine.dart.DartMessenger.send(DartMessenger.java:80)
E/AndroidRuntime(10771): 	at io.flutter.embedding.engine.dart.DartExecutor.send(DartExecutor.java:187)
E/AndroidRuntime(10771): 	at io.flutter.view.FlutterNativeView.send(FlutterNativeView.java:128)
E/AndroidRuntime(10771): 	at io.flutter.plugin.common.MethodChannel.invokeMethod(MethodChannel.java:98)
E/AndroidRuntime(10771): 	at io.flutter.plugin.common.MethodChannel.invokeMethod(MethodChannel.java:84)
E/AndroidRuntime(10771): 	at io.flutter.plugins.geofencing.GeofencingService.onHandleWork(GeofencingService.kt:147)
E/AndroidRuntime(10771): 	at androidx.core.app.JobIntentService$CommandProcessor.doInBackground(JobIntentService.java:392)
E/AndroidRuntime(10771): 	at androidx.core.app.JobIntentService$CommandProcessor.doInBackground(JobIntentService.java:383)
E/AndroidRuntime(10771): 	at android.os.AsyncTask$3.call(AsyncTask.java:378)
E/AndroidRuntime(10771): 	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
E/AndroidRuntime(10771): 	... 3 more

I can see that this is not an issue on your project. So I removed that change again.

That's interesting, I'm surprised I've never run into that myself (unless it's happening and it's only being logged without bringing up a crash dialog). It looks like you're right though as my colleague made a similar change to the android_alarm_manager plugin that I maintain, which also utilizes background execution (see here).

I see you've published this on pub. While I wasn't planning on publishing this as a production quality plugin, clearly there's demand for it so I should check with the plugins team to see if we want to support it officially. Would you mind adding me as an uploader / admin for the project in the meantime?

I am not the one who published it. From what I can see this: https://pub.dev/packages/geofencing was published by axella.gerald@gmail.com. Furthermore the fork from https://github.com/KarimAbdo/FlutterGeofencing seems to be published as well: https://pub.dev/packages/flutter_geofencing

I have reverted a few extra minor things to minimize the diff.

Ah, sorry about the confusion. GitHub names don't always match to Pub developer emails so I just made a bad assumption :-).

@bkonyi bkonyi merged commit a8de907 into bkonyi:master Nov 1, 2019
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

Successfully merging this pull request may close these issues.

2 participants