bkonyi / fluttergeofencing Goto Github PK
View Code? Open in Web Editor NEWRough work for Flutter geofencing plugin
License: BSD 3-Clause "New" or "Revised" License
Rough work for Flutter geofencing plugin
License: BSD 3-Clause "New" or "Revised" License
I'm using this great plugin for geofencing in my app. Geofencing is the only location service that is used in the background by my app, no location updates or similiar things.
The app got rejected by Apple because it included the background location mode as a capability without using any background location features.
Since the plugin sets allowsBackgroundLocationUpdates
to true, the app crashes right away when you don't include the background mode.
Removing the background mode and not setting allowsBackgroundLocationUpdates
actually works with region monitoring and even launches the app in the background after being swiped off.
Apple's documentation is very misleading and lacking in that regard (like usual) in my opinion, I was quite surprised by that and thought the background mode was obvious for this usecase.
To prevent apps from being rejected, allowsBackgroundLocationUpdates
should probably be controlled by a parameter in the GeofencingManager.initialize()
method.
I am getting the error below after a fence be registered. I've tested in some devices and all reproduced the same error.
Did someone already got this exception?
Could it be caused by another plugin I'm using?
I/GeofencingService(19227): Starting GeofencingService...
D/AndroidRuntime(19227): Shutting down VM
E/AndroidRuntime(19227): FATAL EXCEPTION: main
E/AndroidRuntime(19227): Process: com.example.geofencing_test, PID: 19227
E/AndroidRuntime(19227): java.lang.RuntimeException: Unable to create service io.flutter.plugins.geofencing.GeofencingService: java.lang.NullPointerException: Attempt to invoke virtual method 'android.os.Looper android.app.Activity.getMainLooper()' on a null object reference
E/AndroidRuntime(19227): at android.app.ActivityThread.handleCreateService(ActivityThread.java:3883)
E/AndroidRuntime(19227): at android.app.ActivityThread.access$2100(ActivityThread.java:229)
E/AndroidRuntime(19227): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1909)
E/AndroidRuntime(19227): at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime(19227): at android.os.Looper.loop(Looper.java:148)
E/AndroidRuntime(19227): at android.app.ActivityThread.main(ActivityThread.java:7406)
E/AndroidRuntime(19227): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(19227): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
E/AndroidRuntime(19227): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
E/AndroidRuntime(19227): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.os.Looper android.app.Activity.getMainLooper()' on a null object reference
E/AndroidRuntime(19227): at com.google.android.gms.common.api.GoogleApi.<init>(Unknown Source)
E/AndroidRuntime(19227): at com.google.android.gms.location.FusedLocationProviderClient.<init>(Unknown Source)
E/AndroidRuntime(19227): at com.google.android.gms.location.LocationServices.getFusedLocationProviderClient(Unknown Source)
E/AndroidRuntime(19227): at com.lyokone.location.LocationPlugin.<init>(LocationPlugin.java:76)
E/AndroidRuntime(19227): at com.lyokone.location.LocationPlugin.registerWith(LocationPlugin.java:211)
E/AndroidRuntime(19227): at io.flutter.plugins.GeneratedPluginRegistrant.registerWith(GeneratedPluginRegistrant.java:19)
E/AndroidRuntime(19227): at com.example.geofencing_test.Application.registerWith(Application.java:19)
E/AndroidRuntime(19227): at io.flutter.plugins.geofencing.GeofencingService.startGeofencingService(GeofencingService.kt:75)
E/AndroidRuntime(19227): at io.flutter.plugins.geofencing.GeofencingService.onCreate(GeofencingService.kt:115)
E/AndroidRuntime(19227): at android.app.ActivityThread.handleCreateService(ActivityThread.java:3873)
E/AndroidRuntime(19227): ... 8 more
I/Process (19227): Sending signal. PID: 19227 SIG: 9
AndroidManifest.xml
<?xml version="1.0" encoding="UTF-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.geofencing_test">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application android:name=".Application" android:label="geofencing_test" android:icon="@mipmap/ic_launcher">
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
<meta-data android:name="com.google.android.geo.API_KEY" android:value="XXXX"/>
<activity android:name=".MainActivity" android:launchMode="singleTop" android:theme="@style/LaunchTheme" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" android:hardwareAccelerated="true" android:windowSoftInputMode="adjustResize">
<!-- This keeps the window background of the activity showing
until Flutter renders its first frame. It can be removed if
there is no splash screen (such as the default splash screen
defined in @style/LaunchTheme). -->
<meta-data android:name="io.flutter.app.android.SplashScreenUntilFirstFrame" android:value="true" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="io.flutter.plugins.geofencing.GeofencingBroadcastReceiver" android:enabled="true" android:exported="true"/>
<receiver android:name="io.flutter.plugins.geofencing.GeofencingRebootBroadcastReceiver" android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"></action>
</intent-filter>
</receiver>
<service android:name="io.flutter.plugins.geofencing.GeofencingService" android:permission="android.permission.BIND_JOB_SERVICE" android:exported="true"/>
</application>
</manifest>
android/build.gradle
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.configurations.all {
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'com.android.support'
&& !details.requested.name.contains('multidex') ) {
details.useVersion "27.1.1"
}
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
app/build.gradle
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 27
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.geofencing_test"
minSdkVersion 16
targetSdkVersion 27
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}
flutter {
source '../..'
}
dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:support-v4:27.1.1'
}
Thanks for the help
Hey @bkonyi . I would like to request you for a feature for registering multiple geofences at once. I see no API for adding currently. One more issue is that the Plugin works but the response is a bit slow. It is taking time to trigger events. I wanted to know whether its a normal case or a issue in plugin?
I see no API for registering multiple geofence regions. How can i able to achieve it. Should i use a for loop and to Iterate over the List and use the same callback for all?
In the crash section of google play console this error occurs a lot in our Android app:
java.lang.RuntimeException:
at android.app.ActivityThread.handleCreateService (ActivityThread.java:3793)
at android.app.ActivityThread.access$1400 (ActivityThread.java:241)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1823)
at android.os.Handler.dispatchMessage (Handler.java:106)
at android.os.Looper.loop (Looper.java:214)
at android.app.ActivityThread.main (ActivityThread.java:7156)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:494)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:975)
Caused by: java.lang.IllegalStateException:
at io.flutter.plugins.geofencing.GeofencingService.startGeofencingService (GeofencingService.kt:65)
at io.flutter.plugins.geofencing.GeofencingService.onCreate (GeofencingService.kt:114)
at android.app.ActivityThread.handleCreateService (ActivityThread.java:3781)
To match the line numbers we have deployed this version in our app: https://github.com/tashiwangdi/FlutterGeofencing/blob/master/android/src/main/kotlin/io/flutter/plugins/geofencing/GeofencingService.kt
A similar issue is tracked here: flutter/flutter#59262
I don't know if there is anything specific to the Geofencing plugin that could cause this?
In my app some Geofence should be removed after some conditions, so I want to remove some of them (in some particular cases) after they were triggered. I was testing on Android and it is working fine but on iOS I'm not being able to do it.
When the geofence event is triggered I'm not being able to initialise/register/remove the geofence plugin inside the callback on iOS. Apparently the plugin is not being initialised from within the isolate: MissingPluginException (MissingPluginException(No implementation found for method GeofencingPlugin.initializeService on channel plugins.flutter.io/geofencing_plugin)).
Any thoughts on how to solve this?
Thanks;
I tried running the example project and it fails with 10 warnings and 1 error.
Error:
error: no visible @interface for 'FlutterHeadlessDartRunner' declares the selector 'runWithEntrypointAndLibraryUri:libraryUri:' [_headlessRunner runWithEntrypointAndLibraryUri:entrypoint libraryUri:uri];
I had the error of the kotlin version even I have the kotlin version 1.2.71.
Error running Gradle: ProcessException: Process "/home/serpentcs/flutter_projects/geofence_example/android/gradlew" exited abnormally: FAILURE: Build failed with an exception. * What went wrong: The Android Gradle plugin supports only Kotlin Gradle plugin version 1.2.51 and higher. Project 'geofencing' is using version 1.2.30. * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. * Get more help at https://help.gradle.org. BUILD FAILED in 0s Command: /home/serpentcs/flutter_projects/geofence_example/android/gradlew app:properties Finished with error: Please review your Gradle project setup in the android/ folder.
I had used your project as plugin in pubspec.yaml file, So can you please suggest me how I can use it as a plugin of flutter in another project?
I noticed that in a recent commit updating to Flutter Android Embedding v2 the method "registerWith" was removed. This was a breaking change for my application since I register each plugin individually. How does the plugin registration process change with the new commit?
I'm trying to import this plugin inside a mine plugin.
All "works" but i can't register GeofencingService.setPluginRegistrant(this);
as needed.
how can i set the pluginregistrant in the service from dart?
Hi, I've hooked this library up to my Flutter iOS application, but trying to run the app on my iPhone is crashing with this message:
Launching lib/main.dart on iPhone 8 in debug mode...
Running Xcode build...
Xcode build done. 25.9s
*** First throw call stack:
(
0 CoreFoundation 0x00007fff23e3cf0e __exceptionPreprocess + 350
1 libobjc.A.dylib 0x00007fff50ba89b2 objc_exception_throw + 48
2 CoreFoundation 0x00007fff23e3cc88 +[NSException raise:format:arguments:] + 88
3 Foundation 0x00007fff258b8bd2 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 191
4 CoreLocation 0x00007fff24a1c99b CLClientStopVehicleHeadingUpdates + 27143
5 geofencing 0x000000010598efb7 -[GeofencingPlugin init:] + 631
6 geofencing 0x000000010598d8d8 +[GeofencingPlugin registerWithRegistrar:] + 120
7 Runner 0x00000001036afaa8<…>
Is the FlutterGeofencing library still supported with the latest Flutter versions? Or is the message above tied to common mistakes in implementing this library? The above pops up when trying to run on an iPhone emulator. When trying to run on a physical iPhone, the above message does not pop up, rather, the app launches and crashes immediately with no message or exception.
Things run fine when I run the app with FlutterGeofencing detached and not used, so I know it's the library that is causing the failures.
I have created new project in android embedding 2 with package example and I have facing this issue when tap on register btn
/AndroidRuntime( 8624): Process: com.example.ggofence, PID: 8624
E/AndroidRuntime( 8624): java.lang.RuntimeException: Unable to create service io.flutter.plugins.geofencing.GeofencingService: kotlin.UninitializedPropertyAccessException: lateinit property sPluginRegistrantCallback has not been initialized
E/AndroidRuntime( 8624): at android.app.ActivityThread.handleCreateService(ActivityThread.java:3965)
E/AndroidRuntime( 8624): at android.app.ActivityThread.access$1500(ActivityThread.java:219)
E/AndroidRuntime( 8624): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1875)
E/AndroidRuntime( 8624): at android.app.ActivityThread.access$1500(ActivityThread.java:219)
E/AndroidRuntime( 8624): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1875)
E/AndroidRuntime( 8624): at android.os.Handler.dispatchMessage(Handler.java:107)
E/AndroidRuntime( 8624): at android.os.Looper.loop(Looper.java:214)
E/AndroidRuntime( 8624): at android.app.ActivityThread.main(ActivityThread.java:7356)
E/AndroidRuntime( 8624): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 8624): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
E/AndroidRuntime( 8624): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
E/AndroidRuntime( 8624): Caused by: kotlin.UninitializedPropertyAccessException: lateinit property sPluginRegistrantCallback has not been initialized
E/AndroidRuntime( 8624): at io.flutter.plugins.geofencing.GeofencingService.startGeofencingService(GeofencingService.kt:74)
E/AndroidRuntime( 8624): at io.flutter.plugins.geofencing.GeofencingService.onCreate(GeofencingService.kt:114)
E/AndroidRuntime( 8624): at android.app.ActivityThread.handleCreateService(ActivityThread.java:3953)
E/AndroidRuntime( 8624): ... 8 more
I/Process ( 8624): Sending signal. PID: 8624 SIG: 9
on iOS, I try to understand the workflow when smartphone is restarting and a geofence event occurs.
Why do we need to call startGeofencingService in the didFinishLaunchingWithOptions method ?
This method is called as well in the dart main file when the Flutter app is starting:
await GeofencingManager.initialize();
I think, I do not understand what is happening after smartphone reboot and Flutter application state...
Can you please explain ?
We are getting bellow error on
// Callback method name is intentionally left blank.
mBackgroundChannel.invokeMethod("", geofenceUpdateList)
When geofence is triggered .
W/System.err(22473): java.lang.RuntimeException: Methods marked with @UiThread must be executed on the main thread. Current thread: AsyncTask #4
W/System.err(22473): at io.flutter.embedding.engine.FlutterJNI.ensureRunningOnMainThread(FlutterJNI.java:794)
W/System.err(22473): at io.flutter.embedding.engine.FlutterJNI.dispatchPlatformMessage(FlutterJNI.java:684)
W/System.err(22473): at io.flutter.embedding.engine.dart.DartMessenger.send(DartMessenger.java:80)
W/System.err(22473): at io.flutter.embedding.engine.dart.DartExecutor.send(DartExecutor.java:189)
W/System.err(22473): at io.flutter.view.FlutterNativeView.send(FlutterNativeView.java:155)
W/System.err(22473): at io.flutter.plugin.common.MethodChannel.invokeMethod(MethodChannel.java:98)
W/System.err(22473): at io.flutter.plugin.common.MethodChannel.invokeMethod(MethodChannel.java:84)
W/System.err(22473): at io.flutter.plugins.geofencing.GeofencingService.onHandleWork(GeofencingService.kt:152)
W/System.err(22473): at android.support.v4.app.JobIntentService$CommandProcessor.doInBackground(JobIntentService.java:391)
W/System.err(22473): at android.support.v4.app.JobIntentService$CommandProcessor.doInBackground(JobIntentService.java:382)
W/System.err(22473): at android.os.AsyncTask$2.call(AsyncTask.java:305)
W/System.err(22473): at java.util.concurrent.FutureTask.run(FutureTask.java:237)
W/System.err(22473): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
W/System.err(22473): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
W/System.err(22473): at java.lang.Thread.run(Thread.java:761)
how do I add this to my project like this example flutter_geofencing: ^0.1.2
When I added this plugin to my app, the only event that appears is GeofenceEvent.exit. I ran the example app and GeofenceEvent.enter fired. I'm not sure what part of the setup I am missing. Any help will be much appreciated!
Running the example code in IOS result in a crash on startup with the following error message:
flutter: Initializing..
*** Assertion failure in -[GeofencingPlugin startGeofencingService:], /Users/xxx/flutter/.pub-cache/hosted/pub.dartlang.org/geofencing-0.0.1/ios/Classes/GeofencingPlugin.m:164
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'failed to set registerPlugins'
using pubspec.yaml entry:
geofencing: ^0.0.1
I would be very pleased about some help or a idea for a possible solution
I have copied all the code from example into a new flutter project, main file is exactly the same as example project. Added information in info.plist file but Calling GeofencingManager.initialize() is crashing application with this error but download repo example project is working fine.
*** First throw call stack:
(
0 CoreFoundation 0x00007fff23b98bde __exceptionPreprocess + 350
1 libobjc.A.dylib 0x00007fff503b5b20 objc_exception_throw + 48
2 CoreFoundation 0x00007fff23b98958 +[NSException raise:format:arguments:] + 88
3 Foundation 0x00007fff255eb6f5 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 191
4 Runner 0x0000000104a2fdbf -[GeofencingPlugin startGeofencingService:] + 799
5 Runner 0x0000000104a2e59b -[GeofencingPlugin handleMethodCall:result:] + 635
6 Flutter 0x0000000104b7592e __45-[FlutterMethodChannel setMethodCallHandler:]_block_invoke + 104
7 Flutter 0x0000000104b0c9a4 _ZNK7flutter21PlatformMessage<…>
Flutter Doctor
[✓] Flutter (Channel beta, v1.10.7, on Mac OS X 10.14.6 18G103, locale en-US)
• Flutter version 1.10.7 at /Users/wahib/flutter
• Framework revision e70236e36c (6 weeks ago), 2019-10-02 09:32:30 -0700
• Engine revision 9e6314d348
• Dart version 2.6.0 (build 2.6.0-dev.0.0 1103600280)
[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
• Android SDK at /Users/wahib/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-29, build-tools 28.0.3
• ANDROID_HOME = /Users/wahib/Library/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 11.0)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 11.0, Build version 11A420a
• CocoaPods version 1.8.4
[✓] Android Studio (version 3.5)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 38.2.3
• Dart plugin version 191.8423
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
[✓] VS Code (version 1.40.0)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.6.0
[✓] Connected device (1 available)
• iPhone 11 Pro • 52B6B926-AF1D-47E0-8A37-7A8927BC0BA0 • ios • com.apple.CoreSimulator.SimRuntime.iOS-13-0 (simulator)
• No issues found!
Thanks!
Following the steps in REAMDE
and including the plugin from git, I'm unable to compile the sources in a clean project.
It only compiles if I replace
override fun registerWith(registry: PluginRegistry) {
GeneratedPluginRegistrant.registerWith(registry);
}
with
override fun registerWith(registry: PluginRegistry) {
registry.registrarFor("io.flutter.plugins.geofencing.GeofencingPlugin")
}
in Application.kt
Log:
Application.kt: (17, 48): Type mismatch: inferred type is PluginRegistry but FlutterEngine was expected
i´ve import the plugin in my project, but when i try compile my project throws me this:
*********************************************************
WARNING: This version of firebase_core will break your Android build if it or its dependencies aren't compatible with AndroidX.
See https://goo.gl/CP92wY for more information on the problem and how to fix it.
This warning prints for all Android build failures. The real root cause of the error may be unrelated.
*********************************************************
FAILURE: Build failed with an exception.
How can i update the kotlin version in the plugin?
In file GeofencingPlugin.m, showing Error: unknown type name 'FlutterPluginRegistrantCallback'
static FlutterPluginRegistrantCallback registerPlugins = nil;
What can be done to solve this issue.
I have installed example app in iOS device and when i click on Register button. It does not work. It always shows Current stat: N/A.
Is there any settings i need to do?
In Android device it works as expected.
@bkonyi : Thank you for adding the fix for crash on hot restart. The fix for the issue - #24 fixes the crash. However, there is this MissingPluginException on hot restart that we have been struggling to get rid of.
We tried the same approach to avoid the crash in our swift version but this MissingPluginException
won't budge. Here is the stacktrace:
Performing hot restart...
Syncing files to device tashi’s iPhone...
flutter: Initializing...
Restarted application in 1,476ms.
flutter: Initializing...
flutter: Initialization done
[VERBOSE-2:ui_dart_state.cc(148)] Unhandled Exception: MissingPluginException(No implementation found for method GeofencingPlugin.initializeService on channel plugins.flutter.io/geofencing_plugin)
#0 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:314:7)
<asynchronous suspension>
#1 GeofencingManager.initialize (package:geofencing/src/geofencing.dart:108:20)
<asynchronous suspension>
#2 _MyAppState.initPlatformState (package:geofencing_example/main.dart:62:29)
<asynchronous suspension>
#3 _MyAppState.initState (package:geofencing_example/main.dart:49:5)
#4 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4068:58)
#5 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3919:5)
#6 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3101:14)
#7 Element.updateChild (package:flutter/src/widgets/framework.dart:2904:12)
#8 RenderObjectToWidgetElement._rebuild (package:flutter/src/widgets/binding.dart:998:16)
#9 RenderObjectToWidgetElement.mount (package:flutter/src/widgets/binding.dart:969:5)
#10 RenderObjectToWidgetAdapter.attachToRenderTree.<anonymous closure> (package:flutter/src/widgets/binding.dart:915:17)
#11 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2328:19)
#12 RenderObjectToWidgetAdapter.attachToRenderTree (package:flutter/src/widgets/binding.dart:914:13)
#13 WidgetsBinding.attachRootWidget (package:flutter/src/widgets/binding.dart:795:7)
#14 runApp (package:flutter/src/widgets/binding.dart:845:7)
#15 main (package:geofencing_example/main.dart:12:16)
#16 _runMainZoned.<anonymous closure>.<anonymous closure> (dart:ui/hooks.dart:229:25)
#17 _rootRun (dart:async/zone.dart:1124:13)
#18 _CustomZone.run (dart:async/zone.dart:1021:19)
#19 _runZoned (dart:async/zone.dart:1516:10)
#20 runZoned (dart:async/zone.dart:1500:12)
#21 _runMainZoned.<anonymous closure> (dart:ui/hooks.dart:221:5)
#22 _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:305:19)
#23 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:172:12)
@bkonyi Firstly, thank you for kindly offering this plugin code and writing the blog post. Awesome work!
Today I decided to try and integrate this plugin as an experiment to the app I'm building as part of a hack day at work. Everything went great but I did bump into a few issues that I had to work around and I wanted to report these troubles with hopes we can find the best way around them. The problem has to do with how the geofencing plugin is registered via the custom Application class..
When the service starts and uses this method to register, and as a side effect, the GeneratedPluginRegistrant runs through all the other plugins the host application may have installed and registers them as well. In my case I had several that expected to receive an Activity in the registrar. But when registering in this background context, there was no Activity delivered and my app crashed. As a temporary work around I decided not to use the GeneratedPluginRegistrant and instead jut copied lines out of that class and stuck them right in my Application.kt. This ended up being safe and effective since this code path is specifically for the geofencing plugin to work. Here's a snippet:
class Application : FlutterApplication(), PluginRegistry.PluginRegistrantCallback {
override fun onCreate() {
super.onCreate();
GeofencingService.setPluginRegistrant(this);
}
override fun registerWith(registry: PluginRegistry) {
if (alreadyRegisteredWith(registry)) {
return
}
GeofencingPlugin.registerWith(registry.registrarFor("io.flutter.plugins.geofencing.GeofencingPlugin"))
FlutterLocalNotificationsPlugin.registerWith(registry.registrarFor("com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin"))
}
private fun alreadyRegisteredWith(registry: PluginRegistry): Boolean {
val key = GeneratedPluginRegistrant::class.java.canonicalName
if (registry.hasPlugin(key)) {
return true
}
registry.registrarFor(key)
return false
}
}
Notice here that I also included the Flutter Local Notifications plugin. My implementation needed to show a local notification when the user interacts with the geofence. The app crashed on my first attempt to call the notification plugin from the background isolate and then it occurred to me that from that isolate context, the local notifications plugin was never registered, so it needed to tag along with the geofencing plugin. I'm basically duplicating what the GeneratedPluginRegistrant does but only including the plugins I need and which I know will work without an Activity context.
This is obviously pretty messy and fragile and I'm feeling like this is maybe an are that needs a little more thought towards an official solution. Perhaps a way to have a GeneratedBackgroundPluginRegistrant class generated for plugins that can support execution in the background without an Activity context? Just a thought.
Basically there's two challenges:
In my solution I'm just manually registering the necessary plugins, but I can see how this might not be very friendly to work with. Just wanted to send you some of my notes with hopes that perhaps you have some ideas to improve this situation.
Thanks!
Dustin
I'm getting the following Gradle build error after I've updated to AndroidX:
The Android Gradle plugin supports only Kotlin Gradle plugin version 1.3.10 and higher.
The following dependencies do not satisfy the required version:
root project 'android' -> org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.30
I can't find a combination of settings that will allow this to build.
Relevant files here:
android/build.gradle
buildscript {
ext.kotlin_version = '1.3.10'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
google()
jcenter()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
gradle/wrapper/gradle-wrapper.properties
#Fri Jun 23 08:50:38 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
app/src/main/AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.fermovian.nas_activity">
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application
android:name=".Application"
android:label="nas_activity"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- This keeps the window background of the activity showing
until Flutter renders its first frame. It can be removed if
there is no splash screen (such as the default splash screen
defined in @style/LaunchTheme). -->
<meta-data
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
android:value="true" />
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<receiver android:name="io.flutter.plugins.geofencing.GeofencingBroadcastReceiver"
android:enabled="true" android:exported="true"/>
<receiver android:name="io.flutter.plugins.geofencing.GeofencingRebootBroadcastReceiver"
android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"></action>
</intent-filter>
</receiver>
<service android:name="io.flutter.plugins.geofencing.GeofencingService"
android:permission="android.permission.BIND_JOB_SERVICE" android:exported="true"/>
</application>
</manifest>
app/src/main/java/.../Application.java
import io.flutter.app.FlutterApplication;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugins.GeneratedPluginRegistrant;
import io.flutter.plugins.geofencing.GeofencingService;
public class Application extends FlutterApplication implements PluginRegistry.PluginRegistrantCallback {
@Override
public void onCreate() {
super.onCreate();
GeofencingService.setPluginRegistrant(this);
}
@Override
public void registerWith(PluginRegistry registry) {
GeneratedPluginRegistrant.registerWith(registry);
}
}
Upon initialization of geofences, the callback is always called for every geofence initially with the event GeofenceEvent.exit, even though the user did not exit or enter the geofence.
I am running my app on an Android emulator device (API 27) and I am getting a exception when invoking await GeofencingManager.initialize();
MissingPluginException(No implementation found for method GeofencingPlugin.initializeService on channel plugins.flutter.io/geofencing_plugin)
MethodChannel.invokeMethod (platform_channel.dart:291)
GeofencingManager.initialize (geofencing.dart:105)
Am I missing anything? Why I don't I see any usages of the callbackDispatcher() method in the callback_dispatcher.dart file?
I believe I have set up everything on the Android project correctly:
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hammer">
<!-- The INTERNET permission is required for development. Specifically,
flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application
android:name=".HammerApplication"
android:label="hammer"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- This keeps the window background of the activity showing
until Flutter renders its first frame. It can be removed if
there is no splash screen (such as the default splash screen
defined in @style/LaunchTheme). -->
<meta-data
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
android:value="true" />
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<!-- FOR GEOFENCNING START -->
<receiver android:name="io.flutter.plugins.geofencing.GeofencingBroadcastReceiver"
android:enabled="true" android:exported="true"/>
<service android:name="io.flutter.plugins.geofencing.GeofencingService"
android:permission="android.permission.BIND_JOB_SERVICE" android:exported="true"/>
<!-- FOR GEOFENCNING END -->
</application>
</manifest>
HammerApplication.java
package com.hammer;
import android.content.Context;
import android.support.multidex.*;
import io.flutter.app.FlutterApplication;
import io.flutter.plugins.GeneratedPluginRegistrant;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback;
import io.flutter.plugins.geofencing.GeofencingService;
public class HammerApplication extends FlutterApplication implements PluginRegistrantCallback {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
@Override
public void onCreate() {
super.onCreate();
GeofencingService.setPluginRegistrant(this);
}
@Override
public void registerWith(PluginRegistry registry) {
GeneratedPluginRegistrant.registerWith(registry);
}
}
MainActivity.java
package com.hammer;
import android.os.Bundle;
import io.flutter.app.FlutterActivity;
import io.flutter.plugins.GeneratedPluginRegistrant;
public class MainActivity extends FlutterActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
}
}
Really appreciate the help! Thanks!
I have built android example using this geofence plugin . I am using example given here and either i am in radius or not, I always get Event: GeofenceEvent.exit . And even i tried using fake location and tried changing my location but Event never get trigger.Please let me know the issue cause.
I've tried scheduling jobs using android_alarm_manager to keep the geofence manager initialized but it doesn't quite work correctly, is there a reliable way to keep the geofence manager running after app termination?
Hi,
I have a strange issue while using this library. Setting a Geofence will never start a GeofenceEvent.entry but EXIT works fine.
This happens on Emulator and real device both running Android 9.
Any idea where I can take a look on why it is not calling entry?
Androidmanifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.ews">
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<!--android:name="io.flutter.app.FlutterApplication"-->
<application
android:name=".Application"
android:label="ews"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<receiver android:name="io.flutter.plugins.geofencing.GeofencingBroadcastReceiver"
android:enabled="true" android:exported="true"/>
<receiver android:name="io.flutter.plugins.geofencing.GeofencingRebootBroadcastReceiver"
android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"></action>
</intent-filter>
</receiver>
<service android:name="io.flutter.plugins.geofencing.GeofencingService"
android:permission="android.permission.BIND_JOB_SERVICE" android:exported="true"/>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
</manifest>
Hi Sir! How to modify the code to be able to execute or maybe print logs every X seconds or minutes? I need your help on this. Thank you so much!
Might be a dumb question, but I'm curious why mContext needs to be saved as a class variable in GeoFencingService
? Since JobIntentService
has its own context, why do you use mContext.startForegroundService
in the onMethodCall
function instead of this.startForegroundService
?
D/EGL_emulation(12145): eglMakeCurrent: 0xe6be2280: ver 2 0 (tinfo 0xe7db52a0) D/eglCodecCommon(12145): setVertexArrayObject: set vao to 0 (0) 1 0 I/flutter (12145): Initializing... D/GeofencingPlugin(12145): Initializing GeofencingService I/flutter (12145): Initialization done E/GeofencingPlugin(12145): Failed to add geofence: com.google.android.gms.common.api.ApiException: 1000:
Unhandled Exception: PlatformException(com.google.android.gms.common.api.ApiException: 1000: , null, null)
E/flutter (11788): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:569:7)
E/flutter (11788): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:156:18)
E/flutter (11788):
I was added all in android manifest file receiver and permission too, added plugin in pubspec call the code but this error occured the getRegisteredGeofenceIds isnt defined for GeofencingManager class
The details about this issue is shared in the issue from the flutter repo here: flutter/flutter#43621
Basically the example app (and other apps using the plugin) crashes on hot restart.
We reimplemented the plugin in Swift (https://github.com/JFreakDK/FlutterGeofencing/) but the same issue occurs in this ObjectiveC version.
What is the minimum requirement for the plugin for the Android version?
I have simply cloned the repo, built and started the example app.
I have got the following error, once I tapped on Register button:
E/GeofencingPlugin(17185): Failed to add geofence: com.google.android.gms.common.api.ApiException: 1000:
E/flutter (17185): [ERROR:flutter/shell/common/shell.cc(184)] Dart Error: Unhandled exception:
E/flutter (17185): PlatformException(com.google.android.gms.common.api.ApiException: 1000: , null, null)
E/flutter (17185): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:551:7)
E/flutter (17185): #1 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:292:18)
E/flutter (17185):
E/flutter (17185): #2 GeofencingManager.registerGeofence (package:geofencing/src/geofencing.dart:149:20)
E/flutter (17185):
E/flutter (17185): #3 _MyAppState.build. (package:geofencing_example/main.dart:103:45)
E/flutter (17185): #4 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:507:14)
E/flutter (17185): #5 _InkResponseState.build. (package:flutter/src/material/ink_well.dart:562:30)
E/flutter (17185): #6 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:102:24)
E/flutter (17185): #7 TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:242:9)
E/flutter (17185): #8 TapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:175:7)
E/flutter (17185): #9 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:315:9)
E/flutter (17185): #10 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:73:12)
E/flutter (17185): #11 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:101:11)
E/flutter (17185): #12 _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:180:19)
E/flutter (17185): #13 _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:158:22)
E/flutter (17185): #14 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:138:7)
E/flutter (17185): #15 _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:101:7)
E/flutter (17185): #16 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:85:7)
E/flutter (17185): #17 _invoke1 (dart:ui/hooks.dart:168:13)
E/flutter (17185): #18 _dispatchPointerDataPacket (dart:ui/hooks.dart:122:5)
flutter --version
Flutter 1.0.0 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 5391447fae (9 weeks ago) • 2018-11-29 19:41:26 -0800
Engine • revision 7375a0f414
Tools • Dart 2.1.0 (build 2.1.0-dev.9.4 f9ebf21297)
The package fails to detect GeofenceEvent.dwell
state automatically. To manually trigger it I need to first open Google Maps app and then switching back to the Geofencing app it detects the dwell state.
And similarly, if I exit the geofence I need to manually switch to the Google Maps app and then back to trigger the exit
state change.
Flutter debug console doesn't have any useful information.
I've this error on xCode and i'm going crazy trying to access other plugins from callback.
I added this plugin into my project and when I click the Register button to add a GeoFence it throws this exception.
I am running this on Emulator Pixel 2 API 27. But I get the same error on a real device with Noguet 7.1.
Location is Mode is on High Accuracy
and wifi and mobile data are enabled.
This is my AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="in.milton.smartthings">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="18" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-feature android:name="android.hardware.wifi" />
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application android:name=".Application" android:label="Milton" android:icon="@mipmap/ic_launcher">
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
<meta-data android:name="com.google.android.geo.API_KEY" android:value="API_KEY" />
<activity android:name=".MainActivity" android:launchMode="singleTop" android:theme="@style/LaunchTheme" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" android:hardwareAccelerated="true" android:windowSoftInputMode="adjustResize">
<!-- This keeps the window background of the activity showing
until Flutter renders its first frame. It can be removed if
there is no splash screen (such as the default splash screen
defined in @style/LaunchTheme). -->
<meta-data android:name="io.flutter.app.android.SplashScreenUntilFirstFrame" android:value="true" />
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
<action android:name="FLUTTER_NOTIFICATION_CLICK" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<receiver android:name="io.flutter.plugins.geofencing.GeofencingBroadcastReceiver" android:enabled="true" android:exported="true"/>
<receiver android:name="io.flutter.plugins.geofencing.GeofencingRebootBroadcastReceiver" android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"></action>
</intent-filter>
</receiver>
<service android:name="io.flutter.plugins.geofencing.GeofencingService" android:permission="android.permission.BIND_JOB_SERVICE" android:exported="true"/>
</application>
</manifest>
this is Application.java
package in.milton.smartthings;
import io.flutter.app.FlutterApplication;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback;
import io.flutter.plugins.GeneratedPluginRegistrant;
import io.flutter.plugins.geofencing.GeofencingService;
public class Application extends FlutterApplication implements PluginRegistrantCallback {
@Override
public void onCreate() {
super.onCreate();
GeofencingService.setPluginRegistrant(this);
}
@Override
public void registerWith(PluginRegistry registry) {
GeneratedPluginRegistrant.registerWith(registry);
}
}
I/GeofencingPlugin( 6681): Successfully added geofence
I/GeofencingService( 6681): Starting GeofencingService...
D/AndroidRuntime( 6681): Shutting down VM
E/AndroidRuntime( 6681): FATAL EXCEPTION: main
E/AndroidRuntime( 6681): Process: in.milton.smartthings, PID: 6681
E/AndroidRuntime( 6681): java.lang.RuntimeException: Unable to create service io.flutter.plugins.geofencing.GeofencingService: java.lang.IllegalStateException: registrar.activity() must not be null
E/AndroidRuntime( 6681): at android.app.ActivityThread.handleCreateService(ActivityThread.java:3349)
E/AndroidRuntime( 6681): at android.app.ActivityThread.-wrap4(Unknown Source:0)
E/AndroidRuntime( 6681): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1677)
E/AndroidRuntime( 6681): at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime( 6681): at android.os.Looper.loop(Looper.java:164)
E/AndroidRuntime( 6681): at android.app.ActivityThread.main(ActivityThread.java:6494)
E/AndroidRuntime( 6681): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 6681): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
E/AndroidRuntime( 6681): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
E/AndroidRuntime( 6681): Caused by: java.lang.IllegalStateException: registrar.activity() must not be null
E/AndroidRuntime( 6681): at com.apptreesoftware.barcodescan.BarcodeScanPlugin$Companion.registerWith(BarcodeScanPlugin.kt:19)
E/AndroidRuntime( 6681): at com.apptreesoftware.barcodescan.BarcodeScanPlugin.registerWith(Unknown Source:2)
E/AndroidRuntime( 6681): at io.flutter.plugins.GeneratedPluginRegistrant.registerWith(GeneratedPluginRegistrant.java:33)
E/AndroidRuntime( 6681): at in.milton.smartthings.Application.registerWith(Application.java:18)
E/AndroidRuntime( 6681): at io.flutter.plugins.geofencing.GeofencingService.startGeofencingService(GeofencingService.kt:73)
E/AndroidRuntime( 6681): at io.flutter.plugins.geofencing.GeofencingService.onCreate(GeofencingService.kt:113)
E/AndroidRuntime( 6681): at android.app.ActivityThread.handleCreateService(ActivityThread.java:3339)
Any help is appreciated.
I tried to execute example app to copy main.dart in the example app to myapp I created by flutter create
. However, it crashes with following errors. It seems that there is some problem about plugins.
I also tried to replace ios
directory in the "example app" with myapp's, and it works well.
Here, I used the example app in the library I fetched (like /.symlinks/plugins/geofencing/example) bacause if I use the example app I cloned from github, I got an another error which is /build/ios/Debug-iphonesimulator/Runner.app/Frameworks/Flutter.framework: Permission denied
.
Xcode error output is this.
2019-11-04 17:45:53.974677+0900 Runner[98628:6930647] flutter: Observatory listening on http://127.0.0.1:61147/si91USLHVws=/
2019-11-04 17:45:54.539093+0900 Runner[98628:6930637] flutter: Initializing...
2019-11-04 17:45:55.203242+0900 Runner[98628:6930328] *** Assertion failure in -[GeofencingPlugin startGeofencingService:], /Users/yanyo/development/flutter/.pub-cache/hosted/pub.dartlang.org/geofencing-0.0.1/ios/Classes/GeofencingPlugin.m:168
2019-11-04 17:45:55.231958+0900 Runner[98628:6930328] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'failed to set registerPlugins'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff23c4f02e __exceptionPreprocess + 350
1 libobjc.A.dylib 0x00007fff50b97b20 objc_exception_throw + 48
2 CoreFoundation 0x00007fff23c4eda8 +[NSException raise:format:arguments:] + 88
3 Foundation 0x00007fff256c9b61 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 191
4 geofencing 0x0000000106a5187f -[GeofencingPlugin startGeofencingService:] + 799
5 geofencing 0x0000000106a5001c -[GeofencingPlugin handleMethodCall:result:] + 652
6 Flutter 0x0000000104a6d4fd __45-[FlutterMethodChannel setMethodCallHandler:]_block_invoke + 104
7 Flutter 0x0000000104a06ec0 _ZNK7flutter21PlatformMessageRouter21HandlePlatformMessageEN3fml6RefPtrINS_15PlatformMessageEEE + 166
8 Flutter 0x0000000104a0a780 _ZN7flutter15PlatformViewIOS21HandlePlatformMessageEN3fml6RefPtrINS_15PlatformMessageEEE + 38
9 Flutter 0x0000000104a67db3 _ZNSt3__110__function6__funcIZN7flutter5Shell29OnEngineHandlePlatformMessageEN3fml6RefPtrINS2_15PlatformMessageEEEE4$_31NS_9allocatorIS8_EEFvvEEclEv + 57
10 Flutter 0x0000000104a193f1 _ZN3fml15MessageLoopImpl10FlushTasksENS_9FlushTypeE + 123
11 Flutter 0x0000000104a1e742 _ZN3fml17MessageLoopDarwin11OnTimerFireEP16__CFRunLoopTimerPS0_ + 26
12 CoreFoundation 0x00007fff23bb2944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20
13 CoreFoundation 0x00007fff23bb2632 __CFRunLoopDoTimer + 1026
14 CoreFoundation 0x00007fff23bb1c8a __CFRunLoopDoTimers + 266
15 CoreFoundation 0x00007fff23bac9fe __CFRunLoopRun + 2238
16 CoreFoundation 0x00007fff23babe16 CFRunLoopRunSpecific + 438
17 GraphicsServices 0x00007fff38438bb0 GSEventRunModal + 65
18 UIKitCore 0x00007fff4784fb68 UIApplicationMain + 1621
19 Runner 0x00000001046c60f8 main + 72
20 libdyld.dylib 0x00007fff51a1dc25 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
Flutter doctor is this.
$ flutter doctor -v
[✓] Flutter (Channel stable, v1.9.1+hotfix.5, on Mac OS X 10.14.6 18G95, locale ja-JP)
• Flutter version 1.9.1+hotfix.5 at /Users/yanyo/development/flutter
• Framework revision 1aedbb1835 (3 weeks ago), 2019-10-17 08:37:27 -0700
• Engine revision b863200c37
• Dart version 2.5.0
[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
• Android SDK at /Users/yanyo/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-28, build-tools 28.0.3
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 11.2)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 11.2, Build version 11B52
• CocoaPods version 1.6.1
[!] Android Studio (version 3.5)
• Android Studio at /Applications/Android Studio.app/Contents
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
[✓] VS Code (version 1.39.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.6.0
[✓] Connected device (1 available)
• iPhone 11 Pro Max • 5D418355-E533-491B-8821-97DCA97BB049 • ios • com.apple.CoreSimulator.SimRuntime.iOS-13-2 (simulator)
! Doctor found issues in 1 category.
I have added the lines of code that were mentioned in the readme. I added these inside my Application.kt which I have already created for Firebase Messaging Service.
GeofencingService.setPluginRegistrant(this)
However, when I run this I get an unresolved error,
Unresolved reference: GeofencingService
As it says the package cannot be found, any help would be appreciated.
Cloned the repo and trying to run the example app.
Location permission and high accuracy is granted.
This is what happens when I try to run it on a physical device (Huawei Honor 6X with Android 7):
I/GeofencingPlugin( 5453): Successfully added geofence
E/AndroidRuntime( 5453): FATAL EXCEPTION: main
E/AndroidRuntime( 5453): Process: io.flutter.plugins.geofencingexample, PID: 5453
E/AndroidRuntime( 5453): java.lang.RuntimeException: Unable to start receiver io.flutter.plugins.geofencing.GeofencingBroadcastReceiver: java.lang.SecurityException: Neither user 10470 nor current process has android.permission.WAKE_LOCK.
E/AndroidRuntime( 5453): at android.app.ActivityThread.handleReceiver(ActivityThread.java:3184)
E/AndroidRuntime( 5453): at android.app.ActivityThread.-wrap18(ActivityThread.java)
E/AndroidRuntime( 5453): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1653)
E/AndroidRuntime( 5453): at android.os.Handler.dispatchMessage(Handler.java:105)
E/AndroidRuntime( 5453): at android.os.Looper.loop(Looper.java:156)
E/AndroidRuntime( 5453): at android.app.ActivityThread.main(ActivityThread.java:6517)
E/AndroidRuntime( 5453): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 5453): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:942)
E/AndroidRuntime( 5453): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832)
E/AndroidRuntime( 5453): Caused by: java.lang.SecurityException: Neither user 10470 nor current process has android.permission.WAKE_LOCK.
E/AndroidRuntime( 5453): at android.os.Parcel.readException(Parcel.java:1673)
E/AndroidRuntime( 5453): at android.os.Parcel.readException(Parcel.java:1626)
E/AndroidRuntime( 5453): at android.os.IPowerManager$Stub$Proxy.acquireWakeLock(IPowerManager.java:572)
E/AndroidRuntime( 5453): at android.os.PowerManager$WakeLock.acquireLocked(PowerManager.java:1399)
E/AndroidRuntime( 5453): at android.os.PowerManager$WakeLock.acquire(PowerManager.java:1383)
E/AndroidRuntime( 5453): at android.support.v4.app.JobIntentService$CompatWorkEnqueuer.enqueueWork(JobIntentService.java:191)
E/AndroidRuntime( 5453): at android.support.v4.app.JobIntentService.enqueueWork(JobIntentService.java:522)
E/AndroidRuntime( 5453): at android.support.v4.app.JobIntentService.enqueueWork(JobIntentService.java:500)
E/AndroidRuntime( 5453): at io.flutter.plugins.geofencing.GeofencingService$Companion.enqueueWork(GeofencingService.kt:48)
E/AndroidRuntime( 5453): at io.flutter.plugins.geofencing.GeofencingBroadcastReceiver.onReceive(GeofencingBroadcastReceiver.kt:20)
E/AndroidRuntime( 5453): at android.app.ActivityThread.handleReceiver(ActivityThread.java:3177)
E/AndroidRuntime( 5453): ... 8 more
When trying it on an emulator I get #8 (comment) instead, so the app can be run on neither for me.
I rebuilt the functionality of your alarm_manager_plugin changes from flutter/plugins#642 for my flutter_activity_recognition
plugin. You can find the current state here: https://github.com/Morosko/flutter_activity_recognition/tree/dev. It works, if the app is just in background, but when I kill it, no more updates will occur. In this plugin you have an extra Service, running beside the BroadcastReceiver. Will this make any difference?
I try to develop the same kind of background plugin for Bluetooth.
final SendPort send = IsolateNameServer.lookupPortByName('ble_send_port');
Is it normal that IsolateNameServer.lookupPortByName returns null after phone reboot ?
Any advice ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.