oney / react-native-gcm-android

GCM for React Native Android
MIT License
172 stars 76 forks source link

Undefined GcmAndroid.launchNotification when receiving notification when app is closed (not in foreground/background) #30

Closed stinju closed 8 years ago

stinju commented 8 years ago

Hello!

Thanks for the plugin! Having trouble getting the launchNotification come through successfully. There are a number of red flags in the logs, but I'm not sure how to proceed. The notification seems to go through some trouble around "setLocalOnly" and "setColor" on my device on 4.4.4. It also seems to have some trouble referencing some classes (might be unrelated). Would love your guidance on the matter.

Note that notifications all work smoothly when the app is in the foreground and background.

Thanks in advance!

Logs:

I/ActivityManager( 1128): Start proc com.gogomonkey.business for broadcast com.gogomonkey.business/com.google.android.gms.gcm.GcmReceiver: pid=17947 uid=10203 gids={50203, 3003, 1028, 1015, 3002}
I/dalvikvm(17947): Could not find method android.app.Notification$Builder.setLocalOnly, referenced from method com.google.android.gms.common.GooglePlayServicesUtil.zza
W/dalvikvm(17947): VFY: unable to resolve virtual method 236: Landroid/app/Notification$Builder;.setLocalOnly (Z)Landroid/app/Notification$Builder;
D/dalvikvm(17947): VFY: replacing opcode 0x6e at 0x00c8
I/dalvikvm(17947): Could not find method android.content.pm.PackageManager.getPackageInstaller, referenced from method com.google.android.gms.common.GooglePlayServicesUtil.zzj
W/dalvikvm(17947): VFY: unable to resolve virtual method 544: Landroid/content/pm/PackageManager;.getPackageInstaller ()Landroid/content/pm/PackageInstaller;
D/dalvikvm(17947): VFY: replacing opcode 0x6e at 0x000b
I/GMPM    (17947): App measurement is starting up
I/dalvikvm(17947): Could not find method android.app.Notification$Builder.setColor, referenced from method com.google.android.gms.gcm.zza.zzw
W/dalvikvm(17947): VFY: unable to resolve virtual method 222: Landroid/app/Notification$Builder;.setColor (I)Landroid/app/Notification$Builder;
D/dalvikvm(17947): VFY: replacing opcode 0x6e at 0x0068
D/RNGcmListenerService(17947): sendNotification
D/BackgroundService(17947): onStartCommand
D/Sensors ( 1128): AccelerationSensor: Set Sensors state 0x1
D/Sensors ( 1128): AccelerationSensor: set delay 200
D/Sensors ( 1128): AccelerationSensor: set delay 66
D/dalvikvm(17947): Trying to load lib /data/app-lib/com.gogomonkey.business-2/libreactnativejni.so 0x41f85b10
D/dalvikvm(17947): Added shared lib /data/app-lib/com.gogomonkey.business-2/libreactnativejni.so 0x41f85b10
D/dalvikvm(17947): Trying to load lib /data/app-lib/com.gogomonkey.business-2/libreactnativejni.so 0x41f85b10
D/dalvikvm(17947): Shared lib '/data/app-lib/com.gogomonkey.business-2/libreactnativejni.so' already loaded in same CL 0x41f85b10
I/dalvikvm(17947): threadid=1: recursive native library load attempt (/data/app-lib/com.gogomonkey.business-2/libreactnativejni.so)
D/dalvikvm(17947): Trying to load lib /data/app-lib/com.gogomonkey.business-2/libfbjni.so 0x41f85b10
D/dalvikvm(17947): Added shared lib /data/app-lib/com.gogomonkey.business-2/libfbjni.so 0x41f85b10
I/dalvikvm(17947): Could not find method com.facebook.react.views.view.ReactViewGroup.drawableHotspotChanged, referenced from method com.facebook.react.views.view.ReactViewManager.receiveCommand
W/dalvikvm(17947): VFY: unable to resolve virtual method 24770: Lcom/facebook/react/views/view/ReactViewGroup;.drawableHotspotChanged (FF)V
D/dalvikvm(17947): VFY: replacing opcode 0x6e at 0x002d
I/dalvikvm(17947): Could not find method com.facebook.react.views.view.ReactViewGroup.setElevation, referenced from method com.facebook.react.views.view.ReactViewManager.setElevation
W/dalvikvm(17947): VFY: unable to resolve virtual method 24806: Lcom/facebook/react/views/view/ReactViewGroup;.setElevation (F)V
D/dalvikvm(17947): VFY: replacing opcode 0x6e at 0x000a
I/dalvikvm(17947): Could not find method android.webkit.CookieManager.setCookie, referenced from method com.facebook.react.modules.network.ForwardingCookieHandler.addCookieAsync
W/dalvikvm(17947): VFY: unable to resolve virtual method 16883: Landroid/webkit/CookieManager;.setCookie (Ljava/lang/String;Ljava/lang/String;Landroid/webkit/ValueCallback;)V
D/dalvikvm(17947): VFY: replacing opcode 0x6e at 0x0005
I/dalvikvm(17947): Could not find method android.webkit.CookieManager.removeAllCookies, referenced from method com.facebook.react.modules.network.ForwardingCookieHandler.clearCookiesAsync
W/dalvikvm(17947): VFY: unable to resolve virtual method 16880: Landroid/webkit/CookieManager;.removeAllCookies (Landroid/webkit/ValueCallback;)V
D/dalvikvm(17947): VFY: replacing opcode 0x6e at 0x0009
I/dalvikvm(17947): Could not find method android.webkit.CookieManager.flush, referenced from method com.facebook.react.modules.network.ForwardingCookieHandler$CookieSaver.flush
W/dalvikvm(17947): VFY: unable to resolve virtual method 16876: Landroid/webkit/CookieManager;.flush ()V
D/dalvikvm(17947): VFY: replacing opcode 0x6e at 0x0006
D/ConnectivityService( 1128): handleInetConditionHoldEnd: net=1, condition=100, published condition=100
I/SBar.NetworkController( 1227): onReceive: ConnectivityManager.INET_CONDITION_ACTION Received
I/ModemStatsDSDetect( 1314): onReceive() -Intent { act=android.net.conn.INET_CONDITION_ACTION flg=0x4000010 (has extras) }
I/SBar.NetworkController( 1227): updateConnectivity: NetworkInfo: NetworkInfo: type: WIFI[], state: CONNECTED/CONNECTED, reason: (unspecified), extra: "WYXWJ", roaming: false, failover: false, isAvailable: true, isConnectedToProvisioningNetwork: false, inetCondition= 1
I/ModemStatsDSDetect( 1314): INET_CONDITION=100 ,activeNet=NetworkInfo: type: WIFI[], state: CONNECTED/CONNECTED, reason: (unspecified), extra: "WYXWJ", roaming: false, failover: false, isAvailable: true, isConnectedToProvisioningNetwork: false
I/ModemStatsDSDetect( 1314): onReceive() - done, currentInetCondition=100
W/dalvikvm(17947): VFY: unable to find class referenced in signature (Ljava/nio/file/Path;)
W/dalvikvm(17947): VFY: unable to find class referenced in signature ([Ljava/nio/file/OpenOption;)
I/dalvikvm(17947): Could not find method java.nio.file.Files.newOutputStream, referenced from method okio.Okio.sink
W/dalvikvm(17947): VFY: unable to resolve static method 46635: Ljava/nio/file/Files;.newOutputStream (Ljava/nio/file/Path;[Ljava/nio/file/OpenOption;)Ljava/io/OutputStream;
D/dalvikvm(17947): VFY: replacing opcode 0x71 at 0x000a
W/dalvikvm(17947): VFY: unable to find class referenced in signature (Ljava/nio/file/Path;)
W/dalvikvm(17947): VFY: unable to find class referenced in signature ([Ljava/nio/file/OpenOption;)
I/dalvikvm(17947): Could not find method java.nio.file.Files.newInputStream, referenced from method okio.Okio.source
W/dalvikvm(17947): VFY: unable to resolve static method 46634: Ljava/nio/file/Files;.newInputStream (Ljava/nio/file/Path;[Ljava/nio/file/OpenOption;)Ljava/io/InputStream;
D/dalvikvm(17947): VFY: replacing opcode 0x71 at 0x000a
I/ReactNativeJS(17947): index.android.js==============================
I/ReactNativeJS(17947): undefined

I/dalvikvm(17947): Could not find method android.widget.ImageView.<init>, referenced from method com.facebook.drawee.view.DraweeView.<init>
W/dalvikvm(17947): VFY: unable to resolve direct method 17156: Landroid/widget/ImageView;.<init> (Landroid/content/Context;Landroid/util/AttributeSet;II)V
D/dalvikvm(17947): VFY: replacing opcode 0x70 at 0x0000
I/dalvikvm(17947): Could not find method com.facebook.drawee.view.DraweeView.getImageTintList, referenced from method com.facebook.drawee.view.DraweeView.init
W/dalvikvm(17947): VFY: unable to resolve virtual method 19393: Lcom/facebook/drawee/view/DraweeView;.getImageTintList ()Landroid/content/res/ColorStateList;
D/dalvikvm(17947): VFY: replacing opcode 0x6e at 0x0015
V/AlarmManager( 1128): sending alarm Alarm{42088680 type 2 com.facebook.katana}
I/ActivityManager( 1128): Waited long enough for: ServiceRecord{42a494c8 u0 com.gogomonkey.business/com.oney.gcm.BackgroundService}

app/build.gradle dependencies:

dependencies {
    compile project(':react-native-code-push')
    compile project(':react-native-device-info')
    compile project(':react-native-vector-icons')
    compile fileTree(dir: "libs", include: ["*.jar"])
    compile "com.android.support:appcompat-v7:23.0.1"
    compile "com.facebook.react:react-native:0.17.+"
    compile 'com.google.android.gms:play-services-gcm:8.1.0'
    compile project(':RNGcmAndroid')
    compile project(':react-native-system-notification')
}

versions:

    "react-native-gcm-android": "^0.1.8",
    "react-native-system-notification": "0.0.8",
    "react-native": "^0.17.0",
oney commented 8 years ago

Please give me some code snippets of index.android.js

stinju commented 8 years ago

I'm currently using snippets from the example to just try to get it to work (see below). Note that I've already registered my token with my server (not shown here), and am using this example page as a reduced repro case for myself.

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 */
'use strict';

var React = require('react-native');
var {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  DeviceEventEmitter,
} = React;

var GcmAndroid = require('react-native-gcm-android');
import Notification from 'react-native-system-notification';

console.log('index.android.js==============================');
console.log(GcmAndroid.launchNotification);
if (GcmAndroid.launchNotification) {
  console.log('GcmAndroid.launchNotification:', GcmAndroid.launchNotification);
  var notification = GcmAndroid.launchNotification;
  var info = JSON.parse(notification.info);
  Notification.create({
    subject: info.subject,
    message: info.message,
  });
  GcmAndroid.stopService();
} else {
  var GoGoMonkeyBusiness = React.createClass({
    componentDidMount: function() {
      GcmAndroid.addEventListener('register', function(token){
        console.log('send gcm token to server', token);
      });
      GcmAndroid.addEventListener('notification', function(notification){
        console.log('receive gcm notification', notification);
      });

      DeviceEventEmitter.addListener('sysNotificationClick', function(e) {
        console.log('sysNotificationClick', e);
      });
      GcmAndroid.requestPermissions();
    },
    render: function() {
      return (
        <View style={styles.container}>
          <Text style={styles.welcome}>
            Welcome to React Native!
          </Text>
          <Text style={styles.instructions}>
            To get started, edit index.android.js
          </Text>
          <Text style={styles.instructions}>
            Shake or press menu button for dev menu
          </Text>
        </View>
      );
    }
  });

  var styles = StyleSheet.create({
    container: {
      flex: 1,
      justifyContent: 'center',
      alignItems: 'center',
      backgroundColor: '#F5FCFF',
    },
    welcome: {
      fontSize: 20,
      textAlign: 'center',
      margin: 10,
    },
    instructions: {
      textAlign: 'center',
      color: '#333333',
      marginBottom: 5,
    },
  });

  AppRegistry.registerComponent('GoGoMonkeyBusiness', () => GoGoMonkeyBusiness);
}
oney commented 8 years ago

Weird.... Can you try the demo project?

stinju commented 8 years ago

So, it's working now, but I am not certain of the culprit.

The demo worked as advertised. Even though last night's version bump wasn't really relevant here, I decided to upgrade this plugin for my project just to get parity with the demo project. Then, after restarting the phone and ensuring that the react native packager was fresh, it just worked. So unfortunately, I don't have a great rationale to contribute here. I'll definitely update here if I find anything, but otherwise, thanks for your quick attention and pointer to try out the demo project!

Log (note the unreferenced classes and notification builder issues are still here, so likely irrelevant):

I/GCM     ( 1435): GCM message com.gogomonkey.business 0:1453214615376206%e20063ecf9fd7ecd
D/dalvikvm( 7823): Late-enabling CheckJNI
I/ActivityManager( 1084): Start proc com.gogomonkey.business for broadcast com.gogomonkey.business/com.google.android.gms.gcm.GcmReceiver: pid=7823 uid=10207 gids={50207, 3003, 1028, 1015, 3002}
I/dalvikvm( 7823): Could not find method android.app.Notification$Builder.setLocalOnly, referenced from method com.google.android.gms.common.GooglePlayServicesUtil.zza
W/dalvikvm( 7823): VFY: unable to resolve virtual method 236: Landroid/app/Notification$Builder;.setLocalOnly (Z)Landroid/app/Notification$Builder;
D/dalvikvm( 7823): VFY: replacing opcode 0x6e at 0x00c8
I/dalvikvm( 7823): Could not find method android.content.pm.PackageManager.getPackageInstaller, referenced from method com.google.android.gms.common.GooglePlayServicesUtil.zzj
W/dalvikvm( 7823): VFY: unable to resolve virtual method 544: Landroid/content/pm/PackageManager;.getPackageInstaller ()Landroid/content/pm/PackageInstaller;
D/dalvikvm( 7823): VFY: replacing opcode 0x6e at 0x000b
I/GMPM    ( 7823): App measurement is starting up
I/dalvikvm( 7823): Could not find method android.app.Notification$Builder.setColor, referenced from method com.google.android.gms.gcm.zza.zzw
W/dalvikvm( 7823): VFY: unable to resolve virtual method 222: Landroid/app/Notification$Builder;.setColor (I)Landroid/app/Notification$Builder;
D/dalvikvm( 7823): VFY: replacing opcode 0x6e at 0x0068
D/RNGcmListenerService( 7823): sendNotification
D/BackgroundService( 7823): onStartCommand
D/Sensors ( 1084): AccelerationSensor: set delay 66
D/dalvikvm( 7823): Trying to load lib /data/app-lib/com.gogomonkey.business-2/libreactnativejni.so 0x41f83938
D/dalvikvm( 7823): Added shared lib /data/app-lib/com.gogomonkey.business-2/libreactnativejni.so 0x41f83938
D/dalvikvm( 7823): Trying to load lib /data/app-lib/com.gogomonkey.business-2/libreactnativejni.so 0x41f83938
D/dalvikvm( 7823): Shared lib '/data/app-lib/com.gogomonkey.business-2/libreactnativejni.so' already loaded in same CL 0x41f83938
I/dalvikvm( 7823): threadid=1: recursive native library load attempt (/data/app-lib/com.gogomonkey.business-2/libreactnativejni.so)
D/dalvikvm( 7823): Trying to load lib /data/app-lib/com.gogomonkey.business-2/libfbjni.so 0x41f83938
D/dalvikvm( 7823): Added shared lib /data/app-lib/com.gogomonkey.business-2/libfbjni.so 0x41f83938
I/dalvikvm( 7823): Could not find method com.facebook.react.views.view.ReactViewGroup.drawableHotspotChanged, referenced from method com.facebook.react.views.view.ReactViewManager.receiveCommand
W/dalvikvm( 7823): VFY: unable to resolve virtual method 24770: Lcom/facebook/react/views/view/ReactViewGroup;.drawableHotspotChanged (FF)V
D/dalvikvm( 7823): VFY: replacing opcode 0x6e at 0x002d
I/dalvikvm( 7823): Could not find method com.facebook.react.views.view.ReactViewGroup.setElevation, referenced from method com.facebook.react.views.view.ReactViewManager.setElevation
W/dalvikvm( 7823): VFY: unable to resolve virtual method 24806: Lcom/facebook/react/views/view/ReactViewGroup;.setElevation (F)V
D/dalvikvm( 7823): VFY: replacing opcode 0x6e at 0x000a
D/WifiStateMachine( 1084): handleMessage: E msg.what=151572
D/WifiStateMachine( 1084): processMsg: ConnectedState
D/WifiStateMachine( 1084): processMsg: L2ConnectedState
D/WifiStateMachine( 1084): handleMessage: X
I/SFPerfTracer(  327):      triggers: (rate: 0:0) (29211 sw vsyncs) (0 skipped) (18:16155 vsyncs) (20:46086)
I/dalvikvm( 7823): Could not find method android.webkit.CookieManager.setCookie, referenced from method com.facebook.react.modules.network.ForwardingCookieHandler.addCookieAsync
W/dalvikvm( 7823): VFY: unable to resolve virtual method 16883: Landroid/webkit/CookieManager;.setCookie (Ljava/lang/String;Ljava/lang/String;Landroid/webkit/ValueCallback;)V
D/dalvikvm( 7823): VFY: replacing opcode 0x6e at 0x0005
I/dalvikvm( 7823): Could not find method android.webkit.CookieManager.removeAllCookies, referenced from method com.facebook.react.modules.network.ForwardingCookieHandler.clearCookiesAsync
W/dalvikvm( 7823): VFY: unable to resolve virtual method 16880: Landroid/webkit/CookieManager;.removeAllCookies (Landroid/webkit/ValueCallback;)V
D/dalvikvm( 7823): VFY: replacing opcode 0x6e at 0x0009
I/dalvikvm( 7823): Could not find method android.webkit.CookieManager.flush, referenced from method com.facebook.react.modules.network.ForwardingCookieHandler$CookieSaver.flush
W/dalvikvm( 7823): VFY: unable to resolve virtual method 16876: Landroid/webkit/CookieManager;.flush ()V
D/dalvikvm( 7823): VFY: replacing opcode 0x6e at 0x0006
D/ConnectivityService( 1084): handleInetConditionHoldEnd: net=1, condition=100, published condition=100
I/ModemStatsDSDetect( 1253): onReceive() -Intent { act=android.net.conn.INET_CONDITION_ACTION flg=0x4000010 (has extras) }
I/SBar.NetworkController( 1178): onReceive: ConnectivityManager.INET_CONDITION_ACTION Received
I/SBar.NetworkController( 1178): updateConnectivity: NetworkInfo: NetworkInfo: type: WIFI[], state: CONNECTED/CONNECTED, reason: (unspecified), extra: "SXCTS", roaming: false, failover: false, isAvailable: true, isConnectedToProvisioningNetwork: false, inetCondition= 1
I/ModemStatsDSDetect( 1253): INET_CONDITION=100 ,activeNet=NetworkInfo: type: WIFI[], state: CONNECTED/CONNECTED, reason: (unspecified), extra: "SXCTS", roaming: false, failover: false, isAvailable: true, isConnectedToProvisioningNetwork: false
I/ModemStatsDSDetect( 1253): onReceive() - done, currentInetCondition=100
W/dalvikvm( 7823): VFY: unable to find class referenced in signature (Ljava/nio/file/Path;)
W/dalvikvm( 7823): VFY: unable to find class referenced in signature ([Ljava/nio/file/OpenOption;)
I/dalvikvm( 7823): Could not find method java.nio.file.Files.newOutputStream, referenced from method okio.Okio.sink
W/dalvikvm( 7823): VFY: unable to resolve static method 46635: Ljava/nio/file/Files;.newOutputStream (Ljava/nio/file/Path;[Ljava/nio/file/OpenOption;)Ljava/io/OutputStream;
D/dalvikvm( 7823): VFY: replacing opcode 0x71 at 0x000a
W/dalvikvm( 7823): VFY: unable to find class referenced in signature (Ljava/nio/file/Path;)
W/dalvikvm( 7823): VFY: unable to find class referenced in signature ([Ljava/nio/file/OpenOption;)
I/dalvikvm( 7823): Could not find method java.nio.file.Files.newInputStream, referenced from method okio.Okio.source
W/dalvikvm( 7823): VFY: unable to resolve static method 46634: Ljava/nio/file/Files;.newInputStream (Ljava/nio/file/Path;[Ljava/nio/file/OpenOption;)Ljava/io/InputStream;
D/dalvikvm( 7823): VFY: replacing opcode 0x71 at 0x000a
I/ReactNativeJS( 7823): index.android.js==============================
I/ReactNativeJS( 7823): index.android.js==============================
I/ReactNativeJS( 7823): { message: 'bar',
I/ReactNativeJS( 7823):   title: 'foo',
I/ReactNativeJS( 7823):   sound: 'true',
I/ReactNativeJS( 7823):   collapse_key: 'do_not_collapse' }
I/ReactNativeJS( 7823): 'GcmAndroid.launchNotification:', { message: 'bar',
I/ReactNativeJS( 7823):   title: 'foo',
I/ReactNativeJS( 7823):   sound: 'true',
I/ReactNativeJS( 7823):   collapse_key: 'do_not_collapse' }
I/dalvikvm( 7823): Could not find method android.widget.ImageView.<init>, referenced from method com.facebook.drawee.view.DraweeView.<init>
W/dalvikvm( 7823): VFY: unable to resolve direct method 17156: Landroid/widget/ImageView;.<init> (Landroid/content/Context;Landroid/util/AttributeSet;II)V
D/dalvikvm( 7823): VFY: replacing opcode 0x70 at 0x0000
I/dalvikvm( 7823): Could not find method com.facebook.drawee.view.DraweeView.getImageTintList, referenced from method com.facebook.drawee.view.DraweeView.init
W/dalvikvm( 7823): VFY: unable to resolve virtual method 19393: Lcom/facebook/drawee/view/DraweeView;.getImageTintList ()Landroid/content/res/ColorStateList;
D/dalvikvm( 7823): VFY: replacing opcode 0x6e at 0x0015
I/dalvikvm( 7823): Could not find method android.app.Notification$Builder.setLocalOnly, referenced from method io.neson.react.notification.Notification.build
W/dalvikvm( 7823): VFY: unable to resolve virtual method 236: Landroid/app/Notification$Builder;.setLocalOnly (Z)Landroid/app/Notification$Builder;
D/dalvikvm( 7823): VFY: replacing opcode 0x6e at 0x010a
I/ReactSystemNotification( 7823): Notification Show: 66847
I/ReactSystemNotification( 7823): Notification Created: 66847
oney commented 8 years ago

Restarting everything may solve the problem sometimes when developing React Native app. :weary: