I added the lib awesome_notifications_fcm and when compiling if for android getting this error, havent even implemented yet.
Duplicate class me.carda.awesome_notifications.core.utils.BooleanUtils found in modules jetified-AndroidAwnCore-0.7.5-dev.3-runtime (me.carda:AndroidAwnCore:0.7.5-dev.3) and jetified-androidcore-0.7.7-runtime (me.carda:androidcore:0.7.7)
Duplicate class me.carda.awesome_notifications.core.utils.CalendarUtils found in modules jetified-AndroidAwnCore-0.7.5-dev.3-runtime (me.carda:AndroidAwnCore:0.7.5-dev.3) and jetified-androidcore-0.7.7-runtime (me.carda:androidcore:0.7.7)
Duplicate class me.carda.awesome_notifications.core.utils.CompareUtils found in modules jetified-AndroidAwnCore-0.7.5-dev.3-runtime (me.carda:AndroidAwnCore:0.7.5-dev.3) and jetified-androidcore-0.7.7-runtime (me.carda:androidcore:0.7.7)
Duplicate class me.carda.awesome_notifications.core.utils.CronUtils found in modules jetified-AndroidAwnCore-0.7.5-dev.3-runtime (me.carda:AndroidAwnCore:0.7.5-dev.3) and jetified-androidcore-0.7.7-runtime (me.carda:androidcore:0.7.7)
Duplicate class me.carda.awesome_notifications.core.utils.EnumUtils found in modules jetified-AndroidAwnCore-0.7.5-dev.3-runtime (me.carda:AndroidAwnCore:0.7.5-dev.3) and jetified-androidcore-0.7.7-runtime (me.carda:androidcore:0.7.7)
Duplicate class me.carda.awesome_notifications.core.utils.HtmlUtils found in modules jetified-AndroidAwnCore-0.7.5-dev.3-runtime (me.carda:AndroidAwnCore:0.7.5-dev.3) and jetified-androidcore-0.7.7-runtime (me.carda:androidcore:0.7.7)
Duplicate class me.carda.awesome_notifications.core.utils.IntegerUtils found in modules jetified-AndroidAwnCore-0.7.5-dev.3-runtime (me.carda:AndroidAwnCore:0.7.5-dev.3) and jetified-androidcore-0.7.7-runtime (me.carda:androidcore:0.7.7)
Duplicate class me.carda.awesome_notifications.core.utils.JsonUtils found in modules jetified-AndroidAwnCore-0.7.5-dev.3-runtime (me.carda:AndroidAwnCore:0.7.5-dev.3) and jetified-androidcore-0.7.7-runtime (me.carda:androidcore:0.7.7)
Duplicate class me.carda.awesome_notifications.core.utils.JsonUtils$1 found in modules jetified-AndroidAwnCore-0.7.5-dev.3-runtime (me.carda:AndroidAwnCore:0.7.5-dev.3) and jetified-androidcore-0.7.7-runtime (me.carda:androidcore:0.7.7)
Duplicate class me.carda.awesome_notifications.core.utils.ListUtils found in modules jetified-AndroidAwnCore-0.7.5-dev.3-runtime (me.carda:AndroidAwnCore:0.7.5-dev.3) and jetified-androidcore-0.7.7-runtime (me.carda:androidcore:0.7.7)
Duplicate class me.carda.awesome_notifications.core.utils.MapUtils found in modules jetified-AndroidAwnCore-0.7.5-dev.3-runtime (me.carda:AndroidAwnCore:0.7.5-dev.3) and jetified-androidcore-0.7.7-runtime (me.carda:androidcore:0.7.7)
Duplicate class me.carda.awesome_notifications.core.utils.MediaUtils found in modules jetified-AndroidAwnCore-0.7.5-dev.3-runtime (me.carda:AndroidAwnCore:0.7.5-dev.3) and jetified-androidcore-0.7.7-runtime (me.carda:androidcore:0.7.7)
Duplicate class me.carda.awesome_notifications.core.utils.SerializableUtils found in modules jetified-AndroidAwnCore-0.7.5-dev.3-runtime (me.carda:AndroidAwnCore:0.7.5-dev.3) and jetified-androidcore-0.7.7-runtime (me.carda:androidcore:0.7.7)
Duplicate class me.carda.awesome_notifications.core.utils.StringUtils found in modules jetified-AndroidAwnCore-0.7.5-dev.3-runtime (me.carda:AndroidAwnCore:0.7.5-dev.3) and jetified-androidcore-0.7.7-runtime (me.carda:androidcore:0.7.7)
Duplicate class me.carda.awesome_notifications.core.utils.ThreadUtils found in modules jetified-AndroidAwnCore-0.7.5-dev.3-runtime (me.carda:AndroidAwnCore:0.7.5-dev.3) and jetified-androidcore-0.7.7-runtime (me.carda:androidcore:0.7.7)
Duplicate class me.carda.awesome_notifications.core.utils.TimeZoneUtils found in modules jetified-AndroidAwnCore-0.7.5-dev.3-runtime (me.carda:AndroidAwnCore:0.7.5-dev.3) and jetified-androidcore-0.7.7-runtime (me.carda:androidcore:0.7.7)
Go to the documentation to learn how to <a href="d.android.com/r/tools/classpath-sync-errors">Fix dependency resolution errors</a>.
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BU�LD FAILED in 55s
Exception: Gradle task assembleDebug failed with exit code 1
Exited (sigterm)
android/build.gradle
buildscript {
ext.kotlin_version = '1.6.10'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.google.gms:google-services:4.3.10'
classpath 'com.android.tools.build:gradle:7.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
android/app/build.gradle
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new FileNotFoundException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 33 // flutter.compileSdkVersion
ndkVersion flutter.ndkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "app.fely.staff"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
minSdkVersion 21//flutter.minSdkVersion
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.multidex:multidex:2.0.1'
}
gradle.properties
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
pubspec.yaml
name: fely_staff
description: fely staff mobile app
# The following line prevents the package from being accidentally published to
# pub.dev using `flutter pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.7.1+1
environment:
sdk: ">=2.17.0 <3.0.0"
# Dependencies specify other packages that your package needs in order to work.
# To automatically upgrade your package dependencies to the latest versions
# consider running `flutter pub upgrade --major-versions`. Alternatively,
# dependencies can be manually updated by changing the version numbers below to
# the latest version available on pub.dev. To see which dependencies have newer
# versions available, run `flutter pub outdated`.
dependencies:
flutter:
sdk: flutter
get: ^4.6.1
get_storage: ^2.0.3
vexana: ^3.4.3
flutter_barcode_scanner: ^2.0.0
build_runner: ^2.1.7
analyzer: ^5.13.0
json_annotation: ^4.4.0
json_serializable: ^6.1.3
intl: ^0.18.1
auto_size_text: ^3.0.0
encrypt: ^5.0.1
firebase_core: ^2.15.1
awesome_notifications_fcm: ^0.7.4+1
awesome_notifications: ^0.7.4+1
http: ^1.1.0
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
dev_dependencies:
flutter_test:
sdk: flutter
# The "flutter_lints" package below contains a set of recommended lints to
# encourage good coding practices. The lint set provided by the package is
# activated in the `analysis_options.yaml` file located at the root of your
# package. See that file for information about deactivating specific lint
# rules and activating additional ones.
flutter_lints: ^2.0.0
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter packages.
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
# To add assets to your application, add an assets section, like this:
assets:
- assets/
- assets/images/
# - assets/svgs/
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware
# For details regarding adding assets from package dependencies, see
# https://flutter.dev/assets-and-images/#from-packages
# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
fonts:
- family: Rubik
fonts:
- asset: fonts/Rubik-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.dev/custom-fonts/#from-packages
and i got this error when i implement the awesome_notifications_fcm codes inside to my project.
Launching lib\main.dart on sdk gphone x86 64 in debug mode...
main.dart:1
Building with Flutter multidex support enabled.
: Error: Too many positional arguments: 2 allowed, but 3 found.
fcm_silent_data.dart:32
Try removing the extra positional arguments.
_createdDate = AwesomeAssertUtils.extractValue(
^
: Context: Found this candidate, but the arguments don't match.
assert_utils.dart:55
static extractValue<T>(String reference, Map dataMap) {
^^^^^^^^^^^^
Target kernel_snapshot failed: Exception
FAILURE: Build failed with an exception.
* Where:
Script 'C:\src\flutter\packages\flutter_tools\gradle\src\main\groovy\flutter.groovy' line: 1297
* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'C:\src\flutter\bin\flutter.bat'' finished with non-zero exit value 1
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BU�LD FAILED in 23s
Exception: Gradle task assembleDebug failed with exit code 1
Exited (sigterm)
awesome_notifications_fcm codes
import 'package:awesome_notifications/awesome_notifications.dart';
import 'package:awesome_notifications_fcm/awesome_notifications_fcm.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:http/http.dart' as http;
class NotificationController extends GetxController {
static NotificationController get instance => Get.find();
Rx<String> firebaseToken = ''.obs;
Rx<String> nativeToken = ''.obs;
ReceivedAction? initialAction;
//! *********************************************
//! INITIALIZATION METHODS
//! *********************************************
static Future<void> initializeLocalNotifications({required bool debug}) async {
await AwesomeNotifications().initialize(
null, //'resource://drawable/res_app_icon',//
[
NotificationChannel(
channelKey: 'alerts',
channelName: 'Alerts',
channelDescription: 'Notification tests as alerts',
playSound: true,
importance: NotificationImportance.High,
defaultPrivacy: NotificationPrivacy.Private,
defaultColor: Colors.deepPurple,
ledColor: Colors.deepPurple),
],debug: debug
);
instance.initialAction = await AwesomeNotifications()
.getInitialNotificationAction(removeFromActionEvents: false);
}
static Future<void> initializeRemoteNotifications({required bool debug}) async {
await Firebase.initializeApp();
await AwesomeNotificationsFcm().initialize(
onFcmSilentDataHandle: NotificationController.mySilentDataHandle,
onFcmTokenHandle: NotificationController.myFcmTokenHandle,
onNativeTokenHandle: NotificationController.myNativeTokenHandle,
licenseKeys: [
// me.carda.awesomeNotificationsFcmExample
'B3J3yxQbzzyz0KmkQR6rDlWB5N68sTWTEMV7k9HcPBroUh4RZ/Og2Fv6Wc/lE',
'2YaKuVY4FUERlDaSN4WJ0lMiiVoYIRtrwJBX6/fpPCbGNkSGuhrx0Rekk',
'+yUTQU3C3WCVf2D534rNF3OnYKUjshNgQN8do0KAihTK7n83eUD60=',
// me.carda.awesome_notifications_fcm_example
'UzRlt+SJ7XyVgmD1WV+7dDMaRitmKCKOivKaVsNkfAQfQfechRveuKblFnCp4',
'zifTPgRUGdFmJDiw1R/rfEtTIlZCBgK3Wa8MzUV4dypZZc5wQIIVsiqi0Zhaq',
'YtTevjLl3/wKvK8fWaEmUxdOJfFihY8FnlrSA48FW94XWIcFY=',
], debug: debug
);
}
//! *********************************************
//! REMOTE NOTIFICATION EVENTS
//! *********************************************
//* Use this method to execute on background when a silent data arrives (even while terminated)
@pragma("vm:entry-point")
static Future<void> mySilentDataHandle(FcmSilentData silentData) async {
Get.showSnackbar(
const GetSnackBar(
messageText: Text(
"Slient data received",
style: TextStyle(color: Colors.white, fontSize: 16),
),
backgroundColor: Colors.black,
),
);
debugPrint('"SilentData": ${silentData.toString()}');
if (silentData.createdLifeCycle != NotificationLifeCycle.Foreground) {
debugPrint("bg");
} else {
debugPrint("FOREGROUND");
}
debugPrint("mySilentDatahandle received a FcmSilentData execution");
await executeLongTaskInBackground();
}
//* Use this method to detect when a new fcm token is received
@pragma("vm:entry-point")
static Future<void> myFcmTokenHandle(String token) async {
Get.showSnackbar(
const GetSnackBar(
messageText: Text(
"Fcm token received",
style: TextStyle(color: Colors.white, fontSize: 16),
),
backgroundColor: Colors.black,
),
);
debugPrint('Firebase Token:"$token"');
instance.firebaseToken.value = token;
}
//* Use this method to detect when a new native token is received
@pragma("vm:entry-point")
static Future<void> myNativeTokenHandle(String token) async {
Get.showSnackbar(
const GetSnackBar(
messageText: Text(
"Native token received",
style: TextStyle(color: Colors.white, fontSize: 16),
),
backgroundColor: Colors.black,
),
);
debugPrint('Native Token:"$token"');
instance.nativeToken.value = token;
}
//! *********************************************
//! BACKGROUND TASKS TEST
//! *********************************************
static Future<void> executeLongTaskInBackground() async {
debugPrint("starting long task");
await Future.delayed(const Duration(seconds: 4));
final url = Uri.parse("http://google.com");
final re = await http.get(url);
debugPrint(re.body);
debugPrint("long task done");
}
//! *********************************************
//! REQUEST NOTIFICATION PERMISSIONS
//! *********************************************
static Future<bool> displayNotificationRationale() async {
bool userAuthorized = false;
BuildContext context = Get.context!;
await showDialog(
context: context,
builder: (BuildContext ctx) {
return AlertDialog(
title: Text('Get Notified!',
style: Theme.of(context).textTheme.titleLarge),
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
Row(
children: [
Expanded(
child: Image.asset(
'assets/animated-bell.gif',
height: MediaQuery.of(context).size.height * 0.3,
fit: BoxFit.fitWidth,
),
),
],
),
const SizedBox(height: 20),
const Text(
'Allow Awesome Notifications to send you beautiful notifications!'),
],
),
actions: [
TextButton(
onPressed: () {
Navigator.of(ctx).pop();
},
child: Text(
'Deny',
style: Theme.of(context)
.textTheme
.titleLarge
?.copyWith(color: Colors.red),
)),
TextButton(
onPressed: () async {
userAuthorized = true;
Navigator.of(ctx).pop();
},
child: Text(
'Allow',
style: Theme.of(context)
.textTheme
.titleLarge
?.copyWith(color: Colors.deepPurple),
)),
],
);
});
return userAuthorized &&
await AwesomeNotifications().requestPermissionToSendNotifications();
}
// //! *********************************************
// //! LOCAL NOTIFICATION CREATION METHODS
// //! *********************************************
static Future<void> createNewNotification() async {
bool isAllowed = await AwesomeNotifications().isNotificationAllowed();
if (!isAllowed) {
isAllowed = await displayNotificationRationale();
}
if (!isAllowed) return;
await AwesomeNotifications().createNotification(
content: NotificationContent(
id: -1, // -1 is replaced by a random number
channelKey: 'channel_key',
title: 'Huston! The eagle has landed!',
body:
"A small step for a man, but a giant leap to Flutter's community!",
bigPicture: 'https://storage.googleapis.com/cms-storage-bucket/d406c736e7c4c57f5f61.png',
largeIcon: 'https://storage.googleapis.com/cms-storage-bucket/0dbfcc7a59cd1cf16282.png',
notificationLayout: NotificationLayout.BigPicture,
payload: {'notificationId': '1234567890'}),
actionButtons: [
NotificationActionButton(key: 'REDIRECT', label: 'Redirect'),
NotificationActionButton(
key: 'REPLY',
label: 'Reply Message',
requireInputText: true,
actionType: ActionType.SilentAction),
NotificationActionButton(
key: 'DISMISS',
label: 'Dismiss',
actionType: ActionType.DismissAction,
isDangerousOption: true)
]);
}
static Future<void> resetBadge() async {
await AwesomeNotifications().resetGlobalBadge();
}
//! *********************************************
//! REMOTE TOKEN REQUESTS
//! *********************************************
static Future<String> requestFirebaseToken() async {
if (await AwesomeNotificationsFcm().isFirebaseAvailable) {
try {
return await AwesomeNotificationsFcm().requestFirebaseAppToken();
} catch (exception) {
debugPrint('$exception');
}
} else {
debugPrint('Firebase is not available on this project');
}
return '';
}
}