Geolocation plugin user-permission error. not detecting AndroidManifest set permissions

Bug Report

Plugin(s)

@capacitor/geolocation”: “^1.3.1”,

Capacitor Version

Latest Dependencies:

@capacitor/cli: 4.6.1
@capacitor/core: 4.6.1
@capacitor/android: 4.6.1
@capacitor/ios: 4.6.1

Installed Dependencies:

@capacitor/cli: 3.9.0
@capacitor/ios: 3.9.0
@capacitor/android: 3.9.0
@capacitor/core: 3.9.0

Platform(s)

Android 12+

Current Behavior

When calling method requestGeoPermissions, an error is thrown that AndroidManifest is missing needed permissions.

Expected Behavior

Should work properly since I have the user-permissions already in the manifest.

Code Reproduction

` async requestGeoPermissions() {

  await Geolocation.requestPermissions('location')
  .then((result) => {

      this.$log.debug('TgPermissionsTest:requestGeoPermissions:success:', result);

    })
    .catch((error) => {

      this.$log.debug('TgPermissionsTest:requestGeoPermissions:success:', error);

    })
},`

Other Technical Details

Additional Context

Console error with live reload:

TgPermissionsTest:requestGeoPermissions:success: Error: Missing the following permissions in AndroidManifest.xml:
android.permission.ACCESS_FINE_LOCATION
android.permission.ACCESS_COARSE_LOCATION

