Cordova Plugin Variables

Configuring Cordova Plugin Variables Without config.xml

Cordova 129 has two kinds of settings, and Capacitor 243,123 treats them differently. Preferences are runtime values from config.xml that plugin code reads with preferences.getString(). Capacitor keeps them in the cordova block of its config file and writes them into the generated res/xml/config.xml. Install variables, like the notes app's cordova plugin add cordova-plugin-geolocation --variable GPS_REQUIRED=false, are substituted into the plugin's manifest entries at install time. Capacitor does not support them, and putting the value in cordova.preferences does not help:

capacitor.config.json: a preference is not an install variableJSON
{
  "appId": "com.example.booknest.legacy",
  "appName": "BookNest",
  "webDir": "www",
  "cordova": {
    "preferences": {
      "GPS_REQUIRED": "false"
    }
  }
}

After npx cap sync android, a grep of the plugin module's manifest and of config.xml showed the preference arriving, and the manifest using the plugin's default anyway:

Output of 73
<uses-feature android:name="android.hardware.location.gps" android:required="true"/>
18:  <preference name="GPS_REQUIRED" value="false" />

cap sync replaces each $VARIABLE with the plugin's default, so Google Play 1 would hide the app from devices without GPS. The fix is a tools:replace in the app's own manifest, which wins the manifest merge:

android/app/src/main/AndroidManifest.xml: overriding the plugin's defaultXML
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">
    ...
    <uses-feature android:name="android.hardware.location.gps" android:required="false"
        tools:replace="android:required" />
</manifest>

aapt2 dump badging on the Capacitor APK and on the old Cordova APK now agree: uses-feature-not-required: name='android.hardware.location.gps'. For every Cordova plugin you keep, read its plugin.xml (Reading plugin.xml) for <preference> elements and apply each non-default value by hand: in AndroidManifest.xml, strings.xml or variables.gradle on Android, and Info.plist on iOS.