Android build error after migration from Capacitor 3 to Capacitor 4

We’ve followed the documentation here and migrated our Ionic/Angular app from Capacitor 3 to Capacitor 4.

We can successfully build the app for iOS and the Web but our Android builds are failing due to an issue with the cordova-plugin-badge plugin:

FAILURE: Build failed with an exception.
 * Where:
 Script '/Users/rks/Projects/myApp/node_modules/cordova-plugin-badge/src/android/badge.gradle' line: 28

 * What went wrong:
 A problem occurred evaluating script.
 > Could not find method compile() for arguments [me.leolin:ShortcutBadger:1.1.22@aar] on object of type

The badge plugin is not mentioned on the Capacitor Migration page in the sections that lists Plugins that require any code changes.

Has anyone else had this issue and managed to get round it and build successfully for Android?

The capacitor migration docs only include information about the Capacitor core plugins, your problem is not even on a Capacitor plugin, that’s a Cordova plugin.

The problem is that the plugin is unmaintained, last release was in 2018, since then a lot of things have changed in Android development and the way the plugin declares the dependency for me.leolin:ShortcutBadger has been deprecated for years and removed in Gradle 7, which is one of the things that were updated for Capacitor 4.

Note that the plugin will not work on cordova-android 11 neither, it’s not a Capacitor issue.

Looks like the plugin author updated the plugin to fix that problem, but for some reason they never published that change on npm, so you can install the plugin from the github url like npm install

1 Like

Thanks! Yeah I wasn’t even thinking this through properly. Of course it would not be mentioned as it’s a Cordova plugin!