question

felipeclaude avatar image
felipeclaude asked

Android Push Unity 5.0

Hi!

I've implemented AndroidPushPlugin and I'm having this error only in certain devices (even though they both have Android 5.1).

On 9/10 devices pushes work perfectly, but on 1 huawei device the below error always ocurrs when handling the push outside of the game.

Please help, any other usefull snippet needed I'll be glad to post

regards!

E/AndroidRuntime(19911): Caused by: java.lang.RuntimeException: Unable to start receiver com.playfab.unityplugin.GCM.NotificationPublisher: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.playfab.unityplugin.GCM.PlayFabNotificationPackage.SetDeliveryDate(java.util.Date)' on a null object reference
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

marcowilliamspf avatar image
marcowilliamspf answered

Hi Guys,

Sorry for the delay in response on this, I was out of town for a spell.

I'm not 100% sure if this will solve your issue because I don't know what your manifest looks like, however. I believe the issue might be that you are missing the following line in your manifest.

We added this about a month ago, and it is now required for the plugin to work.

<receiver android:name="com.playfab.unityplugin.GCM.NotificationPublisher" android:enabled="true" android:exported="false" /> 

If you do not have this line in the manifest, any reference to it via JNI will return NULL, hence you can't call the method.

Let me know if this solved your issue.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

felipeclaude avatar image
felipeclaude answered

more of the related error

E/Parcel  (  934): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.playfab.unityplugin.GCM.PlayFabNotificationPackage" on path: DexPathList[[directory "."],nativeLibraryDirectories=[/vendor/lib64, /system/lib64]]



E/art     (  934): ClassLinker::FindClass not found:Lcom/playfab/unityplugin/GCM/PlayFabNotificationPackage;


I/HwSystemManager( 2619): SimCardManagerExt:/getOperatorNameOnQcom name is: null


D/ActivityManager(  934): broadcastIntentLocked Callstacl:com.android.server.am.ActivityManagerService.broadcastIntentInPackage:17888 com.android.server.am.PendingIntentRecord.sendInner:272 com.android.server.am.PendingIntentRecord.send:195 android.app.PendingIntent.send:733 android.app.PendingIntent.send:687 com.android.server.AlarmManagerService.deliverAlarmsLocked:2158 com.android.server.AlarmManagerService$AlarmThread.run:2338 <bottom of call stack> <bottom of call stack> <bottom of call stack> 


E/Parcel  (  934): Class not found when unmarshalling: com.playfab.unityplugin.GCM.PlayFabNotificationPackage


E/Parcel  (  934): java.lang.ClassNotFoundException: com.playfab.unityplugin.GCM.PlayFabNotificationPackage
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

felipeclaude avatar image
felipeclaude answered

Hello Marco, Thanks for the response.

Saldy I already have that in the manifest (Using your last month unity 5.0 plugin).

If it helps here's my manifest:

Regards

