cordova-plugin-gradle-config-modifier
v1.0.0
Published
Cordova plugin to manipulate Android cdv-gradle-config.json safely
Maintainers
Readme
Cordova Plugin Gradle Config Modifier
This plugin allows you to dynamically modify the values inside the cdv-gradle-config.json file on the Android platform via the Cordova Command-Line Interface (CLI). It is highly useful for centrally managing SDK versions, Kotlin versions, or other Gradle configurations.
Key Features
- Modifies Android Gradle build configurations using
--variableflags. - Non-destructive by default: If you do not specify any variables during installation, your existing configurations remain completely untouched.
- Automatically parses data types (converting CLI strings into JSON-compliant
number,boolean, ornullvalues). - Includes an internal blocklist to protect crucial built-in Cordova variables.
Installation
Safe Installation (No Overwrites)
Installing the plugin without any variables will securely preserve your existing cdv-gradle-config.json settings.
cordova plugin add cordova-plugin-gradle-config-modifierInstallation with Variable Overrides
Use the --variable flag to specifically target and overwrite configurations during installation:
cordova plugin add cordova-plugin-gradle-config-modifier \
--variable KOTLIN_VERSION=2.1.21 \
--variable MIN_SDK_VERSION=24 \
--variable IS_GRADLE_PLUGIN_KOTLIN_ENABLED=trueSupported Variables
By default, all variables are set to a PRESERVE state, meaning they will not modify your project unless explicitly declared in the CLI. Below is the list of supported variables alongside standard Cordova default examples:
| Variable Name | Example Value |
| :--- | :--- |
| MIN_SDK_VERSION | 24 |
| SDK_VERSION | 36 |
| COMPILE_SDK_VERSION | null |
| GRADLE_VERSION | 8.13 |
| MIN_BUILD_TOOLS_VERSION | 35.0.0 |
| AGP_VERSION | 8.7.3 |
| KOTLIN_VERSION | 2.1.21 |
| ANDROIDX_APP_COMPAT_VERSION | 1.7.0 |
| ANDROIDX_WEBKIT_VERSION | 1.12.1 |
| ANDROIDX_CORE_SPLASHSCREEN_VERSION | 1.0.1 |
| GRADLE_PLUGIN_GOOGLE_SERVICES_VERSION | 4.4.2 |
| IS_GRADLE_PLUGIN_GOOGLE_SERVICES_ENABLED | false |
| IS_GRADLE_PLUGIN_KOTLIN_ENABLED | true |
| JAVA_SOURCE_COMPATIBILITY | 11 |
| JAVA_TARGET_COMPATIBILITY | 11 |
| KOTLIN_JVM_TARGET | null |
System Exception: The
PACKAGE_NAMESPACEvariable is internally blocked and cannot be modified through this plugin. This is to prevent build conflicts, as Cordova automatically manages this namespace based on the appiddefined in yourconfig.xmlfile.
How It Works
This plugin registers a hook during the after_prepare lifecycle. When you run cordova prepare android or cordova build android, the script runs in the background, reads your preference configurations from android.json, and safely overwrites the targeted properties in platforms/android/cdv-gradle-config.json before the compilation process begins. Any variables you did not explicitly set will be ignored, leaving your original project configurations intact.
Uninstallation
To remove the plugin from your project:
cordova plugin rm cordova-plugin-gradle-config-modifier