0

I'd like to set androids permissions to use geolocation in config.xml.

I don't want to use cordova-plugin-geolocation which would set these settings as a side-effect because the webviews I am targeting (crosswalk) support GeoLocation out of the box. The Plugin would just be bloatware.

I don't want to write it directly in AndroidManifest.xml because I am using cordova prepare to prevent having any plattform-specific stuff inside my repository. Everybody is currently able to build the plattforms from scratch without any plattform-specific stuff from our git-repo.

What I tried

I took a look at cordova-plugin-geolocation to see how they would achieve this.

<platform name="android">
    <config-file target="AndroidManifest.xml" parent="/*">
      <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
      <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
      <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
    </config-file>
</platform>

This returns the following in my build-phase

Error: Command failed: /bin/sh -c cordova build android
/Users/sven/.../cordova/platforms/android/build/intermediates/res/armv7/debug/xml/config.xml:34: error: Error parsing XML: unbound prefix

What my next step would be

I am unsure about why the 'rob-from-cordova-plugin-geolocation'-approach does not work, but maybe it would help to just put above into a new plugin? Is it worth a try?

Gundon
  • 2,081
  • 6
  • 28
  • 46

2 Answers2

1

Your error is "unbound prefix", have you provided a definition for the "android" prefix that you're using in "android:name"?

Looking at cordova-plugin-geolocation plugin.xml you may need to add this to your XML:

xmlns:android="http://schemas.android.com/apk/res/android"

So that the android namespace is defined.

Simon Prickett
  • 3,838
  • 1
  • 13
  • 26
0

You will be able to add permissions (and many other extra configuration actions) in Cordova straight from CLI's config.xml by adding the plugin cordova-custom-config to your environment. It will add nothing in your application and consists only in a group of Cordova hooks.

So, only add the XML chuck in your config.xml (<config-file...), and also add what @SimonPrickett say in his answer.

Javier Haro
  • 1,255
  • 9
  • 14