1

I am trying to do what this question/answer has java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader but in cordova instead.

android {
    ....
    defaultConfig {
        ....
        ndk {
            abiFilters "armeabi", "armeabi-v7a", "x86", "mips"
        }
    }
}

This works if I edit build.gradle manually in platforms/android/build.gradle Using Cordova Android 6.4.0 (7.1 seems to break almost every plugin, including some cordova plugins such as cordova-network-information, so I've been unable to upgrade so far, and am looking for other solutions).

Editing manually isn't ideal, is there a way to set this automatically? Possibly with a hook or config.xml change?

Thanks

(edit) Updated to 7.1 successfully, 64 bit still broken.

Trevor
  • 2,792
  • 1
  • 30
  • 43

1 Answers1

3

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.

Trevor
  • 2,792
  • 1
  • 30
  • 43