flutterlocation
flutterlocation copied to clipboard
fix:
Description
App crashes right after accepting location permissions. I have narrowed down the issue to a Google Play Services issue.
When running the Google Play Services beta (version 22.29.+) I get a NullPointerException.
I left the beta, uninstalled, and reinstalled and am now on version 22.26.+, and there no longer seems to be an issue.
Furthermore, I did not receive the error when setting useGooglePlayServices: false
.
I am using 5.0.0-dev.8
The issue is in this line: location.extras.getInt("satellites").toLong()
. It appears that location.extras
is null.
Tested on:
- Android, API Level 33, simulator and real device
- Pixel 6 Pro
- Pixel 2 XL
- Pixel 4 (emulator)
Additional logs
Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.os.Bundle.getInt(java.lang.String)' on a null object reference
at com.lyokone.location.LocationPlugin.onLocationChanged(LocationPlugin.kt:153)
at com.lyokone.location.location.providers.locationprovider.GooglePlayServicesLocationProvider.onLocationChanged(GooglePlayServicesLocationProvider.java:119)
at com.lyokone.location.location.providers.locationprovider.GooglePlayServicesLocationProvider.onLastKnowLocationTaskReceived(GooglePlayServicesLocationProvider.java:211)
at com.lyokone.location.location.providers.locationprovider.GooglePlayServicesLocationSource$3.onComplete(GooglePlayServicesLocationSource.java:92)
at com.google.android.gms.tasks.zzi.run(com.google.android.gms:play-services-tasks@@18.0.1:1)
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7898)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
Hi @Lyokone,
I'm facing the same exception after updating to the 5.0.0-dev.8 as suggested into a different issue.
You'll find below the exceptions I tried to fix with this new release.
Exception 1
Caused by java.lang.NullPointerException Attempt to invoke virtual method 'io.flutter.plugin.common.p com.lyokone.location.FlutterLocationService.h()' on a null object reference
Exception 2
Fatal Exception: java.lang.ClassCastException android.os.BinderProxy cannot be cast to com.lyokone.location.FlutterLocationService$b
So far they seem fixed.
Hello I have same issue on Pixel 4 (Android 13) location: 5.0.0-dev.8.
Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.os.Bundle.getInt(java.lang.String)' on a null object reference at z5.l.onLocationChanged(:150) at h6.e.onLocationChanged(:10) at h6.e.d(:23) at h6.f.b(:4) at l2.l.a(:4) at com.google.android.gms.common.api.internal.d.d(:8) at com.google.android.gms.common.api.internal.x.run(:4) at android.os.Handler.handleCallback(Handler.java:942) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loopOnce(Looper.java:201) at android.os.Looper.loop(Looper.java:288) at android.app.ActivityThread.main(ActivityThread.java:7898) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
Same Here Xiamoi Note 10 S
Same issue with Pixel 4a (Android 13) location: 5.0.0-dev.8
location: ^5.0.0-dev.8
geocoding: ^2.0.5
E/AndroidRuntime( 7090): at com.lyokone.location.LocationPlugin.onLocationChanged(LocationPlugin.kt:153)
E/AndroidRuntime( 7090): at com.lyokone.location.location.providers.locationprovider.GooglePlayServicesLocationProvider.onLocationChanged(GooglePlayServicesLocationProvider.java:119)
E/AndroidRuntime( 7090): at com.lyokone.location.location.providers.locationprovider.GooglePlayServicesLocationProvider.onLastKnowLocationTaskReceived(GooglePlayServicesLocationProvider.java:211)
E/AndroidRuntime( 7090): at com.lyokone.location.location.providers.locationprovider.GooglePlayServicesLocationSource$3.onComplete(GooglePlayServicesLocationSource.java:92)
E/AndroidRuntime( 7090): at com.google.android.gms.tasks.zzi.run(com.google.android.gms:play-services-tasks@@18.0.1:1)
E/AndroidRuntime( 7090): at android.os.Handler.handleCallback(Handler.java:938)
E/AndroidRuntime( 7090): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 7090): at android.os.Looper.loopOnce(Looper.java:201)
E/AndroidRuntime( 7090): at android.os.Looper.loop(Looper.java:288)
E/AndroidRuntime( 7090): at android.app.ActivityThread.main(ActivityThread.java:7839)
E/AndroidRuntime( 7090): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 7090): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
E/AndroidRuntime( 7090): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
I/Process ( 7090): Sending signal. PID: 7090 SIG: 9
Lost connection to device.
Got the same exception with 5.0.0-dev.8
:
E/AndroidRuntime(22364): Process: com.lyokone.location_example, PID: 22364
E/AndroidRuntime(22364): java.lang.NullPointerException: Attempt to invoke virtual method 'int android.os.Bundle.getInt(java.lang.String)' on a null object reference
E/AndroidRuntime(22364): at com.lyokone.location.LocationPlugin.onLocationChanged(LocationPlugin.kt:153)
E/AndroidRuntime(22364): at com.lyokone.location.location.providers.locationprovider.GooglePlayServicesLocationProvider.onLocationChanged(GooglePlayServicesLocationProvider.java:119)
E/AndroidRuntime(22364): at com.lyokone.location.location.providers.locationprovider.GooglePlayServicesLocationProvider.onLocationResult(GooglePlayServicesLocationProvider.java:141)
E/AndroidRuntime(22364): at com.lyokone.location.location.providers.locationprovider.GooglePlayServicesLocationSource.onLocationResult(GooglePlayServicesLocationSource.java:99)
E/AndroidRuntime(22364): at com.google.android.gms.internal.location.zzap.notifyListener(com.google.android.gms:play-services-location@@18.0.0:2)
E/AndroidRuntime(22364): at com.google.android.gms.common.api.internal.ListenerHolder.zaa(com.google.android.gms:play-services-base@@18.0.1:2)
E/AndroidRuntime(22364): at com.google.android.gms.common.api.internal.zacb.run(Unknown Source:4)
I disabled Google location services to test how it works with just GPS. Turns out, the library does not account for this case.
Sony Xperia 10 IV, Android 12.
Any solution to this
Any update on this?
Add
configurations.all {
resolutionStrategy {
force 'com.google.android.gms:play-services-location:21.0.1'
}
}
to your android/build.gradle like this:
allprojects {
repositories {
google()
mavenCentral()
configurations.all {
resolutionStrategy {
force 'com.google.android.gms:play-services-location:21.0.1'
}
}
}
}
This worked for me. I found the answer here
Should be fixed by #847.
Should be fixed in v5
versions.