react-native-geolocation
react-native-geolocation copied to clipboard
java.lang.IllegalStateException: Method addObserver must be called on the main thread
Environment
System:
OS: macOS 12.4
CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
Memory: 149.21 MB / 16.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 16.15.1 - ~/.nvm/versions/node/v16.15.1/bin/node
Yarn: Not Found
npm: 8.11.0 - ~/.nvm/versions/node/v16.15.1/bin/npm
Watchman: 2022.10.10.00 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.10.2 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 21.4, iOS 15.5, macOS 12.3, tvOS 15.4, watchOS 8.5
Android SDK:
API Levels: 27, 28, 29, 30, 31
Build Tools: 28.0.3, 29.0.2, 29.0.3, 30.0.2, 30.0.3, 31.0.0
System Images: android-24 | Google APIs Intel x86 Atom, android-24 | Google Play Intel x86 Atom, android-28 | Google APIs Intel x86 Atom, android-30 | Google APIs Intel x86 Atom, android-30 | Google Play Intel x86 Atom, android-32 | Google APIs ARM 64 v8a, android-32 | Google APIs Intel x86 Atom_64, android-33 | Google APIs Intel x86 Atom_64
Android NDK: Not Found
IDEs:
Android Studio: 2020.3 AI-203.7717.56.2031.7678000
Xcode: 13.4.1/13F100 - /usr/bin/xcodebuild
Languages:
Java: 11.0.2 - /Users/hugogresse/.jabba/jdk/[email protected]/Contents/Home/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: 17.0.2 => 17.0.2
react-native: 0.68.4 => 0.68.4
react-native-macos: Not Found
npmGlobalPackages:
*react-native*: Not Found
Platforms
Android only, in release, not debug
Versions
- Android: 12
- react-native-geolocation: 3.0.3
- react-native: 0.68.4
- react: 17
Description
When getting the current position, the app crash with the following report:
java.lang.IllegalStateException: Method addObserver must be called on the main thread
at androidx.lifecycle.LifecycleRegistry.enforceMainThreadIfNeeded(LifecycleRegistry.java:317)
at androidx.lifecycle.LifecycleRegistry.addObserver(LifecycleRegistry.java:172)
at androidx.fragment.app.Fragment.initLifecycle(Fragment.java:496)
at androidx.fragment.app.Fragment.<init>(Fragment.java:476)
at com.google.android.gms.common.api.internal.zzd.<init>(com.google.android.gms:play-services-basement@@18.0.0:1)
at com.google.android.gms.common.api.internal.zzd.zzc(com.google.android.gms:play-services-basement@@18.0.0:6)
at com.google.android.gms.common.api.internal.LifecycleCallback.getFragment(com.google.android.gms:play-services-basement@@18.0.0:4)
at com.google.android.gms.common.api.internal.LifecycleCallback.getFragment(com.google.android.gms:play-services-basement@@18.0.0:1)
at com.google.android.gms.tasks.zzv.zza(com.google.android.gms:play-services-tasks@@18.0.1:1)
at com.google.android.gms.tasks.zzw.addOnSuccessListener(com.google.android.gms:play-services-tasks@@18.0.1:3)
at com.reactnativecommunity.geolocation.PlayServicesLocationManager.getCurrentLocationData(PlayServicesLocationManager.java:50)
at com.reactnativecommunity.geolocation.GeolocationModule.lambda$getCurrentPosition$5$com-reactnativecommunity-geolocation-GeolocationModule(GeolocationModule.java:123)
at com.reactnativecommunity.geolocation.GeolocationModule$$ExternalSyntheticLambda6.invoke(Unknown Source:8)
at com.reactnativecommunity.geolocation.GeolocationModule.lambda$requestAuthorization$3(GeolocationModule.java:94)
at com.reactnativecommunity.geolocation.GeolocationModule$$ExternalSyntheticLambda4.invoke(Unknown Source:11)
at com.facebook.react.bridge.PromiseImpl.resolve(PromiseImpl.java:56)
at com.facebook.react.modules.permissions.PermissionsModule.checkPermission(PermissionsModule.java:63)
at com.reactnativecommunity.geolocation.GeolocationModule.requestAuthorization(GeolocationModule.java:98)
at com.reactnativecommunity.geolocation.GeolocationModule.getCurrentPosition(GeolocationModule.java:123)
at com.reactnativecommunity.geolocation.RNCGeolocationModule.getCurrentPosition(RNCGeolocationModule.java:41)
at java.lang.reflect.Method.invoke(Native Method)
at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:188)
at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
at android.os.Looper.loop(Looper.java:233)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:228)
at java.lang.Thread.run(Thread.java:923)
According to firebase, it happen on all android versions.
Reproducible Demo
This is a regression compared to version 2.0.2
Thank you for reporting. I'm preparing an update and will include the fix, but I don't have a specific time when it will be launched. You can roll back to 2.x if you need an immediate fix.
thanks for the quick update! I did rollback. Thanks for taking care of maintaining the library! You may want to add a Sponsor button on your GH profil too?