Location provider is unavailable on Android 6

Hi everyone,

I need help because I’m facing a location issue on Android and can’t figure out how to resolve it.
Even if location is enabled and permission is given, Location.getCurrentPositionAsync return E_LOCATION_UNAVAILABLE code.

Works on Snack but not on Expo Client and neither on standalone app on my Android phone.
Everything works well on iOS.

This issue appears on SDK 37 and continue appearing after updating to SDK38 and SDK39.

  1. SDK Version:
    Expo CLI 3.28.0 environment info:
    System:
    OS: macOS 10.15.4
    Shell: 3.2.57 - /bin/bash
    Binaries:
    Node: 12.16.2 - /usr/local/bin/node
    npm: 6.14.8 - ~/.npm-global/bin/npm
    SDKs:
    iOS SDK:
    Platforms: iOS 13.4, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2
    IDEs:
    Android Studio: 4.1 AI-201.8743.12.41.6858069
    Xcode: 11.4.1/11E503a - /usr/bin/xcodebuild
    npmPackages:
    expo: ~39.0.2 => 39.0.3
    react: 16.13.1 => 16.13.1
    react-dom: 16.13.1 => 16.13.1
    react-native: https://github.com/expo/react-native/archive/sdk-39.0.3.tar.gz => 0.63.2
    react-native-web: ~0.13.12 => 0.13.18
    npmGlobalPackages:
    expo-cli: 3.28.0
    Expo Workflow: managed

  2. Platforms(Android/iOS/web/all):
    OS : Android 6.0
    Model: Huawei ALE-L21

import { StatusBar } from 'expo-status-bar';
import React, { useEffect, useState } from 'react';
import { StyleSheet, Text, View } from 'react-native';
import * as Location from 'expo-location';

export default function App() {
  const [location, setLocation] = useState(null);
  const [errorMsg, setErrorMsg] = useState(null);

  useEffect(() => {
    (async () => {
      try {
        const isLocationEnabled = await Location.hasServicesEnabledAsync();
        if (!isLocationEnabled) {
          throw new Error('Location is disabled')
        }
        let { status } = await Location.requestPermissionsAsync();
        if (status !== 'granted') {
          throw new Error('Permission to access location was denied');
        }

        let location = await Location.getCurrentPositionAsync({});
        setLocation(location);
      } catch (err) {
        setErrorMsg(err);
      }
    })();
  }, []);

  let text = 'Waiting..';
  if (errorMsg) {
    if (typeof errorMsg === 'string') text = errorMsg;
    else text = JSON.stringify(errorMsg);
    console.log(text);
  } else if (location) {
    text = JSON.stringify(location);
  }
  return (
    <View style={styles.container}>
      <Text>{text}</Text>
      <StatusBar style="auto" />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});

Returned error :

{"nativeStackAndroid":[{"lineNumber":2,"file":"LocationModule.java","methodName":"onLocationAvailability","class":"abi39_0_0.expo.modules.location.LocationModule$1"},{"lineNumber":-1,"file":null,"methodName":"a","class":"d.g.b.f.f.m.w"},{"lineNumber":3,"file":"com.google.android.gms:play-services-base@@17.3.0","methodName":"d","class":"com.google.android.gms.common.api.internal.k"},{"lineNumber":3,"file":"com.google.android.gms:play-services-base@@17.3.0","methodName":"handleMessage","class":"com.google.android.gms.common.api.internal.k$c"},{"lineNumber":102,"file":"Handler.java","methodName":"dispatchMessage","class":"android.os.Handler"},{"lineNumber":1,"file":"com.google.android.gms:play-services-base@@17.3.0","methodName":"dispatchMessage","class":"d.g.b.f.f.d.h"},{"lineNumber":150,"file":"Looper.java","methodName":"loop","class":"android.os.Looper"},{"lineNumber":8,"file":"MessageQueueThreadImpl.java","methodName":"run","class":"abi39_0_0.com.facebook.react.bridge.queue.MessageQueueThreadImpl$4"},{"lineNumber":833,"file":"Thread.java","methodName":"run","class":"java.lang.Thread"}],"userInfo":null,"message":"Location provider is unavailable. Make sure that location services are enabled.","code":"E_LOCATION_UNAVAILABLE","line":2543,"column":45,"sourceURL":"http://192.168.1.37:19001/node_modules/expo/AppEntry.bundle?platform=android&dev=true&minify=false&hot=false"}
{"nativeStackAndroid":[{"lineNumber":2,"file":"LocationModule.java","methodName":"onLocationAvailability","class":"abi39_0_0.expo.modules.location.LocationModule$1"},{"lineNumber":-1,"file":null,"methodName":"a","class":"d.g.b.f.f.m.w"},{"lineNumber":3,"file":"com.google.android.gms:play-services-base@@17.3.0","methodName":"d","class":"com.google.android.gms.common.api.internal.k"},{"lineNumber":3,"file":"com.google.android.gms:play-services-base@@17.3.0","methodName":"handleMessage","class":"com.google.android.gms.common.api.internal.k$c"},{"lineNumber":102,"file":"Handler.java","methodName":"dispatchMessage","class":"android.os.Handler"},{"lineNumber":1,"file":"com.google.android.gms:play-services-base@@17.3.0","methodName":"dispatchMessage","class":"d.g.b.f.f.d.h"},{"lineNumber":150,"file":"Looper.java","methodName":"loop","class":"android.os.Looper"},{"lineNumber":8,"file":"MessageQueueThreadImpl.java","methodName":"run","class":"abi39_0_0.com.facebook.react.bridge.queue.MessageQueueThreadImpl$4"},{"lineNumber":833,"file":"Thread.java","methodName":"run","class":"java.lang.Thread"}],"userInfo":null,"message":"Location provider is unavailable. Make sure that location services are enabled.","code":"E_LOCATION_UNAVAILABLE","line":2543,"column":45,"sourceURL":"http://192.168.1.37:19001/node_modules/expo/AppEntry.bundle?platform=android&dev=true&minify=false&hot=false"}

I precise that High Accuracy is enabled in phone settings

I’ve tried differents solution that i’ve found on web but none of them works:

  • give an empty object as options
  • give different accuracies as options (Low/Balanced/High)

I don’t want to detach Expo as mentionned here

Any help will be very appreciated.

Hey @smart_futures, have you been able to try with other device models running Android 6 or only the Huawei ALE-L21?

If possible, it’d be great to know if this is OS-specific or device/model specific.

Cheers,
Adam

Hi @adamjnav! Thanks for your reply. Same problem appears on Google Pixel 4.0 emulator (Android 6.0 - API 23). Today, I will try differents Android versions to give you more information about if it’s OS related.

@adamjnav I share this Google sheets that sum up my tests (Expo Location Test - Android). I 'm gonna continue to fill it out as the testing progresses on the different versions of Android (actually done : 6.0 & 7.1) . Hope it can help.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.