NativeScript / push-plugin

Contains the source code for the Push Plugin.
Apache License 2.0
123 stars 45 forks source link

Unable to instantiate receiver com.google.android.gms.gcm.GcmReceiver #105

Open ignaciolarranaga opened 7 years ago

ignaciolarranaga commented 7 years ago

I'm receiving this exception when receive a push notification. This is from the emulator (API 23) but the app also experience the same on a device:

02-18 06:02:02.045: W/ContentTaskController(2015): Invalid newTask was provided to startTracking.
02-18 06:02:05.708: W/GAv4(4324): syncDispatchLocalHits timed out: java.util.concurrent.TimeoutException
02-18 06:02:05.708: W/System.err(4324): java.lang.RuntimeException: Unable to instantiate receiver 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/com.hezea.ForSaleByOwner-1/base.apk"],nativeLibraryDirectories=[/data/app/com.hezea.ForSaleByOwner-1/lib/x86, /data/app/com.hezea.ForSaleByOwner-1/base.apk!/lib/x86, /vendor/lib, /system/lib]]
02-18 06:02:05.708: W/System.err(4324):     at android.app.ActivityThread.handleReceiver(ActivityThread.java:2706)
02-18 06:02:05.708: W/System.err(4324):     at android.app.ActivityThread.-wrap14(ActivityThread.java)
02-18 06:02:05.708: W/System.err(4324):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1421)
02-18 06:02:05.708: W/System.err(4324):     at android.os.Handler.dispatchMessage(Handler.java:102)
02-18 06:02:05.708: W/System.err(4324):     at android.os.Looper.loop(Looper.java:148)
02-18 06:02:05.708: W/System.err(4324):     at android.app.ActivityThread.main(ActivityThread.java:5417)
02-18 06:02:05.709: W/System.err(4324):     at java.lang.reflect.Method.invoke(Native Method)
02-18 06:02:05.709: W/System.err(4324):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
02-18 06:02:05.709: W/System.err(4324):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
02-18 06:02:05.709: W/System.err(4324): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.gcm.GcmReceiver" on path: DexPathList[[zip file "/data/app/com.hezea.ForSaleByOwner-1/base.apk"],nativeLibraryDirectories=[/data/app/com.hezea.ForSaleByOwner-1/lib/x86, /data/app/com.hezea.ForSaleByOwner-1/base.apk!/lib/x86, /vendor/lib, /system/lib]]
02-18 06:02:05.709: W/System.err(4324):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
02-18 06:02:05.709: W/System.err(4324):     at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
02-18 06:02:05.709: W/System.err(4324):     at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
02-18 06:02:05.709: W/System.err(4324):     at android.app.ActivityThread.handleReceiver(ActivityThread.java:2701)
02-18 06:02:05.709: W/System.err(4324):     ... 8 more
02-18 06:02:05.709: W/System.err(4324):     Suppressed: java.lang.ClassNotFoundException: com.google.android.gms.gcm.GcmReceiver
02-18 06:02:05.709: W/System.err(4324):         at java.lang.Class.classForName(Native Method)
02-18 06:02:05.709: W/System.err(4324):         at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
02-18 06:02:05.709: W/System.err(4324):         at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
02-18 06:02:05.709: W/System.err(4324):         at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
02-18 06:02:05.709: W/System.err(4324):         ... 10 more
02-18 06:02:05.709: W/System.err(4324):     Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
02-18 06:02:05.716: I/ActivityManager(1581): START u0 {flg=0x14008000 cmp=com.hezea.ForSaleByOwner/com.tns.ErrorReportActivity (has extras)} from uid 10060 on display 0
02-18 06:02:05.720: D/gralloc_ranchu(1205): gralloc_alloc: format 1 and usage 0x333 imply creation of host color buffer
02-18 06:02:05.722: D/(1581): HostConnection::get() New Host Connection established 0x7fb2da525ec0, tid 1592
02-18 06:02:05.731: E/EGL_emulation(1205): tid 1205: eglCreateSyncKHR(1660): error 0x3004 (EGL_BAD_ATTRIBUTE)
02-18 06:02:05.806: D/gralloc_ranchu(1581): gralloc_unregister_buffer: exiting HostConnection (is buffer-handling thread)
02-18 06:02:05.820: I/Process(4324): Sending signal. PID: 4324 SIG: 9
02-18 06:02:05.846: D/gralloc_ranchu(1205): gralloc_alloc: format 1 and usage 0x933 imply creation of host color buffer
02-18 06:02:05.856: D/(1581): HostConnection::get() New Host Connection established 0x7fb2dbd186c0, tid 1600
02-18 06:02:05.867: D/GraphicsStats(1581): Buffer count: 2
02-18 06:02:05.867: I/WindowState(1581): WIN DEATH: Window{cb57acd u0 com.hezea.ForSaleByOwner/com.tns.NativeScriptActivity}
02-18 06:02:05.882: I/ActivityManager(1581): Process com.hezea.ForSaleByOwner (pid 4324) has died
02-18 06:02:05.889: I/ActivityManager(1581): Start proc 4409:com.hezea.ForSaleByOwner/u0a60 for activity com.hezea.ForSaleByOwner/com.tns.ErrorReportActivity
02-18 06:02:05.891: W/GCM-DMM(2015): broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE pkg=com.hezea.ForSaleByOwner (has extras) }
02-18 06:02:05.893: I/art(4409): Not late-enabling -Xcheck:jni (already on)
02-18 06:02:05.947: D/FirebaseApp(4409): com.google.firebase.auth.FirebaseAuth is not linked. Skipping initialization.
02-18 06:02:05.949: D/FirebaseApp(4409): com.google.firebase.crash.FirebaseCrash is not linked. Skipping initialization.
02-18 06:02:05.952: I/FA(4409): App measurement is starting up, version: 10298
02-18 06:02:05.952: I/FA(4409): To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
02-18 06:02:05.955: I/FA(4409): To enable faster debug mode event logging run:
02-18 06:02:05.955: I/FA(4409):   adb shell setprop debug.firebase.analytics.app com.hezea.ForSaleByOwner
02-18 06:02:05.959: I/FirebaseInitProvider(4409): FirebaseApp initialization successful
02-18 06:02:05.968: I/TNS.Native(4409): NativeScript Runtime Version 2.5.0, commit 95dd12d69eba88755158987d8c4666a9c5aa5e07
02-18 06:02:05.968: D/TNS.Native(4409): JNI_ONLoad
02-18 06:02:05.968: D/TNS.Native(4409): JNI_ONLoad END
02-18 06:02:05.975: W/GooglePlayServicesUtil(4409): Google Play services out of date.  Requires 10298000 but found 10084480
02-18 06:02:05.994: W/art(4409): Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
02-18 06:02:06.072: E/SurfaceFlinger(1205): ro.sf.lcd_density must be defined as a build property
02-18 06:02:06.077: D/OpenGLRenderer(4409): Use EGL_SWAP_BEHAVIOR_PRESERVED: true
02-18 06:02:06.081: W/FA(4409): Service connection failed: ConnectionResult{statusCode=SERVICE_VERSION_UPDATE_REQUIRED, resolution=null, message=null}
02-18 06:02:06.138: D/(4409): HostConnection::get() New Host Connection established 0xedd45380, tid 4430
02-18 06:02:06.146: W/(4409): Process pipe failed
02-18 06:02:06.150: I/OpenGLRenderer(4409): Initialized EGL, version 1.4
02-18 06:02:06.161: D/gralloc_ranchu(1205): gralloc_alloc: format 1 and usage 0x900 imply creation of host color buffer
02-18 06:02:06.181: E/EGL_emulation(4409): tid 4430: eglSurfaceAttrib(1165): error 0x3009 (EGL_BAD_MATCH)
02-18 06:02:06.181: W/OpenGLRenderer(4409): Failed to set EGL_SWAP_BEHAVIOR on surface 0xedd436e0, error=EGL_BAD_MATCH
02-18 06:02:06.182: D/gralloc_ranchu(1205): gralloc_alloc: format 1 and usage 0x900 imply creation of host color buffer
02-18 06:02:06.191: D/gralloc_ranchu(1205): gralloc_alloc: format 1 and usage 0x900 imply creation of host color buffer
02-18 06:02:06.617: I/Choreographer(1581): Skipped 45 frames!  The application may be doing too much work on its main thread.
02-18 06:02:06.631: I/ActivityManager(1581): Displayed com.hezea.ForSaleByOwner/com.tns.ErrorReportActivity: +746ms
02-18 06:02:06.641: W/InputMethodManagerService(1581): Got RemoteException sending setActive(false) notification to pid 4324 uid 10060
02-18 06:02:06.827: D/gralloc_ranchu(1581): gralloc_unregister_buffer: exiting HostConnection (is buffer-handling thread)
02-18 06:02:07.333: W/WindowAnimator(1581): Failed to dispatch window animation state change.
02-18 06:02:07.333: W/WindowAnimator(1581): android.os.DeadObjectException
02-18 06:02:07.333: W/WindowAnimator(1581):     at android.os.BinderProxy.transactNative(Native Method)
02-18 06:02:07.333: W/WindowAnimator(1581):     at android.os.BinderProxy.transact(Binder.java:503)
02-18 06:02:07.333: W/WindowAnimator(1581):     at android.view.IWindow$Stub$Proxy.onAnimationStopped(IWindow.java:534)
02-18 06:02:07.333: W/WindowAnimator(1581):     at com.android.server.wm.WindowAnimator.updateWindowsLocked(WindowAnimator.java:286)
02-18 06:02:07.333: W/WindowAnimator(1581):     at com.android.server.wm.WindowAnimator.animateLocked(WindowAnimator.java:678)
02-18 06:02:07.333: W/WindowAnimator(1581):     at com.android.server.wm.WindowAnimator.-wrap0(WindowAnimator.java)
02-18 06:02:07.333: W/WindowAnimator(1581):     at com.android.server.wm.WindowAnimator$1.doFrame(WindowAnimator.java:123)
02-18 06:02:07.333: W/WindowAnimator(1581):     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:856)
02-18 06:02:07.333: W/WindowAnimator(1581):     at android.view.Choreographer.doCallbacks(Choreographer.java:670)
02-18 06:02:07.333: W/WindowAnimator(1581):     at android.view.Choreographer.doFrame(Choreographer.java:603)
02-18 06:02:07.333: W/WindowAnimator(1581):     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
02-18 06:02:07.333: W/WindowAnimator(1581):     at android.os.Handler.handleCallback(Handler.java:739)
02-18 06:02:07.333: W/WindowAnimator(1581):     at android.os.Handler.dispatchMessage(Handler.java:95)
02-18 06:02:07.333: W/WindowAnimator(1581):     at android.os.Looper.loop(Looper.java:148)
02-18 06:02:07.333: W/WindowAnimator(1581):     at android.os.HandlerThread.run(HandlerThread.java:61)
02-18 06:02:07.333: W/WindowAnimator(1581):     at com.android.server.ServiceThread.run(ServiceThread.java:46)
02-18 06:02:16.077: I/FA(4409): Tag Manager is not found and thus will not be used
02-18 06:02:16.092: W/GooglePlayServicesUtil(4409): Google Play services out of date.  Requires 10298000 but found 10084480
02-18 06:02:16.092: W/FA(4409): Service connection failed: ConnectionResult{statusCode=SERVICE_VERSION_UPDATE_REQUIRED, resolution=null, message=null}

