Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
richardkshergold opened this issue Sep 6, 2022 · 7 comments

Comments

@richardkshergold
Copy link

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?

@aodevil
Copy link

aodevil commented Sep 6, 2022

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"

@peterpeterparker
Copy link

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

@davidmarquis
Copy link

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"

@shaifulborhan
Copy link

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

@davidmarquis
Copy link

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

@bdhwan
Copy link

bdhwan commented Apr 4, 2023

@davidmarquis Thanks. you are greate

@alexlopezit
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants