Firebase Cloud Messaging: "Didn't find class com.google.android.gms.gcm.GcmReceiver" error


#1

I’m attempting to use the nativescript push plugin on Android with NativeScript 2.5 to send push notifications to a device. I believe I’ve followed the plugin setup instructions, and my app successfully calls pushPlugin.register and receives a token on startup. However, when I actually send a message from the Firebase console to this device (with the token), the app on the device throws a Java error:

java.lang.RuntimeException: unable to instantiate received
    com.google.android.gms.gcm.GcmReceiver:
java.lang.ClassNotFoundException: Didn't find class 
    "com.google.android.gms.gcm.GcmReceiver"
    on path: DexPathList[[zip file "/data/app/<myappid>-1/base.apk"],
    nativeLibraryDirectories=
    [/data/app/<myappid>-1/lib/x86,/data/app/<myappid>-1/base.apk!lib/x86,
    /vendor/lib,/system/lib]]
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2706)
at (snip lots more traceback)

I imagine that I’ve just failed to enable the GCM/FCM classes somewhere, but I’m not sure where. I’ve followed the plugin instructions, but they’re a bit misleading: they say

“Ensure that the AndroidManifest.xml located at platforms\android contains (various snippets)…”

There is no AndroidManifest.xml in platforms/android. There is one at platforms/android/src/main/AndroidManifest.xml and so I put the snippets in there, but maybe that was wrong.

Add the FCM SDK to … to the application-level build.gradle file in the project platforms/android/ folder

It’s possible – maybe probable – that I don’t need to do this since the documentation explicitly says that I can skip this step for 0.1.1 (which I’m using). But I have verified that this line is in platforms/android/build.gradle:

import groovy.json.JsonSlurper //used to parse package.json
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath "com.google.gms:google-services:+"
        classpath "com.android.tools.build:gradle:2.1.2"
        classpath "com.google.gms:google-services:3.0.0"
    }
}

I added the 3.0.0 line. That may be causing the problem because the + line was auto-added by the plugin? But if I remove that 3.0.0 line then I never receive any onMessageReceived callback at all, whether the app is in foreground or background.

I also have apply plugin: "com.google.gms.google-services" at the bottom of that same platforms/android/build.gradle file: I do not know if that is “your app’s build.gradle file” as referred to by the plugin documentation.

I’m not sure what I might be doing wrong here, and any pointers would be gratefully accepted.


#2

OK, scratch all the above. It seems to be working now; I just forced a rebuild and edited the AndroidManifest.xml in app/App_Resources/android and now I’m receiving messages. So maybe something just wasn’t in there correctly!