at cap.fromNative (permissions_test:413:32)
at <anonymous>:1:18`

Error in production:

TgPermissionsTest:requestGeoPermissions:success: Error: Missing the following permissions in AndroidManifest.xml:
android.permission.ACCESS_FINE_LOCATION
android.permission.ACCESS_COARSE_LOCATION

at cap.fromNative (VM3:413:32)
at <anonymous>:1:18

AndroidManifest.xml

<uses-permission android:maxSdkVersion="30" android:name="android.permission.BLUETOOTH" />
<uses-permission android:maxSdkVersion="30" android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-feature android:name="android.hardware.location.gps" />

Dependencies

"dependencies": {
"@capacitor/android": "^3.4.3",
"@capacitor/app": "1.1.1",
"@capacitor/camera": "^1.3.1",
"@capacitor/core": "^3.4.3",
"@capacitor/geolocation": "^1.3.1",
"@capacitor/haptics": "1.1.4",
"@capacitor/ios": "^3.4.3",
"@capacitor/keyboard": "1.2.2",
"@capacitor/network": "^1.0.7",
"@capacitor/text-zoom": "^1.0.8",
"@ianwalter/vuex-reset": "^4.3.2",
"@ionic-native/android-permissions": "^5.36.0",
"@ionic-native/barcode-scanner": "^5.36.0",
"@ionic-native/bluetooth-le": "^5.36.0",
"@ionic-native/core": "^5.36.0",
"@ionic-native/file": "^5.36.0",
"@ionic-native/globalization": "^5.36.0",
"@ionic-native/http": "^5.36.0",
"@ionic-native/network": "^5.36.0",
"@ionic-native/screen-orientation": "^5.36.0",
"@ionic-native/wifi-wizard-2": "^5.36.0",
"@ionic/vue": "^6.0.10",
"@ionic/vue-router": "^6.0.10",
"@tigoapps/tigobatterymanagement": "^1.0.31",
"@tigoapps/tigobuild": "^3.1.39",
"@tigoapps/tigocalendar": "^1.1.10",
"@tigoapps/tigochart": "^1.1.27",
"@tigoapps/tigochartnav": "^1.1.17",
"@tigoapps/tigoflow": "^2.2.42",
"@tigoapps/tigoicons": "^1.0.84",
"@tigoapps/tigomap": "^1.1.29",
"@tigoapps/tigorange": "^0.1.21",
"@tigoapps/tigotoggle": "^1.0.9",
"@tigoapps/tigoutils": "^0.1.73",
"@vueform/slider": "^2.0.9",
"@vuelidate/core": "^2.0.0-alpha.34",
"@vuelidate/validators": "^2.0.0-alpha.26",
"axios": "^0.21.4",
"babel-plugin-require-context-hook": "^1.0.0",
"bootstrap": "^4.6.1",
"cordova-plugin-advanced-http": "^3.2.2",
"cordova-plugin-android-permissions": "^1.1.3",
"cordova-plugin-ble-central": "^1.6.1",
"cordova-plugin-file": "^6.0.2",
"cordova-plugin-globalization": "^1.11.0",
"cordova-plugin-network-information": "^2.0.2",
"cordova-plugin-screen-orientation": "^3.0.2",
"cordova-plugin-wifiwizard2": "^3.1.1",
"cordova.plugins.diagnostic": "^7.1.1",
"core-js": "^3.21.1",
"crypto-js": "^4.1.1",
"d3-transition": "^2.0.0",
"es6-promise-plugin": "^4.2.2",
"intl-tel-input": "^17.0.18",
"jquery": "^3.6.0",
"js-sha512": "^0.8.0",
"localforage": "^1.10.0",
"localforage-cordovasqlitedriver": "^1.8.0",
"loglevel": "^1.8.0",
"moment-timezone": "^0.5.34",
"numeral": "^2.0.6",
"phonegap-plugin-barcodescanner": "^8.1.0",
"promise.any": "^2.0.3",
"recursive-diff": "^1.0.8",
"sass": "^1.49.9",
"sass-loader": "^8.0.2",
"swiper": "^7.4.1",
"vue": "3.2.30",
"vue-filter-number-format": "^3.0.1",
"vue-gtag": "^2.0.1",
"vue-i18n": "^9.1.9",
"vue-i18n-scanner": "^1.0.5",
"vue-matomo": "^4.1.0",
"vue-moment": "^4.1.0",
"vue-router": "^4.0.13",
"vue-toasted": "^1.1.28",
"vuex": "^4.0.2",
"vuex-map-fields": "^1.4.1"

}

Your issue is most likely related to your Capacitor version. Capacitor 4 and all the plugin updates for that added support for SDK 31 on Android. I’d recommend updating to V4 and see if that resolves your issue. You can follow the guide here or if you use the VS Code extension, it’s got a 1-click upgrade path that you can use that works for most people.

Hope this helps!

1 Like

I’ve done that upgrade to V4 now but the problem persists.


Ionic:

   Ionic CLI       : 6.19.0 (C:\Users\Henry\AppData\Roaming\npm\node_modules\@ionic\cli)
   Ionic Framework : @ionic/vue 6.4.1

Capacitor:

   Capacitor CLI      : 4.6.1
   @capacitor/android : 4.6.1
   @capacitor/core    : 4.6.1
   @capacitor/ios     : 4.6.1

Utility:

   cordova-res : not installed globally
   native-run  : 1.7.1

System:

   NodeJS : v16.14.2 (C:\Program Files\nodejs\node.exe)
   npm    : 8.5.0
   OS     : Windows 10

The error:

requestGeoPermissions:success: Error: Missing the following permissions in AndroidManifest.xml:
android.permission.ACCESS_FINE_LOCATION
android.permission.ACCESS_COARSE_LOCATION

    at returnResult (VM3:747:32)
    at win.androidBridge.onmessage (VM3:722:21)

Our manifest includes those two permissions.

Code:

   async requestGeoPermissions() {
      await Geolocation.requestPermissions()
        .then((result) => {
          this.$log.debug('TgPermissionsTest:requestGeoPermissions:success:', result);
        })
        .catch((error) => {
          this.$log.debug('TgPermissionsTest:requestGeoPermissions:success:', error);
        })
    },

Attempting to debug the @capacitor/geolocation plugin directly and I can see in Android studio logs:

2023-01-05 12:13:13.365 9838-9838/com.tigoenergy.smart V/Capacitor/Plugin: To native (Capacitor plugin): callbackId: 56640974, pluginId: Geolocation, methodName: getCurrentPosition
2023-01-05 12:13:13.365 9838-9838/com.tigoenergy.smart V/Capacitor: callback: 56640974, pluginId: Geolocation, methodName: getCurrentPosition, methodData: {"enableHighAccuracy":true,"timeout":5000,"maximumAge":0}
2023-01-05 12:13:13.377 9838-9838/com.tigoenergy.smart V/Capacitor/AppPlugin: Notifying listeners for event pause
2023-01-05 12:13:13.377 9838-9838/com.tigoenergy.smart D/Capacitor/AppPlugin: No listeners found for event pause
2023-01-05 12:13:13.378 9838-9838/com.tigoenergy.smart D/Capacitor: App paused
2023-01-05 12:13:13.422 9838-9838/com.tigoenergy.smart D/Capacitor: Unable to find a Capacitor plugin to handle permission requestCode, trying Cordova plugins 450497393
2023-01-05 12:13:13.426 9838-9838/com.tigoenergy.smart D/Capacitor: Sending plugin error: {"save":false,"callbackId":"56640974","pluginId":"Geolocation","methodName":"getCurrentPosition","success":false,"error":{"message":"Missing the following permissions in AndroidManifest.xml:\nandroid.permission.ACCESS_FINE_LOCATION\nandroid.permission.ACCESS_COARSE_LOCATION\n"}}

Have you done an npx cap sync since you installed the plugin? If it’s unable to find the plugin when running, that would be my first guess as to what’s wrong there.

Yeah we have, we’re very experienced with Ionic Framework, Capacitor and Cordova. We’ve now forked the plugin and are debugging the java code as this is a severe issue for our app.

Got the Ionic starter working with the plugin, now I just need to figure out what change you guys made that is undocumented.

Execute

npx cap migrate

Later

ncu -i

You must have the plugin installed npm-check-updates - npm

Update all capacitor components, angular

It seems that you are using an old library.
@capacitor/geolocation”: “^1.3.1”,

And the last is
@capacitor/geolocation”: “4.1.0”

I’ve updated all that a while ago:

    "@capacitor/android": "^4.6.1",
    "@capacitor/app": "4.1.1",
    "@capacitor/core": "4.6.1",
    "@capacitor/ios": "^4.6.1",
    "@capacitor/camera": "^4.0.0",
    "@capacitor/geolocation": "^4.1.0",
    "@capacitor/haptics": "^4.0.0",
    "@capacitor/keyboard": "^4.0.0",
    "@capacitor/network": "^4.0.0",
    "@capacitor/text-zoom": "^4.0.0",


    "@capacitor/cli": "^4.6.1",

The starter app breaks after I install all my other cordova/capacitor plugins:


 "dependencies": {
    "@capacitor/android": "^4.6.1",
    "@capacitor/app": "4.1.1",
    "@capacitor/core": "4.6.1",
    "@capacitor/geolocation": "^4.1.0",
    "@capacitor/haptics": "4.1.0",
    "@capacitor/camera": "^4.1.4",
    "@capacitor/network": "^4.1.0",
    "@capacitor/keyboard": "4.1.0",
    "@capacitor/status-bar": "4.1.1",
    "@ionic/vue": "^6.0.0",
    "@ionic/vue-router": "^6.0.0",
    "core-js": "^3.6.5",
    "ionicons": "^6.0.3",
    "vue": "^3.2.21",
    "vue-router": "^4.0.12",
    "es6-promise-plugin": "^4.2.2",
    "@ionic-native/android-permissions": "^5.36.0",
    "@ionic-native/barcode-scanner": "^5.36.0",
    "@ionic-native/bluetooth-le": "^5.36.0",
    "@ionic-native/core": "^5.36.0",
    "@ionic-native/file": "^5.36.0",
    "@ionic-native/globalization": "^5.36.0",
    "@ionic-native/http": "^5.36.0",
    "@ionic-native/network": "^5.36.0",
    "@ionic-native/screen-orientation": "^5.36.0",
    "@ionic-native/wifi-wizard-2": "^5.36.0",
    "cordova-plugin-advanced-http": "^3.2.2",
    "cordova-plugin-android-permissions": "^1.1.3",
    "cordova-plugin-ble-central": "^1.6.1",
    "cordova-plugin-file": "^6.0.2",
    "cordova-plugin-globalization": "^1.11.0",
    "cordova-plugin-network-information": "^2.0.2",
    "cordova-plugin-screen-orientation": "^3.0.2",
    "cordova-plugin-wifiwizard2": "^3.1.1"
  },

Something is going wrong when using a combination of these…

If required most help. write me to Share on WhatsApp

Once I installed this plugin:

Everything breaks with @capacitor/geolocation

3 Likes

I experienced the exact same thing. It was the BLE plugin for me as well. Thanks for the post!

great work guys that was the issue for me too, how did you manage to spot these kinds of incompatibilities between plug-ins?