cordova-plugin-badge
cordova-plugin-badge copied to clipboard
Getting a build error after migrating our Ionic app from Capacitor 3 to Capacitor 4
After migrating our Ionic project from Capacitor 3 to Capacitor 4 (see migration guide) we're getting a build error when building for Android:
* Where:
Script '/builds/rks/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 org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
Any ideas what we need to do?
In node_modules/cordova-plugin-badge/src/android/badge.gradle
you need to change line 28 from this:
compile "me.leolin:ShortcutBadger:${appShortcutBadgerVersion}@aar"
to this
implementation "me.leolin:ShortcutBadger:${appShortcutBadgerVersion}@aar"
For those using the cordova local notifications plugin, this should be patched in that plugin too.
import {readFileSync, writeFileSync} from 'fs';
// Issue: https://github.com/katzer/cordova-plugin-badge/issues/152#issuecomment-1238373550
const deprecated = 'compile "me.leolin:ShortcutBadger:${appShortcutBadgerVersion}@aar"';
const valid = 'implementation "me.leolin:ShortcutBadger:${appShortcutBadgerVersion}@aar"';
const files = [
'node_modules/cordova-plugin-badge/src/android/badge.gradle',
'node_modules/cordova-plugin-local-notification/src/android/build/localnotification.gradle',
];
files.forEach((file) => {
const gradle = readFileSync(file, 'utf-8');
writeFileSync(file, gradle.replace(deprecated, valid), 'utf-8');
});
The issue is caused by this plugin's use of a compile
dependency instead of implementation
dependency in its custom gradle configuration file - apparently this type of dependency goes haywire when using Gradle 7+.
Until the plugin is updated, here's the workaround fix that works without savagely updating sources in node_modules
. You don't want to do that every time you clear your node_modules
, right?
- In your
android/gradle.properties
:
appShortcutBadgerCustom=true
appShortcutBadgerVersion=1.1.22
- In your
android/app/build.gradle
file, add this line to the maindependencies {...}
section:
implementation "me.leolin:ShortcutBadger:$appShortcutBadgerVersion@aar"
@davidmarquis Thank you that worked. I just wanted to know how did you find out about that fix?
@shaifulborhan No problem, glad it could help you! I simply studied the sources, fiddled a bit and found the workaround!
@davidmarquis Thanks. you are greate
By the way, the issue about the compile
dependency has been fixed with the release 0.89