Here is the Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="__PACKAGE__"
    android:versionCode="200003"
    android:versionName="2.0">

    <supports-screens
        android:smallScreens="true"
        android:normalScreens="true"
        android:largeScreens="true"
        android:xlargeScreens="true"/>

    <uses-sdk
        android:minSdkVersion="17"
        android:targetSdkVersion="__APILEVEL__"/>

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

    <application
        android:name="com.tns.NativeScriptApplication"
        android:allowBackup="true"
        android:icon="@drawable/icon"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">

        <activity
            android:name="com.tns.NativeScriptActivity"
            android:label="@string/title_activity_kimera"
            android:configChanges="keyboardHidden|orientation|screenSize"
            android:theme="@style/LaunchScreenTheme">

            <meta-data android:name="SET_THEME_ON_LAUNCH" android:resource="@style/AppTheme" />

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="com.tns.ErrorReportActivity"/>

        <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>
        <activity android:name="com.facebook.FacebookActivity"
            android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
            android:theme="@android:style/Theme.Translucent.NoTitleBar"
            android:label="@string/app_name" />

        <activity android:name="com.telerik.pushplugin.PushHandlerActivity"/>
        <receiver
            android:name="com.google.android.gms.gcm.GcmReceiver"
            android:exported="true"
            android:permission="com.google.android.c2dm.permission.SEND" >
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <category android:name="com.pushApp.gcm" />
            </intent-filter>
        </receiver>
        <service
            android:name="com.telerik.pushplugin.PushPlugin"
            android:exported="false" >
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            </intent-filter>
        </service>
    </application>
