I am stuck with a problem on my android device. The function getCurrentPositionAsync and watchPositionAsync work fine on my iOS device, android emulator and also on android simulator launched via Expo Go but does not work in my android device after I create an apk or aab via expo build:android
Here is the simplified component accessing location: availability-box-android.component.tsx
const AvailabilityBoxAndroid = () => {
const appContext = useContext(AppContext);
const [isLoading, setIsLoading] = useState<boolean>(true);
const [locationErrorMessage, setLocationErrorMessage] = useState<String>('');
const [androidLocation, setAndroidLocation] = useState(null);
useEffect(() => {
const states: StandardButtonStates = {
on: {
isActive: isLocationServicesAvailable && adHocAvailabilityStatus,
appearance: 'ghost',
onPress: handleAdHocAvailabilityButtonPressOff,
text: t('Set unavailable'),
},
off: {
isActive: isLocationServicesAvailable && !adHocAvailabilityStatus,
appearance: 'ghost',
onPress: handleAdHocAvailabilityButtonPressOn,
text: t('Set available'),
},
disabled: {
isActive: !isLocationServicesAvailable,
text: t('Set available (Location disabled)'),
},
};
}, [
androidLocation,
]);
const handleAdHocAvailabilityButtonPressOn = async () => {
setIsLoading(true);
let { status } = await ExpoLocation.requestForegroundPermissionsAsync();
if (status !== 'granted') {
setLocationErrorMessage('Permission to access location was denied');
return;
}
let location = await ExpoLocation.getCurrentPositionAsync({});
setAndroidLocation(location);
}};
const handleAdHocAvailabilityButtonPressOff = async () => {
setIsLoading(true);
setAndroidLocation(null);
return;
};
return (
<ContentBox
Title={
<View
style={{
flexDirection: 'row',
alignContent: 'stretch',
justifyContent: 'space-between',
}}
>
<View style={{ flexDirection: 'row' }}>
<View
style={{
height: 18,
width: 18,
backgroundColor: adHocAvailabilityStatus ? 'green' : 'red',
borderRadius: 18 / 2,
}}
></View>
<Text style={{ paddingLeft: 10, textTransform: 'uppercase' }}>
{adHocAvailabilityStatus ? t('available') + '' : t('unavailable') + ''}
</Text>
</View>
<View style={{ flexDirection: 'row' }}>
<LocationIcon
active={locationForegroundPermissionResponse?.granted === true}
/>
<Text
style={{
fontFamily: 'Lato_700Bold',
marginLeft: 15,
}}
>
{locationName ? locationName + '' : 'Location not known'}
</Text>
</View>
</View>
}
Content={
<View
style={{
flex: 1,
justifyContent: 'center',
alignItems: 'center',
}}
>
<StandardButton
states={adHocAvailabilityButtonStates}
isLoading={isLoading}
></StandardButton>
{<Text>{JSON.stringify(androidLocation)}</Text>}
<Text>{locationErrorMessage + ''}</Text>
</View>
}
></ContentBox>
);
};
I tried creating a fresh project with just location and it worked so I am assuming it might be something with my conflicting libraries. package json
{
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web",
"eject": "expo eject",
"test": "jest --watchAll"
},
"jest": {
"preset": "jest-expo"
},
"dependencies": {
"@apollo/client": "^3.3.21",
"@eva-design/eva": "^2.0.0",
"@expo-google-fonts/dev": "^0.1.0",
"@expo-google-fonts/lato": "^0.1.0",
"@expo/vector-icons": "^12.0.0",
"@expo/webpack-config": "~0.12.63",
"@fingerprintjs/fingerprintjs": "^3.2.0",
"@react-native-async-storage/async-storage": "~1.15.0",
"@react-native-community/masked-view": "0.1.10",
"@react-native-community/netinfo": "6.0.0",
"@react-navigation/bottom-tabs": "^5.11.2",
"@react-navigation/native": "^5.9.4",
"@react-navigation/stack": "^5.12.8",
"@types/javascript-time-ago": "^2.0.2",
"@types/jwt-decode": "^3.1.0",
"@types/lodash": "^4.14.171",
"@types/luxon": "^1.27.1",
"@types/uuid": "^8.3.1",
"@ui-kitten/components": "^5.1.0",
"@ui-kitten/eva-icons": "^5.1.0",
"class-validator": "^0.13.1",
"dotenv": "^8.2.0",
"expo": "^42.0.0",
"expo-app-loading": "^1.1.2",
"expo-auth-session": "~3.3.1",
"expo-battery": "~5.0.0",
"expo-constants": "~11.0.1",
"expo-device": "~3.3.0",
"expo-font": "~9.2.1",
"expo-intent-launcher": "~9.1.0",
"expo-linking": "~2.3.1",
"expo-localization": "~10.2.0",
"expo-location": "~12.1.2",
"expo-notifications": "~0.12.2",
"expo-permissions": "~12.1.1",
"expo-random": "~11.2.0",
"expo-secure-store": "~10.2.0",
"expo-splash-screen": "~0.11.2",
"expo-task-manager": "~9.2.2",
"expo-updates": "~0.8.0",
"expo-web-browser": "~9.2.0",
"fingerprintjs2": "^2.1.4",
"graphql": "^15.5.1",
"i18next": "^19.8.4",
"javascript-time-ago": "^2.3.7",
"jwt-decode": "^3.1.2",
"lodash": "^4.17.21",
"luxon": "^1.25.0",
"react": "16.13.1",
"react-dom": "16.13.1",
"react-i18next": "^11.11.1",
"react-native": "https://github.com/expo/react-native/archive/sdk-42.0.0.tar.gz",
"react-native-advertising-id": "^1.0.11",
"react-native-appearance": "~0.3.3",
"react-native-calendars": "^1.1264.0",
"react-native-elements": "^3.4.2",
"react-native-flags": "^1.0.0",
"react-native-gesture-handler": "~1.10.2",
"react-native-get-random-values": "~1.7.0",
"react-native-paper": "^4.9.2",
"react-native-reanimated": "~2.2.0",
"react-native-safe-area-context": "3.2.0",
"react-native-screens": "~3.4.0",
"react-native-svg": "12.1.1",
"react-native-vector-icons": "^7.1.0",
"react-native-web": "~0.13.12",
"react-refresh": "^0.8.3",
"uuid": "^8.3.2"
},
"devDependencies": {
"@expo/ngrok": "^2.5.0",
"@types/react": "~16.9.35",
"@types/react-native": "~0.63.2",
"file-loader": "^6.2.0",
"react-devtools": "^4.13.5",
"typescript": "~4.0.0"
},
"private": true
}