expo: Exception occurred while executing exported method watchPositionImplAsync on module ExpoLocation

Hi, I catch an error with expo-location only on production on android (work well in dev). I tried with Location.watchPositionAsync() and Location.getLastKnownPositionAsync() :

const [location, setLocation] = useState(null);

useEffect(() => {
    (async () => {
      let { status } = await Location.requestForegroundPermissionsAsync();
      if (status !== "granted") {
        return;
      }
      try {
        await Location.watchPositionAsync(
          { accuracy: Location.Accuracy.High },
          (loc) => {
            setLocation(loc);
          }
        );
      } catch (error) {
        alert(error);
      }
    })();
  }, []);

Error: Encountered an exception while calling native method: Exception occurred while executing exported method watchPositionImplAsync on module ExpoLocation: Found interface com.google.android.gms.lo cation.FusedLocationProviderClient, but class was expected (declaration of ‘com.google.android.gms.locati on.FusedLocation ProviderClient’ appears in /data/app/

I use SDK 49 with expo-location 16.1.0 and managed workflow with eas build

_Originally posted by @m-regragui in https://github.com/expo/expo/issues/10756#issuecomment-1746555020_

About this issue

  • Original URL
  • State: open
  • Created 9 months ago
  • Reactions: 5
  • Comments: 50 (6 by maintainers)

Commits related to this issue

Most upvoted comments

Apparently going inside native-modules folder -> expo-location -> android -> build.gradle and changing:

api 'com.google.android.gms:play-services-location:x.x.x'to api 'com.google.android.gms:play-services-location:21.0.1'

fixes the issue!

So yes, expo team needs to patch this and update this dependency.

It worked perfectly. I just changed the following in the build.gradle api 'com.google.android.gms:play-services-location:20.0.0' to api 'com.google.android.gms:play-services-location:21.0.1' And applied the patch and builded using eas build -p android --profile production

Can you specify the changes you made in build.gradle using the script for patch-package? Hi @superyarik ,

  1. I installed patch-package using:

npx patch-package expo-location

  1. I then added patch-package to the scripts section in package.json
  "scripts": {
    "start": "expo start --dev-client",
    "android": "expo run:android",
    "ios": "expo run:ios",
    "web": "expo start --web",
    "postinstall": "patch-package"
  },
  1. I made sure that all my modules are installed:

npm install or npx expo install

  1. I modified node_modules/expo-location/android/build.gradle by updating line 108 :

reaplacing api 'com.google.android.gms:play-services-location:20.0.0'

with api 'com.google.android.gms:play-services-location:21.0.1'

  1. I then executed the patch-package script using:

npx patch-package expo-location

This produced a file in a sub folder patches/expo-location+16.4.0.patch with contains the delta of our patch

diff --git a/node_modules/expo-location/android/build.gradle b/node_modules/expo-location/android/build.gradle
index e16df0a..09341fc 100644
--- a/node_modules/expo-location/android/build.gradle
+++ b/node_modules/expo-location/android/build.gradle
@@ -105,7 +105,7 @@ dependencies {
     implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${getKotlinVersion()}"
   }
 
-  api 'com.google.android.gms:play-services-location:20.0.0'
+  api 'com.google.android.gms:play-services-location:21.0.1'
 
   api('io.nlopez.smartlocation:library:3.3.3') {
     transitive = false
  1. I finally commited my code to my branch and started the remote build on eas using:

eas build -p android --profile production

As far as I understand, this issue arises from a version mismatch of com.google.android.gms:play-services-location between expo-location and react-native-maps. See #23501 which essentially introduces the bug. To fix this, make sure you use the same version of com.google.android.gms:play-services-location for both expo-location and react-native-maps.

If you’re using expo-location@16.3.0 and react-native-maps@1.8.1 you can do so by bumping the one from expo-location as @CostasCF suggests. If you’re using patch-package, you can use this patch:

diff --git a/node_modules/expo-location/android/build.gradle b/node_modules/expo-location/android/build.gradle
index 3610030..01cd9f7 100644
--- a/node_modules/expo-location/android/build.gradle
+++ b/node_modules/expo-location/android/build.gradle
@@ -85,7 +85,7 @@ android {
 dependencies {
   implementation project(':expo-modules-core')
 
-  api 'com.google.android.gms:play-services-location:20.0.0'
+  api 'com.google.android.gms:play-services-location:21.0.1'
 
   api('io.nlopez.smartlocation:library:3.3.3') {
     transitive = false

hi @larbizard . is it necesary to make this? “postinstall”: “patch-package”, When I make npx install that bring me a lot of errors EDIT: Yes, it was very necessary. Also MAKE SURE to change the react native maps too. It works

@CostasCF Thank you ! It worked perfectly. I just changed the following in the build.gradle api 'com.google.android.gms:play-services-location:20.0.0' to api 'com.google.android.gms:play-services-location:21.0.1' And applied the patch and builded using eas build -p android --profile production

Hopefully the merge will be released soon !

@larbizard I think there is no way to get the changes remotely. However, it’s easy to do it locally. Make the needed changes inside node_modules folder, then you type:

npx patch-package expo-location

(Make sure to add the script in the package.json - follow the readme of patch-package)

Then, a folder called patches is created containing the changes you did locally.

So, then you can just type: eas build -p android --profile production

And it builds in the remote expo server.

Hi everyone ! I have updated the version of expo-location to the latest ~16.5.2 and it fixed it for me.

Finally it’s working! Thank you @farfanRogerBrandon ❤️

Apparently going inside native-modules folder -> expo-location -> android -> build.gradle and changing:

api 'com.google.android.gms:play-services-location:x.x.x'to api 'com.google.android.gms:play-services-location:21.0.1'

fixes the issue!

So yes, expo team needs to patch this and update this dependency.

This solved my problem, I use the patch package 😄

I ended up using patch-package for production as well. (Thanks @robrechtme for the suggestion!). It’s a good temporary fix till the new version of expo-location arrives.

@Thotsuya @mehdi78800

I am using expo location v16.3.0 and Expo SDK 49 and my fix works. You shouldn’t reinstall node modules with what I suggested as it overwrites the fix.

It’s only a temporary fix and it will only work in the local dev environment.

I still think expo team needs to update

api 'com.google.android.gms:play-services-location:x.x.x' to api 'com.google.android.gms:play-services-location:21.0.1' in expo-location package and it should work fine then for production.

I have not the issue in local dev environment, only in production, I also tried to downgrade expo-location but that not resolve the issue. I’m on expo location v16.1.0 and Expo SDK 49 and i also already tried to run a prebuild to create the android folder then change api ‘com.google.android.gms:play-services-location:x.x.x’ to api ‘com.google.android.gms:play-services-location:21.0.1’ but not working neither…

I think expo-location should update “play-services-location” to 21.0.1

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

If that is an issue for those using react-native-maps, they can update this package to v2.0.0-beta.14 which works with PSL 21.0.1.