react-native-geolocation
react-native-geolocation copied to clipboard
Fatal Exception: java.lang.SecurityException. Looks like the app doesn't have the permission to access location. Add the following line to your app's AndroidManifest.xml: <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Environment
System:
OS: macOS 10.14.6
CPU: (4) x64 Intel(R) Core(TM) i5-6360U CPU @ 2.00GHz
Memory: 734.45 MB / 16.00 GB
Shell: 5.3 - /bin/zsh
Binaries:
Node: 12.13.0 - ~/.nvm/versions/node/v12.13.0/bin/node
Yarn: 1.21.1 - /usr/local/bin/yarn
npm: 6.12.0 - ~/.nvm/versions/node/v12.13.0/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 13.2, DriverKit 19.0, macOS 10.15, tvOS 13.2, watchOS 6.1
Android SDK:
API Levels: 23, 24, 25, 26, 27, 28, 29
Build Tools: 23.0.1, 25.0.0, 25.0.1, 25.0.2, 25.0.3, 26.0.1, 26.0.2, 26.0.3, 27.0.1, 27.0.3, 28.0.3, 29.0.2
System Images: android-26 | Google APIs Intel x86 Atom, android-27 | Google Play Intel x86 Atom, android-29 | Google Play Intel x86 Atom
IDEs:
Xcode: 11.3/11C29 - /usr/bin/xcodebuild
npmPackages:
react: 16.12.0 => 16.12.0
react-native: ^0.61.5 => 0.61.5
Platforms
Android
Versions
- Android: 6, 7 & 8
- react-native-geolocation: ^2.0.2
- react-native: 0.61.5
- react: 16.12.0
Description
Hi there ! Thanks for the great lib. 🙂
Getting a crash in production on different versions of Android :
Fatal Exception: java.lang.SecurityException. Looks like the app doesn't have the permission to access location. Add the following line to your app's AndroidManifest.xml:
Although I do have the permissions in my android/app/src/main/AndroidManifest.xml
:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="xxxxxxxxxx.appmobile">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:name=".MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher"
android:allowBackup="false"
android:theme="@style/AppTheme"
android:networkSecurityConfig="@xml/network_security_config">
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="@string/ANDROID_GOOGLE_MAPS_API_KEY"/>
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_app_id"
/>
<meta-data
android:name="io.fabric.ApiKey"
android:value="xxxxxxxxxxxxxxxx"
/>
</application>
</manifest>
I'm using https://github.com/react-native-community/react-native-permissions to request permissions.
Any idea why that would happen or how to debug?
Can I see the AndroidManifest.xml
file once built to check if it does actually not include the permissions ? 🤔
Reproducible Demo
Can't reproduce in dev. Happens only in production...
Hey there team,
I'm getting this error too. It happens when I turn off the location services permissions at a system level and try to boot my app, and seems to happen despite having any calls to the Geolocation API wrapped in permission checks-- that is, the lib being included in the build seems to be what's throwing the error.
I can confirm that the AndroidManifest.xml from the actual build .apk has the correct permission.
@adrienthiery did you have any luck?
Nope, still happening...
Any workaround or solution for this bug ?
I just started getting this too.
I analyzed my release APK with the SDK command line tools: apkanalyzer.bat (for windows) and can confirm the permissions exist for the android.permission.ACCESS_FINE_LOCATION permission. Just wanted to help confirm this isn't an issue of the build process somehow blowing away that permission when built in release mode. (performed with C:>gradlew assembleRelease)
Problem still exists, any ideas?
Happens on Xiaomi devices (Redmi 5 Plus, Redmi Note 8 Pro) in production build
Happens on my old S7 and my S10e.
In dev it's fine, no problem. After installing an apk (made from "gradlew assembleRelease") and it tries to access the location.. boom...it crashes.
log cat from my S10e:
10-14 21:06:39.572 19410 20484 E AndroidRuntime: FATAL EXCEPTION: mqt_native_modules
10-14 21:06:39.572 19410 20484 E AndroidRuntime: Process: com.xxxxxxxxxxx, PID: 19410
10-14 21:06:39.572 19410 20484 E AndroidRuntime: java.lang.SecurityException: Looks like the app doesn't have the permission to access location.
10-14 21:06:39.572 19410 20484 E AndroidRuntime: Add the following line to your app's AndroidManifest.xml:
10-14 21:06:39.572 19410 20484 E AndroidRuntime: <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
10-14 21:06:39.572 19410 20484 E AndroidRuntime: at com.reactnativecommunity.geolocation.GeolocationModule.throwLocationPermissionMissing(GeolocationModule.java:309)
10-14 21:06:39.572 19410 20484 E AndroidRuntime: at com.reactnativecommunity.geolocation.GeolocationModule.startObserving(GeolocationModule.java:243)
10-14 21:06:39.572 19410 20484 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
10-14 21:06:39.572 19410 20484 E AndroidRuntime: at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
10-14 21:06:39.572 19410 20484 E AndroidRuntime: at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:158)
10-14 21:06:39.572 19410 20484 E AndroidRuntime: at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
10-14 21:06:39.572 19410 20484 E AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:883)
10-14 21:06:39.572 19410 20484 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:100)
10-14 21:06:39.572 19410 20484 E AndroidRuntime: at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:29)
10-14 21:06:39.572 19410 20484 E AndroidRuntime: at android.os.Looper.loop(Looper.java:237)
10-14 21:06:39.572 19410 20484 E AndroidRuntime: at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:232)
10-14 21:06:39.572 19410 20484 E AndroidRuntime: at java.lang.Thread.run(Thread.java:919)
10-14 21:06:39.572 19410 20484 E AndroidRuntime: Caused by: java.lang.SecurityException: "network" location provider requires ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission.
10-14 21:06:39.572 19410 20484 E AndroidRuntime: at android.os.Parcel.createException(Parcel.java:2088)
10-14 21:06:39.572 19410 20484 E AndroidRuntime: at android.os.Parcel.readException(Parcel.java:2056)
10-14 21:06:39.572 19410 20484 E AndroidRuntime: at android.os.Parcel.readException(Parcel.java:2004)
10-14 21:06:39.572 19410 20484 E AndroidRuntime: at android.location.ILocationManager$Stub$Proxy.requestLocationUpdates(ILocationManager.java:1266)
10-14 21:06:39.572 19410 20484 E AndroidRuntime: at android.location.LocationManager.requestLocationUpdates(LocationManager.java:1019)
10-14 21:06:39.572 19410 20484 E AndroidRuntime: at android.location.LocationManager.requestLocationUpdates(LocationManager.java:558)
10-14 21:06:39.572 19410 20484 E AndroidRuntime: at com.reactnativecommunity.geolocation.GeolocationModule.startObserving(GeolocationModule.java:235)
10-14 21:06:39.572 19410 20484 E AndroidRuntime: ... 10 more
10-14 21:06:39.572 19410 20484 E AndroidRuntime: Caused by: android.os.RemoteException: Remote stack trace:
10-14 21:06:39.572 19410 20484 E AndroidRuntime: at com.android.server.LocationManagerService.checkResolutionLevelIsSufficientForProviderUseLocked(LocationManagerService.java:2367)
10-14 21:06:39.572 19410 20484 E AndroidRuntime: at com.android.server.LocationManagerService.requestLocationUpdates(LocationManagerService.java:2955)
10-14 21:06:39.572 19410 20484 E AndroidRuntime: at android.location.ILocationManager$Stub.onTransact(ILocationManager.java:514)
10-14 21:06:39.572 19410 20484 E AndroidRuntime: at android.os.Binder.execTransactInternal(Binder.java:1056)
10-14 21:06:39.572 19410 20484 E AndroidRuntime: at android.os.Binder.execTransact(Binder.java:1029)
the top part of my manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xxxxxxxx">
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
....
And yes, the rest of the manifest is valid.
So.. since I tried last night again after months and posting on this same issue... I totally forgot that I had too, btw, I decided to move to another project. As documented from my comment on June8th, this has been an issue for me for months. https://www.npmjs.com/package/react-native-location
I spent about 10 mins implementing the new package. Altogether an hour looking at docs, remove old package, add new properly, dev release checked out, gradlew assembleRelease, and 3-4 different tests in that release APK.. all good, no errors or crashing.
This package is either dead or not enough updates in issues for me to stay interested in. I think the package maintainers should at least be responsive, even for open source. At 81k downloads/week reported on npmjs.com you'd think they would have buffed their triage process by now.
I had this same issue guys. It took me around 2 hours to find a solution and I did found it in docs, read carefully Android >= 23 part. Will post the solution here, it may help somebody to resolve this issue faster.
To resolve this issue add this extra step, I think it would be nice if creators of this lib will fix this one inside library or at least describe installation steps better.
import Geolocation from '@react-native-community/geolocation'; import { Platform, PermissionsAndroid } from 'react-native';
let granted = true;
if (Platform.OS === 'android') { granted = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION) }
if (granted) { Geolocation.getCurrentPosition(location => console.log(location)) }
still happens, upvote