</manifest>
ignaciolarranaga commented 7 years ago

I had to move back to 0.0.19 because I was unable to make it work with the new version (the old one works fine).

Tried also the suggestions and manually touch the version as recommended for before the hook but nothing work.

Daxito commented 7 years ago

@ignaciolarranaga This https://github.com/NativeScript/push-plugin/issues/80 tells you what to remove in order to make it work, I have no idea why the Documentation says the opposite, but check the stuff I had to remove, it works great!

ignaciolarranaga commented 7 years ago

Thanks @Daxito, I would try again for the next release in a few days and comment back.

Hope the documentation gets fixed soon. I first updated to 1.0.0 so I think I added them my self by reading the doc :(

noetius commented 7 years ago

Hello, I'm in the same situation plugin version 0.1.2:

An uncaught Exception occurred on "main" thread.
java.lang.RuntimeException: Unable to instantiate receiver 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/org.nativescript.fleetbar-1/base.apk"],nativeLibraryDirectories=[/data/app/org.nativescript.fleetbar-1/lib/arm, /data/app/org.nativescript.fleetbar-1/base.apk!/lib/armeabi-v7a, /vendor/lib, /system/lib]]
    at android.app.ActivityThread.handleReceiver(ActivityThread.java:2706)
    at android.app.ActivityThread.-wrap14(ActivityThread.java)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1421)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:5417)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.gcm.GcmReceiver" on path: DexPathList[[zip file "/data/app/org.nativescript.fleetbar-1/base.apk"],nativeLibraryDirectories=[/data/app/org.nativescript.fleetbar-1/lib/arm, /data/app/org.nativescript.fleetbar-1/base.apk!/lib/armeabi-v7a, /vendor/lib, /system/lib]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
    at android.app.ActivityThread.handleReceiver(ActivityThread.java:2701)
    ... 8 more
    Suppressed: java.lang.ClassNotFoundException: com.google.android.gms.gcm.GcmReceiver
        at java.lang.Class.classForName(Native Method)
        at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
        at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
        ... 10 more
    Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available

