CaioMelo8 commented on issue #1642:
URL: 
https://github.com/apache/cordova-android/issues/1642#issuecomment-1973002673

   Following @bkohler616's suggestion, for anyone interested, here's an rough 
draft script to remove `kotlin-android-extensions` from `build.gradle`:
   
   ```javascript
   #!/usr/bin/env node
   'use strict';
   
   const fs = require('fs');
   const path = require('path');
   
   const plugins = ['kotlin-android-extensions'];
   
   module.exports = function () {
     const file = path.join('platforms', 'android', 'app', 'build.gradle');
   
     if (fs.existsSync(file)) {
       let newFile = fs.readFileSync(file).toString();
   
       console.log('Removing lines from build.gradle... ');
   
       newFile = removeLines(newFile, plugins, applyPluginRegex);
   
       fs.writeFileSync(file, newFile);
     } else {
       throw `Couldn't find file: ${file}`;
     }
   };
   
   function removeLines(manifest, items, regex) {
     const lines = [];
   
     for (const item of items) {
       lines.push(...Array.from(manifest.matchAll(regex(item))));
     }
   
     if (lines.length > 0) {
       lines.sort((a, b) => b.index - a.index);
   
       for (const line of lines) {
         console.log(`Removing line from build.gradle: ${line[0].trim()}`);
   
         manifest = manifest.slice(0, line.index) + manifest.slice(line.index + 
line[0].length);
       }
     }
   
     return manifest;
   }
   
   function applyPluginRegex(plugin) {
     return new RegExp("\\s*?apply plugin: '" + plugin + "'.*?", 'gm');
   }
   ```
   
   You can add it as a `before_prepare` hook, but from what I've tested, adding 
it as an `after_platform_add` hook worked just fine.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@cordova.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.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