I was able to do this using the build-extras option, combined with Android 7.1
In your project root, create a file called build-extras.gradle
Put this inside it and save
android {
defaultConfig {
ndk {
abiFilters "armeabi", "armeabi-v7a", "x86", "mips"
}
}
}
Next, in your scripts folder, make a new script called update_build_gradle.js
Put this inside it and save
module.exports = function (context) {
if (context.opts.cordova.platforms.indexOf('android') < 0) {
return;
}
console.log("Starting gradle modifications");
const path = require('path');
const fs = require('fs');
const gradlePath = path.join(context.opts.projectRoot, 'platforms/android/app/build-extras.gradle');
const gradleExtraPath = path.join(context.opts.projectRoot, 'build-extras.gradle');
return new Promise(function (resolve, reject) {
fs.copyFile(gradleExtraPath, gradlePath, function (err) {
if (err) {
console.error("Failed to copy to " + gradlePath + " from " + gradleExtraPath);
reject(err);
} else {
console.log("Copied to " + gradlePath + " successfully");
resolve();
}
});
});
};
Lastly, open up your config.xml, find your <platform name="android">
tree and enter this new hook
<hook src="scripts/update_build_gradle.js" type="before_build" />
Note that the documentation here https://cordova.apache.org/docs/en/latest/guide/platforms/android/index.html#extending-buildgradle is wrong.
. This file must be placed in the android platform directory (/platforms/android), so it is recommended that you copy it over via a script attached to the before_build hook.
It actually needs to be in /platforms/android/app
-Edit
As of cordova version 9, you can't use requireCordovaModule
anymore. But you can safely replace with just require
.