Register device for push notifications configuration error (Flutter SDK)?

Mission: PUSH COMMANDER
Task: Register device for push notifications

Have followed the video and checked and rechecked the “Push Notification Setup (Android)” (Flutter SDK) several times

4:45 in video, re AndroidManifest.xml line:

  1. “com.backendless.push.BackendlessFCMService” appears in red, with error “Class referenced in the manifest, com.backendless.push.BackendlessFCMService, was not found in the project or the libraries”
    App ‘build.gradle dependencies’ entry look correct to me:
    implementation group: ‘com.backendless’, name: ‘backendless’, version: ‘6.3.3’
    (6.3.3 is current version, have also tried video version: 5.7.0).
    Earlier versions of Android Studio had a ‘synch gradle’ message when the gradle files changed, but don’t see that in this later version (4.1.3).

  2. (keyword) ’service’ shows warning “Exported service does not require permission”

What am I missing?

Hello @Jim_Austin,

I’ve created an internal ticket BKNDLSS-27403. Our Flutter dev will investigate this issue as soon as possible.

Regards,
Olha

Hello, @Jim_Austin.

I have just created a clean project to register a device for push notifications.
Here are my steps for a successful setup:
Add google.services.json file to android/app.
Add proguard-rules.pro file to android/app with the following content:

-dontwarn com.backendless. **
-dontwarn weborb. **
-keep class weborb. ** {*;}
-keep class com.backendless. ** {*;}

Changes in app/build.gradle:
Add line:
apply plugin: 'com.google.gms.google-services'
Set value:
minSdkVersion 19

Change the content of buildTypes, to connect proguard:

buildTypes {
    release {
        // TODO: Add your own signing config for the release build.
        // Signing with the debug keys for now, so `flutter run --release` works.
        minifyEnabled true

        proguardFiles getDefaultProguardFile ('proguard-android.txt'), 'proguard-rules.pro'
        signingConfig signingConfigs.debug
    }

add dependencies:

    implementation platform ('com.google.firebase: firebase-bom: 29.0.0')
    implementation 'com.google.firebase: firebase-core: 20.0.0'
    implementation 'com.google.firebase: firebase-messaging: 23.0.0'
    implementation 'com.google.firebase: firebase-iid'

Changes in android/build.gradle:
classpath 'com.google.gms: google-services: 4.3.10'

Finally, changes in android/app/src/main/AndroidManifest.xml:
Add:

<service android: name = "com.backendless.backendless_sdk.common.FlutterBackendlessFCMService"
    android: exported = "true">
    <intent-filter>
        <action android: name = "com.google.firebase.MESSAGING_EVENT" />
    </intent-filter>
</service>

Hope this solves your problem, Best regards, Nikita.

Nikita,
Printed instructions and marked them off going down the list. Most lines were already there; built the file‘proguard-rules.pro’ in Notepad, copied the text from your post into it, and put it into ‘android/app’ (is right under ‘google.services.json’).
Other differences:

  • minSdkVersion was at 21
  • implementation ‘com.google.firebase: firebase-iid’ is new
  • left the line from the original video: implementation group: ‘com.backendless’, name: ‘backendless’, version: ‘6.3.3’

New ‘service’ section addition to AndroidManifest.xml caused several new errors; seems .xml didn’t like the space after the ‘:’ (colon). Removed that and errors same as before:

  • ‘com.backendless.backendless_sdk.common.FlutterBackendlessFCMService’ is still red, showing error “Class referenced in the manifest, com.backendless.backendless_sdk.common.FlutterBackendlessFCMService, was not found in the project or the libraries”
  • android:exported shows error “Unknown attribute android:exported”
    I note the ‘service’ keyword shows warning(?) “Exported service does not require permission”; setting android:exported = “false”> removes that warning.

Perhaps a next step is to try to run the correct Flutter API call code for the “Register device for push notifications” task (BKNDLSS-27399); is that in the works somewhere?
Jim

Hello, @Jim_Austin.
Here’s an example from my test project(For correct API device registration):

  Future<dynamic> registerForPushNotifications() async {
    List<String> channels = [];
    channels.add("default");

    try {
      return await Backendless.messaging.registerDevice(channels, null, onMessage);
    } catch (ex) {
      return ex;
    }
  }

  void onMessage(Map<String, dynamic> message) async {
    PushNotificationMessage notification = PushNotificationMessage();

    if (io.Platform.isIOS) {
      Map pushData = message['aps']['alert'];
      notification.title = pushData['title'];
      notification.body = pushData['body'];
    } else if (io.Platform.isAndroid) {
      notification.title = message['android-content-title'];
      notification.body = message['message'];
    }

    showOverlayNotification((context) {
      return MessageNotification(
        title: notification.title,
        body: notification.body,
      );
    });
  }

class PushNotificationMessage {
  String? title;
  String? body;
}

class MessageNotification extends StatelessWidget {
  const MessageNotification({Key? key, this.title, this.body})
      : super(key: key);

  final title;
  final body;

  @override
  Widget build(BuildContext context) {
    return Card(
        //construct notification
        );
  }
}

Best Regards, Nikita.

Nikita,
Getting error ‘The method ‘showOverlayNotification’ isn’t defined’ on the ‘showOverlayNotification’ call. Where can I find it?

If I comment that call out, have a problem with the app/build.gradle dependency
implementation ‘com.google.firebase: firebase-iid’
Gives compile-time error:
Execution failed for task ‘:app:checkDebugAarMetadata’.

Could not resolve all files for configuration ‘:app:debugRuntimeClasspath’.
Could not find com.google.firebase: firebase-iid:.
Required by: project :app

If I comment out that line out of ‘dependencies’, get runtime error:
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/firebase/iid/FirebaseInstanceId;

For reference, here’s the complete ‘dependencies’ section of app/build.gradle:
dependencies {
implementation “org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version”
implementation platform(‘com.google.firebase:firebase-bom:29.0.3’)
implementation ‘com.google.firebase:firebase-analytics’
implementation ‘com.google.firebase:firebase-core:20.0.2’
implementation ‘com.google.firebase:firebase-messaging:23.0.0’
implementation ‘com.google.firebase: firebase-iid’
implementation group: ‘com.backendless’, name: ‘backendless’, version: ‘6.3.3’
// implementation group: ‘com.backendless’, name: ‘backendless’, version: ‘5.7.0’

implementation('io.socket:socket.io-client:1.0.0') {
    exclude group: 'org.json', module: 'json'
}

}

Jim

Hello again, @Jim_Austin!

The method showOverlayNotification is defined in overlay_support: ^1.2.1 package. But this is just my way of displaying notifications. You can use your own approach.

If you are using flutter you do not need to do:
implementation group: ‘com.backendless’, name: ‘backendless’, version: ‘6.3.3’
All of this is included in the backendless_sdk: ^ 7.1.8 which you add in the dependencies in your pubspec.yaml file.
You may receive this error Could not find com.google.firebase: firebase-iid for 2 reasons:

  1. You forgot to add the line: classpath 'com.google.gms:google-services:4.3.10'
    in android/build.gradle file. Like this:
buildscript {
    ext.kotlin_version = '1.5.21'
    repositories {
        google()
        jcenter()
    }

    dependencies {
        //some dependencies
        classpath 'com.google.gms:google-services:4.3.10'
    }
}
  1. You have some data cached and you need to do the following:
flutter clean
flutter pub get

if this does not help, try clicking on the “File” tab in the upper left corner, and clicking on the line: Invalidate Caches / Restart.

Best Regards, Nikita.

Nikita,
Once again your work led to the fix: for whatever reason the system was not able to resolve com.google.firebase: firebase-iid without an explicit version number. Eventually found the latest version (implementation “com.google.firebase:firebase-iid:21.1.0”) and that compiled.

The AndroidManifest.xml service element line
android:name = “com.backendless.backendless_sdk.common.FlutterBackendlessFCMService”
is still red and shows the error “Class referenced in the manifest, com.backendless.backendless_sdk.common.FlutterBackendlessFCMService, was not found in the project or the libraries”.
But … your ‘register device’ code ran successfully, completing this task!!

Another weird one … thanks again for all your help!
Jim

1 Like

I’m glad I was able to help :slight_smile:

Not sure what will help, but if you open an android folder through Android Studio, and after build.gradle, then it will not be underlined in red.
But then you won’t be able to edit your dart files and you will only see the android folder.
Apparently, Android Studio is not doing so well with flutter and java code synchronization.

P.S. I was getting an error with explicit version of com.google.firebase:firebase-iid.
magic… :mage: