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)
Apparently going inside native-modules folder -> expo-location -> android -> build.gradle and changing:
api 'com.google.android.gms:play-services-location:x.x.x'toapi '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.
npx patch-package expo-locationnpm installornpx expo installnode_modules/expo-location/android/build.gradleby 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'patch-packagescript using:npx patch-package expo-locationThis produced a file in a sub folder
patches/expo-location+16.4.0.patchwith contains the delta of our patcheas build -p android --profile productionAs far as I understand, this issue arises from a version mismatch of
com.google.android.gms:play-services-locationbetweenexpo-locationandreact-native-maps. See #23501 which essentially introduces the bug. To fix this, make sure you use the same version ofcom.google.android.gms:play-services-locationfor bothexpo-locationandreact-native-maps.If you’re using
expo-location@16.3.0andreact-native-maps@1.8.1you can do so by bumping the one fromexpo-locationas @CostasCF suggests. If you’re using patch-package, you can use this patch: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'toapi 'com.google.android.gms:play-services-location:21.0.1'And applied the patch and builded usingeas build -p android --profile productionHopefully 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 ❤️
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.
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.