cordova-plugin-badge icon indicating copy to clipboard operation
cordova-plugin-badge copied to clipboard

Getting a build error after migrating our Ionic app from Capacitor 3 to Capacitor 4

Open richardkshergold opened this issue 2 years ago • 7 comments

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?

richardkshergold avatar Sep 06 '22 14:09 richardkshergold

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"

aodevil avatar Sep 06 '22 16:09 aodevil

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');
});

peterpeterparker avatar Oct 02 '22 08:10 peterpeterparker

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?

  1. In your android/gradle.properties:
appShortcutBadgerCustom=true
appShortcutBadgerVersion=1.1.22
  1. In your android/app/build.gradle file, add this line to the main dependencies {...} section:
implementation "me.leolin:ShortcutBadger:$appShortcutBadgerVersion@aar"

davidmarquis avatar Dec 02 '22 14:12 davidmarquis

@davidmarquis Thank you that worked. I just wanted to know how did you find out about that fix?

shaifulborhan avatar Mar 20 '23 14:03 shaifulborhan

@shaifulborhan No problem, glad it could help you! I simply studied the sources, fiddled a bit and found the workaround!

davidmarquis avatar Mar 20 '23 14:03 davidmarquis

@davidmarquis Thanks. you are greate

bdhwan avatar Apr 04 '23 09:04 bdhwan

By the way, the issue about the compile dependency has been fixed with the release 0.89

alexlopezit avatar Apr 28 '23 12:04 alexlopezit