Skip to content
This repository has been archived by the owner on Mar 1, 2022. It is now read-only.

Commit

Permalink
Merge pull request #85 from cabaird/feature/androidx_hook
Browse files Browse the repository at this point in the history
Adding hook to add androidx support in gradle.properties
  • Loading branch information
darryncampbell authored Nov 23, 2019
2 parents 567c0f8 + f41cfde commit ef58440
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
33 changes: 33 additions & 0 deletions hooks/after_prepare.js
Original file line number Diff line number Diff line change
@@ -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);
};
2 changes: 2 additions & 0 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<js-module name="IntentShim" src="www/IntentShim.js">
<clobbers target="intentShim" />
</js-module>

<hook type="after_prepare" src="hooks/after_prepare.js" />

<!-- android -->
<platform name="android">
Expand Down

0 comments on commit ef58440

Please sign in to comment.