Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App crashes or could not invoke Geolocation.getCurrentPosition #398

Open
swatiredhu17 opened this issue Jan 30, 2023 · 23 comments
Open

App crashes or could not invoke Geolocation.getCurrentPosition #398

swatiredhu17 opened this issue Jan 30, 2023 · 23 comments
Labels
bug Something isn't working

Comments

@swatiredhu17
Copy link

Environment

System:
OS: macOS 12.2.1
CPU: (4) x64 Intel(R) Core(TM) 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

  1. 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' }
  2. 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 #367

@swatiredhu17 swatiredhu17 added the bug Something isn't working label Jan 30, 2023
@mohdzaifquraishi-greenapex

Any solution ?

@curtisgibeaut
Copy link

This is occurring for me with 22.50.14 of google play services as well.

@bicanezin
Copy link

Any solution?

@riku99
Copy link

riku99 commented Oct 12, 2023

@mohdzaifquraishi-greenapex @curtisgibeaut @bicanezin

Try putting this in the ext block of android/build.gradle.

googlePlayServicesVersion = "21.0.1"
@LinaEfer
Copy link

@mohdzaifquraishi-greenapex @curtisgibeaut @bicanezin

Try putting this in the ext block of android/build.gradle.

googlePlayServicesVersion = "21.0.1"

Hello, this solution doesn't work in case if you have other libraries with googlePlayServices dependencies.
Like, by declaring googlePlayServicesVersion = "21.0.1" you force every module dependency switch to "21.0.1", in case if this version doesn't existe you got build error.

An exemple :

  • react-native-device-info has com.google.android.gms.play-services-iid module, which is latest version 17.0.0.

In my case this error is still present :

  • "react": "18.2.0",
  • "react-native": "^0.71.8",
  • "react-native-geolocation-service": "^5.3.1",
  • android/app/build.gradle -> implementation "com.google.android.gms:play-services-location:21.0.1"

So, still the same question: any idea ? 🙏

@bicanezin
Copy link

@LinaEfer
My case and the 'solution': after including this dependency in the project, I had this issue when I deleted the yarn.lock and node_modules. I noticed that by keeping the project's yarn.lock while it was working, I no longer had any problems.

@LinaEfer
Copy link

@bicanezin Unfortunately in my case full clean up (node_modules + yarn.lock, pods, android sync prject & gradle files) doesn't fix the issue :(

@LinaEfer My case and the 'solution': after including this dependency in the project, I had this issue when I deleted the yarn.lock and node_modules. I noticed that by keeping the project's yarn.lock while it was working, I no longer had any problems.

@SulthanYS
Copy link

@mohdzaifquraishi-greenapex @curtisgibeaut @bicanezin

Try putting this in the ext block of android/build.gradle.

googlePlayServicesVersion = "21.0.1"

Locking a particular googlePlayServicesVersion, is a best practices?

@vsheyanov
Copy link

Possible solution: check my response to react-native-maps module which changed location module version and broke our app:
react-native-maps/react-native-maps#4858 (comment)

BTW, 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

@SulthanYS
Copy link

Possible solution: check my response to react-native-maps module which changed location module version and broke our app: react-native-maps/react-native-maps#4858 (comment)

BTW, 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

Thanks for the info @vsheyanov I'll check from my side and share info here

@vsheyanov
Copy link

@SulthanYS I updated my answer with a command ./gradlew app:dependencies that helped me to find rn-maps library that updated location dependency that was causing problems.
In our case googlePlayServicesVersion with version > 20 was resulting in a crash.

@riku99
Copy link

riku99 commented Oct 28, 2023

@LinaEfer

You might want to try modifying the build.gradle file of react-native-geolocation-service directly.

Change this line:

implementation "com.google.android.gms:play-services-location:$googlePlayServicesVersion"

to:

implementation "com.google.android.gms:play-services-location:21.0.1"

However, I haven't actually tested this myself as I am not using react-native-device-info.

@Danushka96
Copy link

Any solution for this issue?

@phatlaunchdeck
Copy link

So far @riku99's workaround is the way to go, I can confirm it's working with React Native 72 and latest version of react-native-device-info.

@kimthompson
Copy link

The solutions here didn't quite work for me, but the one here did. It's extremely similar, except in android/gradle.build I set playServicesLocationVersion instead of googlePlayServicesVersion.

@AbaidullahRajpoot
Copy link

AbaidullahRajpoot commented Feb 2, 2024

Certainly! If you are using React Native version 0.71 and need to update the Google Play Services location dependency, follow these steps:

  1. In android/app/build.gradle:
    Add the following line to the dependencies section:

dependencies {
// other dependencies

implementation("com.google.android.gms:play-services-location:21.0.1") //add this line

}

  1. In android/build.gradle:
    Add the googlePlayServicesVersion in the ext block within the buildscript section:

buildscript {
ext {
// other configurations
googlePlayServicesVersion = "21.0.1" //add this line
}
// other configurations
}

@andrecrimb
Copy link

Thanks @riku99 it solves the issue 🙏🏽

@AftabUfaq
Copy link

a solution for this is . go to file node_modules\react-native-geolocation-service\android\build.gradle and change the this line

def DEFAULT_GOOGLE_PLAY_SERVICES_VERSION = "18.0.0"
to
def DEFAULT_GOOGLE_PLAY_SERVICES_VERSION = "21.0.1"

and all like this

dependencies {
   implementation "com.facebook.react:react-native:+"
  implementation 'androidx.appcompat:appcompat:1.0.2'
  implementation "com.google.android.gms:play-services-location:21.0.1"
}

and patch the package with yarn patch-package react-native-geolocation-service

and your issue will be gone

@usamaabutt
Copy link

@LinaEfer

You might want to try modifying the build.gradle file of react-native-geolocation-service directly.

Change this line:

implementation "com.google.android.gms:play-services-location:$googlePlayServicesVersion"

to:

implementation "com.google.android.gms:play-services-location:21.0.1"

However, I haven't actually tested this myself as I am not using react-native-device-info.

It fixed my crash. Thanks!

@Bilal-Abdeen
Copy link

As @kimthompson indicated, updating android/build.gradle and android/app/build.gradle throws an error for me. Updating ONLY android/build.gradle worked perfectly.

buildscript {
 ext {
   // .....
   playServicesLocationVersion = "21.0.1" // add this 
   // .....
  }
}
@rider-cantuaria-eng
Copy link

remove the react-native-geolocation-service and install npm install react-native-fused-location, this lib works.

@gnvcor
Copy link

gnvcor commented Jul 23, 2024

@Bilal-Abdeen it's work, thx!

@awais882s
Copy link

awais882s commented Sep 10, 2024

@AftabUfaq Thank you brother
Working fine now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working