<?xml version="1.0" encoding="utf-8"?>
<manifest
    xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.playfab.pushtestapp"
    android:installLocation="preferExternal"
    android:theme="@android:style/Theme.NoTitleBar"
    android:versionCode="1"
    android:versionName="1.0">


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


    <!--<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="24"/>-->


    <!-- Android GCM Plugin -->
    <permission android:name="com.playfab.pushtestapp.permission.C2D_MESSAGE" android:protectionLevel="signature" /> <!-- //Change to your package name .permission.C2D_MESSAGE -->
    <uses-permission android:name="com.playfab.pushtestapp.permission.C2D_MESSAGE" /> <!-- //Change to your package name .permission.C2D_MESSAGE -->
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="com.android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="com.android.vending.BILLING" />
    
    <!-- Android GCM Plugin -->


    <application
        android:allowBackup="true"
        android:label="@string/app_name"
        android:icon="@drawable/app_icon"
        android:isGame="true">
      
        <!-- Unity Activities -->
        <activity android:name="com.unity3d.player.UnityPlayerProxyActivity"
            android:launchMode="singleTask"
            android:label="@string/app_name"
            android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="com.unity3d.player.UnityPlayerActivity"
            android:launchMode="singleTask"
            android:label="@string/app_name"
            android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
        </activity>
        <activity android:name="com.unity3d.player.UnityPlayerNativeActivity"
            android:launchMode="singleTask"
            android:label="@string/app_name"
            android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
            <meta-data android:name="android.app.lib_name" android:value="unity" />
            <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="false" />
        </activity>
        <!-- End Unity Activities -->


        <!-- Begin GCM -->
        <receiver
            android:name="com.google.android.gms.gcm.GcmReceiver"
            android:permission="com.google.android.c2dm.permission.SEND" >
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <!-- for Gingerbread GSF backward compat -->
                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
                <category android:name="com.playfab.pushtestapp" />  <!-- //Change to your package name -->
            </intent-filter>
        </receiver>


        <service android:name="com.playfab.unityplugin.GCM.PlayFabGcmListenerService" android:exported="false">
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
            </intent-filter>
        </service>


        <service
            android:name="com.playfab.unityplugin.GCM.PlayFabInstanceIDListenerService"
            android:exported="false">
            <intent-filter>
                <action android:name="com.google.android.gms.iid.InstanceID"/>
            </intent-filter>
        </service>
        <service
            android:name="com.playfab.unityplugin.GCM.PlayFabRegistrationIntentService"
            android:exported="false">
        </service>
        <service
            android:name="com.playfab.unityplugin.PlayFabUnityAndroidPlugin"
            android:exported="false"
            android:stopWithTask="true">
        </service>


      <receiver android:name="com.playfab.unityplugin.GCM.NotificationPublisher" android:enabled="true" android:exported="false" />


      <!-- End GCM -->


        <!-- Begin IAP -->


        <!-- End IAP -->
      <activity android:name="com.facebook.unity.FBUnityLoginActivity" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" />
      <activity android:name="com.facebook.unity.FBUnityDialogsActivity" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" />
      <activity android:name="com.facebook.unity.FBUnityAppLinkActivity" android:exported="true" />
      <activity android:name="com.facebook.unity.FBUnityDeepLinkingActivity" android:exported="true" />
      <activity android:name="com.facebook.unity.FBUnityGameRequestActivity" />
      <activity android:name="com.facebook.unity.FBUnityCreateGameGroupActivity" />
      <activity android:name="com.facebook.unity.FBUnityJoinGameGroupActivity" />
      <activity android:name="com.facebook.unity.AppInviteDialogActivity" />
      <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="fb1234554429917577" />
      <provider android:name="com.facebook.FacebookContentProvider" android:authorities="com.facebook.app.FacebookContentProvider1234554429917577" android:exported="true" />
    </application>


</manifest>


10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

marcowilliamspf avatar image
marcowilliamspf answered

My only other guess is maybe that you have moved the .AAR files to another location other than their original installation location. I'm not exactly sure what is going on in your particular situation.

I have created this video, it is a bit raw, but it shows implementing our Android Push Notification Plugin from scratch. be warned, since this is unedited it is about 54 minutes long.

https://www.youtube.com/watch?v=ObdhM3Q9oaw&feature=youtu.be


See if you are doing something different than I am in this video.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Ian Oliver avatar image
Ian Oliver answered

I just ran into a similar issue (with identical symptoms). It turns out that the problem had to do with queued notifications being delivered in one go. Given messages A and B:

onMessageReceived(A)
onMessageReceived(B)
onReceive(A) -- kablewy!

It seemed to be some PendingIntent weirdness related to FLAG_UPDATE_CURRENT. When the messages are queued up like this, the intent passed to NotificationPublisher.onReceive has missing extras.

I 'fixed' this by removing the plugin, adding the code from GitHub to my project, and modifying PlayFabNotificationSender.send to call context.sendBroadcast(notificationIntent); instead of the alarm manager for local notifications.

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

