From f41cfded7acc494ff78d2159dbdef169746b210a Mon Sep 17 00:00:00 2001 From: Christian Baird Date: Fri, 22 Nov 2019 18:41:07 -0500 Subject: [PATCH] Adding hook to add androidx support in gradle.properties --- hooks/after_prepare.js | 33 +++++++++++++++++++++++++++++++++ plugin.xml | 2 ++ 2 files changed, 35 insertions(+) create mode 100644 hooks/after_prepare.js diff --git a/hooks/after_prepare.js b/hooks/after_prepare.js new file mode 100644 index 0000000..530cca2 --- /dev/null +++ b/hooks/after_prepare.js @@ -0,0 +1,33 @@ +const fs = require("fs"); + +function androidXUpgrade (ctx) { + if (!ctx.opts.platforms.includes('android')) + return; + + const enableAndroidX = "android.useAndroidX=true"; + const enableJetifier = "android.enableJetifier=true"; + const gradlePropertiesPath = "./platforms/android/gradle.properties"; + + let gradleProperties = fs.readFileSync(gradlePropertiesPath, "utf8"); + + if (gradleProperties) + { + const isAndroidXEnabled = gradleProperties.includes(enableAndroidX); + const isJetifierEnabled = gradleProperties.includes(enableJetifier); + + if (isAndroidXEnabled && isJetifierEnabled) + return; + + if (isAndroidXEnabled === false) + gradleProperties += "\n" + enableAndroidX; + + if (isJetifierEnabled === false) + gradleProperties += "\n" + enableJetifier; + + fs.writeFileSync(gradlePropertiesPath, gradleProperties); + } +} + +module.exports = function (ctx) { + androidXUpgrade(ctx); +}; diff --git a/plugin.xml b/plugin.xml index 9e95391..3d826e7 100644 --- a/plugin.xml +++ b/plugin.xml @@ -4,6 +4,8 @@ + +