expo: Location.getCurrentPositionAsync not working anymore on Android

Minimal reproducible example

You can reproduce it by yourself by creating a project and following these steps

const getPosition = async () => {
	try {
		const location = await Location.getCurrentPositionAsync();
		console.log(location)

	} catch (error) {
		console.error(error);
	}
};

Run on android simulator

Summary

Location.getCurrentPositionAsync() is currently not working on android device.

Error :

[Error: Encountered an exception while calling native method: Exception occurred while executing exported method getCurrentPositionAsync on module ExpoLocation: Found interface com.google.android.gms.location.FusedLocationProviderClient, but class was expected (declaration of 'com.google.android.gms.location.FusedLocationProviderClient' appears in /data/app/~~Wgqj3r99uKWvrH_B0MaJug==/com.app.dev-ZD2IwBYB-aky0AQxmxqpyA==/base.apk!classes6.dex)]

It was working fine before. I did some research and it may be caused by the last update of google play service : (Release Notes | Google Play services | Google for Developers)

October 13, 2022 The latest update to the play-services-location library includes the following changes:

[FusedLocationProviderClient](https://developers.google.com/android/reference/com/google/android/gms/location/FusedLocationProviderClient), [ActivityRecognitionClient](https://developers.google.com/android/reference/com/google/android/gms/location/ActivityRecognitionClient), [GeofencingClient](https://developers.google.com/android/reference/com/google/android/gms/location/GeofencingClient) and [SettingsClient](https://developers.google.com/android/reference/com/google/android/gms/location/SettingsClient) are now interfaces instead of classes, which helps enforce correct usage and improves testability.

As the error above says :

Found interface com.google.android.gms.location.FusedLocationProviderClient, but class was expected

As the release says :

FusedLocationProviderClient, ... are now interfaces instead of classes

Any solution for this ?

Environment

    System:
      OS: macOS 13.0.1
      Shell: 5.8.1 - /bin/zsh
    Binaries:
      Node: 19.9.0 - ~/.nvm/versions/node/v19.9.0/bin/node
      Yarn: 1.22.17 - /opt/homebrew/bin/yarn
      npm: 9.6.3 - ~/.nvm/versions/node/v19.9.0/bin/npm
    Managers:
      CocoaPods: 1.12.1 - /opt/homebrew/bin/pod
    SDKs:
      iOS SDK:
        Platforms: DriverKit 22.1, iOS 16.1, macOS 13.0, tvOS 16.1, watchOS 9.1
      Android SDK:
        API Levels: 31
        Build Tools: 31.0.0
        System Images: android-29 | Google Play ARM 64 v8a, android-31 | Google APIs ARM 64 v8a
    IDEs:
      Xcode: 14.1/14B47b - /usr/bin/xcodebuild
    npmPackages:
      expo: 48.0.0 => 48.0.0 
      react: 18.2.0 => 18.2.0 
      react-native: 0.71.8 => 0.71.8 
    npmGlobalPackages:
      eas-cli: 3.16.0
    Expo Workflow: managed```

About this issue

  • Original URL
  • State: closed
  • Created 9 months ago
  • Comments: 15

Most upvoted comments

Hi there! It looks like your issue requires a minimal reproducible example, but it is invalid or absent. Please prepare such an example and share it in a new issue.

The best way to get attention to your issue is to provide a clean and easy way for a developer to reproduce the issue on their own machine. Please do not provide your entire project, or a project with more code than is necessary to reproduce the issue.

A side benefit of going through the process of narrowing down the minimal amount of code needed to reproduce the issue is that you may get lucky and discover that the bug is due to a mistake in your application code that you can quickly fix on your own.

Resources

Common concerns

“I’ve only been able to reproduce it in private, proprietary code”

You may not have spent enough time narrowing down the root cause of the issue. Try out the techniques discussed in this manual debugging guide to learn how to isolate the problem from the rest of your codebase.

“I didn’t have time to create one”

That’s understandable, it can take some time to prepare. We ask that you hold off on filing an issue until you are able to fully complete the required fields in the issue template.

“You can reproduce it by yourself by creating a project and following these steps”

This is useful knowledge, but it’s still valuable to have the resulting project that is produced from running the steps, where you have verified you can reproduce the issue.

So I’ve changed api 'com.google.android.gms:play-services-location:20.0.0' to api 'com.google.android.gms:play-services-location:21.0.1' in /node_modules/expo-location/android/build.gradle in as suggested, and it works when running npx expo run:android on a simulator or my own device. But when I create a build with eas build --platform android --local --profile preview, location doesn’t work at all (in fact the status bar location icon doesn’t even light up) Any advice ?