Ionic-native: Geolocation 4.1.0: Illegal value $GPS_REQUIRED

Created on 25 Nov 2020  路  9Comments  路  Source: ionic-team/ionic-native

The plugin cordova-plugin-geolocation added the variable $GPS_REQUIRED in the release 4.1.0.
https://github.com/apache/cordova-plugin-geolocation/pull/189

Its added to the cordova plugin by the --variable parameter. Unfortunately we cant use this with capacitor. Now the android/capacitor-cordova-android-plugins/AndroidManifest.xml contains this line:
<uses-feature android:name="android.hardware.location.gps" android:required="$GPS_REQUIRED"/>
and outputs the error:

Attribute uses-feature#android.hardware.location.gps@required at AndroidManifest.xml:13:60-92 has an illegal value=($GPS_REQUIRED), expected 'true' or 'false' capacitor-cordova-android-plugins main manifest (this file), line 12

Setting this manually to true or false will set it back to '$GPS_REQUIRED' on the next cap sync. Is it possible to use this with capacitor this way?

Most helpful comment

update capacitor to 2.4.4

All 9 comments

same issue. build failed

+1

+1

+1

It is not ideal, but as a temporary "solution", I have added the following script to my npm commands
"android": "npx cap sync android && sed -i 's/$GPS_REQUIRED/true/' android/capacitor-cordova-android-plugins/src/main/AndroidManifest.xml
So instead of npx cap sync android im using npm run android

update capacitor to 2.4.4

Still seeing this issue in capacitor 2.4.6 - are there any other dependencies that need to be updated? @pete-mcwilliams

Still seeing this issue in capacitor 2.4.6 - are there any other dependencies that need to be updated? @pete-mcwilliams

Sorry, since I was poking around with the issue, I have switched to using capacitor Geolocation instead of the Cordova module.

I was just linking the pull request to this issue for anyone else that came past this thread.

something to get you started with capacitor geolocation

import { GeolocationOptions, GeolocationPosition, Plugins } from '@capacitor/core';

const { Geolocation } = Plugins;

<snip>
  options: GeolocationOptions;

  constructor(
    private platform: Platform,
  ) {
    this.options = {
      enableHighAccuracy: false,
      timeout: 10000
    };
  }

  async getLatestPosition(): Promise<GeolocationPosition> {
    try {
      return await Geolocation.getCurrentPosition(this.options);
    } catch (err) {
     console.error('Error getting location: ', err);
    }
  }
Was this page helpful?
0 / 5 - 0 ratings