If I remove this, it works, but i can't receive notifications when app is closed:


<activity android:name="com.telerik.pushplugin.PushHandlerActivity"/>
<receiver android:name="com.google.android.gms.gcm.GcmReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND" >
    <intent-filter>
        <action android:name="com.google.android.c2dm.intent.RECEIVE" />
        <category android:name="com.pushApp.gcm" />
    </intent-filter>
</receiver>
<service android:name="com.telerik.pushplugin.PushPlugin" android:exported="false" >
    <intent-filter>
        <action android:name="com.google.android.c2dm.intent.RECEIVE" />
    </intent-filter>
</service>
noetius commented 7 years ago

For the realization of an important project, I absolutely need to fix this problem. Now the error is disappeared, but still I can't receive notifications when app is closed. I've searched everywhere, but every relevant resource points to this repo.

There's now way?

Nikoms commented 7 years ago

I have the same error. It does not happen if It is put "outstide" of the application xml node, but then, the "release" command does not work :(

Nikoms commented 7 years ago

@ignaciolarranaga , do you have more luck?

AntonDobrev commented 7 years ago

@Nikoms I believe this error should not be produced in the new setup of the plugin (using Firebase). You may need to double check the docs in the README file of this repo. Please note that you may need to remove and add the Android platform to the project.

Also this issue summarized the case and the solution well.

Hope this helps.

Please follow the part in the docs (Android configuration for uisng FCM)[https://github.com/NativeScript/push-plugin/blob/master/README.md#android-configuration-for-using-firebase-cloud-messaging] and skip the previous content.

Nikoms commented 7 years ago

Hey @AntonDobrev thx for your kind reply. i'm working with "nativescript-push-notifications": "^0.1.2". This is the last version right?

I also remove/add platform.

I'm not using gradle deamon. Is it mandatory?

Nikoms commented 7 years ago

Ok,

I removed the xml :


        <activity android:name="com.telerik.pushplugin.PushHandlerActivity"/>
        <receiver
                android:name="com.google.android.gms.gcm.GcmReceiver"
                android:exported="true"
                android:permission="com.google.android.c2dm.permission.SEND">
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE"/>
                <category android:name="com.pushApp.gcm"/>
            </intent-filter>
        </receiver>
        <service
                android:name="com.telerik.pushplugin.PushPlugin"
                android:exported="false">
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE"/>
            </intent-filter>
        </service>

And it works... And I still receive message event when the app is closed...

Is this xml necessary? Can I do a PR if it's not (To update the doc)

ghost commented 7 years ago

Thanks. That solved it for me!