marcowilliamspf avatar image marcowilliamspf commented ·

@Ian Oliver when you have a moment can you ping me on Slack so I can better understand this issue and what your fix was.

0 Likes 0 ·
ryan avatar image
ryan answered

We are having a very similar error with our game now on Android.

We've re-implemented things several times now trying to determine what is going wrong. I can confirm that we have the receiver configured in our manifest as was suggested above. The AAR files are in Plugins/Android as they should be.

Is there anything else I should check?

@Ian Oliver do you know if your change was rolled into the plugin since you suggested it?

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

marcowilliamspf avatar image
marcowilliamspf answered

@ryan While I have not had a chance to look into the issue, I know for a fact we won't be rolling Ian's change into the plugin. This is primarily because we need the Alarm manager to have support for scheduled push notifications.

I should be able to get to looking at this maybe sometime next week.

2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

games avatar image games commented ·

@MarcoWilliamsPF Any updates on this? Push notifications still crash the game on my Nexus 6P. Other devices work fine.

0 Likes 0 ·
ryan avatar image ryan games commented ·

@games Just a side note; We needed to implement something quickly due to the nature of how our game utilizes push messages for multiplayer invites, so we switched over to the GCM plugin by Prime31. It took us about 30 mins to pull it in and wire it up to our invitations code. We haven't had any issues sense. We probably lost some of the Playfab integration for local notifications and such, but we weren't using those anyways. We will likely switch back to Playfab's plugin in the future once they've ironed out the crash bug.

1 Like 1 ·
ryan avatar image
ryan answered
@MarcoWilliamsPF

Ok, that makes sense. I'm just trying to wrap my head around some of the issues we're having currently. On some devices we are able to receive GCM messages without issue, while on others receiving a push message causes the app to crash with several error messages (such as "Class not found when unmarshalling: com.playfab.unityplugin.GCM.PlayFabNotificationPackage"). We've confirmed repeatedly that the packages are pulling in, the manifest we are using is generated by the Playfab plugin, with a few additions for Google Play Services.

Are there any other things we should check that we might be missing?

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

ryan avatar image ryan commented ·

Wanted to add the specific error from the log to ensure we're all talking about the same issue. We aren't using local notifications, just those sent from PlayFab's servers.

 Caused by: java.lang.RuntimeException: Unable to start receiver com.playfab.unityplugin.GCM.NotificationPublisher: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.playfab.unityplugin.GCM.PlayFabNotificationPackage.SetDeliveryDate(java.util.Date)' on a null object reference
0 Likes 0 ·
games avatar image
games answered

@MarcoWilliamsPF @ryan Managed to fix the problem. Notifications now show on all devices.

What I did was wrap the extras in a bundle as suggested here (http://stackoverflow.com/questions/28589509/android-e-parcel-class-not-found-when-unmarshalling-only-on-samsung-tab3)

Also, Bundle internals are not touched by any device till needed. (as seen here: http://stackoverflow.com/questions/2307476/classnotfoundexception-when-using-custom-parcelable/21141830#answer-21141830)

To fix it modify the following classes:


In NotificationPublisher.java, I added

Bundle bundle = intent.getBundleExtra(NOTIFICATION);
PlayFabNotificationPackage notification = bundle.getParcelable(BUNDLE_ID);

Also commented out the String notificationId because it's not being used.

In PlayFabNotificationSender.java : methods Send, ScheduleNotification, CancelScheduledNotification, I added

Bundle bundle = new Bundle();
bundle.putParcelable(NotificationPublisher.BUNDLE_ID, notifyPackage);
        
Intent notificationIntent = new Intent(intent, NotificationPublisher.class);
notificationIntent.putExtra(NotificationPublisher.NOTIFICATION, bundle);

Build with gradle and it's ready.

Changed Files with working AAR: pushnotificationsfix.zip


10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.