cordova-android icon indicating copy to clipboard operation
cordova-android copied to clipboard

Support Optional Android Dependencies For Plugin controlled via command line inputs

Open root-ansh opened this issue 3 years ago • 1 comments

Feature Request

Support Optional Android Dependencies For Plugin controlled via command line inputs

Motivation Behind Feature

This will allow us to develop cordova plugins that depend on multiple optional libraries. in android we can develop 2 separate libraries a & b , where a can check whether the user has included b library, and if so, can change its working accordingly.

Feature Description

in cordova, if i have defined the following preference in my plugin.xml:

<preference name="FIREBASE_MESSAGING_VERSION" default="21.0.0"/>

then the users of my plugin can pass this variable while adding the plugin as :

cordova plugin add https://github.com/root-ansh/my-plugin --variable FIREBASE_MESSAGING_VERSION="20.4.0" 

furthermore, in my plugin.xml , i am able to use this version as :

<framework src="com.google.firebase:firebase-messaging:$FIREBASE_MESSAGING_VERSION" />

what we need is

  1. to restrict user to use versions above 21.0.0 (which i think will be covered in next point)
  2. to have 'optional' depenedencies . like if i take a boolean variable ADD_ANALYTICS_SDK as input during plugin installation, then i should be able to add an additional , optional framework, something like this :
<rule>
    <if>
        <conditions>
            <condition var="ADD_ANALYTICS_SDK" >$ADD_ANALYTICS_SDK</condition>
        </conditions>
        <statements>
            <framework src="com.google.firebase:firebase-analytics:21.0.0" />
        </statements>
    </if>
</rule>

is something like this possible for plugin.xml ?

root-ansh avatar May 17 '22 11:05 root-ansh

is something like this possible for plugin.xml ?

No, and it sounds like quite a task to implement so I don't foresee this becoming a feature anytime soon. Larger/advanced features tends to stall in a volunteer environment.

You might be able to get that pretty close by using Hooks.

Hooks allows you to script logic as part of Cordova's build process... It will however require you to read and manipulate config files manually which might be a difficult task to get it right without causing breakage. The plugin would also have to have uninstall hooks to make sure it cleans up what is has modified as well, as manipulations outside of Cordova tooling is obviously not tracked.

breautek avatar Nov 03 '25 17:11 breautek