GitHub user breautek added a comment to the discussion: Is it possible to add 
specific properties to gradle.properties file from config.xml?

There's nothing like `<edit-config>` or `<config-file>` (which only operates on 
XML files) for the gradle properties file.

But you can configure an `after_prepare` 
[hook](https://cordova.apache.org/docs/en/12.x/guide/appdev/hooks/index.html) 
to run a NodeJS script to manipulate the `gradle.properties`

The config would look something like:

```xml
<widget ...>
    ...
    <platform name="android">
        ...
        <hook type="after_prepare" src="scripts/configureJetifierIgnore.js" />
    </platform>
</widget>
```

And inside `scripts/configureJetifierIgnore.js`:

```js
const FS = require('fs');
const Path = require('path');

module.exports = function(context) {
    const propertiesPath = Path.resolve(process.cwd(), 
'platforms/android/gradle.properties');
    
    let properties = FS.readFileSync(propertiesPath, {
        encoding: 'utf-8'
    });

    // Replace any lines that begin with android.jetifier.ignoreList
    properties = properties.replace(/^android\.jetifier\.ignorelist.+/m, '');

    // Append a new ignoreList directive on a new line:
    properties += '\r\nandroid.jetifier.ignoreList = jackson-core';

    // Finally write the file back out
    FS.writeFileSync(propertiesPath, properties);
};
```

Notes:
1. Code is untested, I don't remember what the actual current working directory 
is in hooks, but I assume it's the project root directory, where you normally 
run your `cordova` commands. The example code might require tweaks to work 
properly.
2. `after_prepare` hook is the hook after cordova sets up the native project. 
By this time all files that cordova manipulates/updates should be written. So 
any manipulations done by the hook should persist for the build step which 
starts just after the `prepare` step.
3. I do not remember if `gradle.properties` is one of the files that is 
consistently wiped, so you may have to check if `android.jetifier.ignoreList` 
key already exist in properties and either remove it (like the script does) or 
parse to update it.
4. The context object isn't well documented. What it contains will vary on hook 
type, platform, and CLI options passed. You can console.log it to see if there 
are anything that is helpful.



GitHub link: 
https://github.com/apache/cordova/discussions/482#discussioncomment-9828421

----
This is an automatically sent email for issues@cordova.apache.org.
To unsubscribe, please send an email to: issues-unsubscr...@cordova.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@cordova.apache.org
For additional commands, e-mail: issues-h...@cordova.apache.org

Reply via email to