react-native-geolocation-service: App crashes or could not invoke Geolocation.getCurrentPosition
Environment
System: OS: macOS 12.2.1 CPU: (4) x64 Intel® Core™ i5-5350U CPU @ 1.80GHz Memory: 29.25 MB / 8.00 GB Shell: 5.8 - /bin/zsh Binaries: Node: 16.13.1 - /usr/local/bin/node Yarn: 1.22.19 - ~/****/node_modules/.bin/yarn npm: 8.1.2 - /usr/local/bin/npm Watchman: 2022.08.29.00 - /usr/local/bin/watchman Managers: CocoaPods: 1.11.3 - /usr/local/bin/pod SDKs: iOS SDK: Not Found Android SDK: Android NDK: 22.1.7171670 IDEs: Android Studio: 2022.1 AI-221.6008.13.2211.9477386 Xcode: /undefined - /usr/bin/xcodebuild Languages: Java: 11.0.16.1 - /usr/bin/javac npmPackages: @react-native-community/cli: Not Found react: 17.0.2 => 17.0.2 react-native: 0.67.0 => 0.67.0 react-native-macos: Not Found npmGlobalPackages: react-native: Not Found
Platforms
Android
Versions
Please add the used versions/branches
- Android : used implementation ‘com.google.android.gms:play-services-location:21.0.1’
- react-native-geolocation-service:“^5.3.1”
- react-native: “0.67.0”,
- react:“17.0.2”,
Description
Caused by: java.lang.IncompatibleClassChangeError: Found interface com.google.android.gms.location.FusedLocationProviderClient, but class was expected (declaration of ‘com.google.android.gms.location.FusedLocationProviderClient’ appears in /data/app/~~bD1cPSXr3jYigB864Ni0yw==/com.truecharger-IyI3jbMZVzNj2aO7gf6B4g==/base.apk!classes14.dex) at com.agontuk.RNFusedLocation.FusedLocationProvider.getCurrentLocation(FusedLocationProvider.java:97) at com.agontuk.RNFusedLocation.RNFusedLocationModule.getCurrentPosition(RNFusedLocationModule.java:112)
Exception in native call
java.lang.RuntimeException: Could not invoke RNFusedLocation.getCurrentPosition
at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:383)
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:246)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:226)
at java.lang.Thread.run(Thread.java:923)
Caused by: java.lang.reflect.InvocationTargetException
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:246)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:226)
at java.lang.Thread.run(Thread.java:923)
Caused by: java.lang.IncompatibleClassChangeError: Found interface com.google.android.gms.location.FusedLocationProviderClient, but class was expected (declaration of 'com.google.android.gms.location.FusedLocationProviderClient' appears in /data/app/~~bD1cPSXr3jYigB864Ni0yw==/com.truecharger-IyI3jbMZVzNj2aO7gf6B4g==/base.apk!classes14.dex)
at com.agontuk.RNFusedLocation.FusedLocationProvider.getCurrentLocation(FusedLocationProvider.java:97)
at com.agontuk.RNFusedLocation.RNFusedLocationModule.getCurrentPosition(RNFusedLocationModule.java:112)
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:246)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:226)
Reproducible Demo
- Add below in android/app/gradle to use latest version
implementation 'com.google.android.gms:play-services-location:21.0.1' implementation (project(path: ':react-native-geolocation-service')) { exclude group: 'com.google.android.gms', module: 'play-services-location' }
- When user allow for permission in android pop-up, either it crashes or give above error
Expected Results
getCurrentLocation should return values
Note:
similar to https://github.com/Agontuk/react-native-geolocation-service/issues/367
About this issue
- Original URL
- State: open
- Created a year ago
- Reactions: 5
- Comments: 15
Any solution?
@LinaEfer
You might want to try modifying the build.gradle file of react-native-geolocation-service directly.
Change this line:
to:
However, I haven’t actually tested this myself as I am not using react-native-device-info.
Possible solution: check my response to
react-native-maps
module which changed location module version and broke our app: https://github.com/react-native-maps/react-native-maps/pull/4858#issuecomment-1777470683BTW, documentation for the library literally says lock to version 17: https://github.com/Agontuk/react-native-geolocation-service/blob/87448a0ab8c9bcc6c2ab0cc8b2db019ae5b400fd/docs/setup.md#1-linking-1
@mohdzaifquraishi-greenapex @curtisgibeaut @bicanezin
Try putting this in the ext block of android/build.gradle.