OneSignal / OneSignal-Unity-SDK

OneSignal is a free push notification service for mobile apps. This plugin makes it easy to integrate your Unity app with OneSignal. https://onesignal.com
Other
222 stars 61 forks source link

Crash when opening notification while app is running on Android #58

Closed paulmriordan closed 7 years ago

paulmriordan commented 7 years ago

onesignal_crash_logcat.txt Android 4.4.2 LG G2, OneSignal-Unity-SDK-2.3.3, Unity 5.6.2f1

The app is running, I click on the notification by dragging down the notifications window, the app relaunches, and this relaunch crashes.

I'm sending a reward via the notification. Because of the crash, reward is never received.

Think these lines from logcat is related:

W/Binder  ( 1469): Caught a RuntimeException from the binder stub implementation.
W/Binder  ( 1469): java.lang.NullPointerException
W/Binder  ( 1469):  at android.inputmethodservice.IInputMethodWrapper.setSessionEnabled(IInputMethodWrapper.java:280)
W/Binder  ( 1469):  at com.android.internal.view.IInputMethod$Stub.onTransact(IInputMethod.java:129)
W/Binder  ( 1469):  at android.os.Binder.execTransact(Binder.java:407)
W/Binder  ( 1469):  at dalvik.system.NativeStart.run(Native Method)

Attached log from running adb logcat -d -v threadtime > onesignal_crash_logcat.txt onesignal_crash_logcat.txt

jkasten2 commented 7 years ago

@paulmriordan I see the notification is opened around 08-01 18:07:08.90 on line 1495 but the crash doesn't happen until 08-01 18:07:17.893 on line 2095 about 10 seconds later.

Do you have any code in the OneSignal NotificationOpened that could be causing the crash? Are you running any other plugins that could be showing their own native Android Activity from here?

Do you also get crash in other states of your app? Such as it running in the background or when it is completely closed?

paulmriordan commented 7 years ago

I have code in HandleNotificationOpened for processing rewards. It exits this function without crashing.

As a test, I completely removed my HandleNotificationOpened code for a build; issue still persists (app crashes, attempts relaunch, relaunch crashes)

When app is in background => it relaunches my app, and my HandleNotificationOpened code doesn't get called. When the app is completely closed => works as intended, app is launched, reward is received via HandleNotificationOpened code.

paulmriordan commented 7 years ago

Looking into it more, I think the issue is related to having kii sdk integrated for backend services.

I tried a test build with just onesignal, and another with onesignal and kii, and only the latter exhibits the issue.

Kii offer push notifications too (which I don't use), so it may be interfering. I'm trying to modify the kii manifest requirements, but not having much luck. Is there anything in this manifest that I should safely remove:

AndroidManifest.txt

paulmriordan commented 7 years ago

Also, I'm getting this output in the log once I click on the notification:

Scheduling restart of crashed service com.[company].[app]/com.onesignal.SyncService in 1000ms

jkasten2 commented 7 years ago

@paulmriordan When opening a notification it should always resume that app instead of relaunching it every time. This side effect is most likely casing the crash as it is creating extra instances of code that might not be able to handle it correctly.

It seems the Kii plugin adds a UnityPlayerProxyActivity manifest entry that is creating the issue. I recommend replacing all android:launchMode="singleTask" entries with android:launchMode="singleTop" in your AndroidManifest.xml which should force the Activity to be brought forward instead of creating another instance.

paulmriordan commented 7 years ago

I still get a crash on relaunch. From looking at the logs, it's now a segmentation fault. (I also only now get the "Unfortunately, __ has stopped" popup.)

logcat:

I/DEBUG   (  279): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
I/DEBUG   (  279): Build fingerprint: 'lge/g2_open_com/g2:4.4.2/KOT49I.D80220c/D80220c.1400592244:user/release-keys'
I/DEBUG   (  279): Revision: '10'
I/DEBUG   (  279): pid: 16824, tid: 18515, name: Thread-7749  >>> com.umbrella.tidyrobots <<<
I/DEBUG   (  279): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00000000

I/DEBUG   (  279): backtrace:
I/DEBUG   (  279):     #00  pc 005e3144  /data/app-lib/com.[company].[app]-1/libunity.so
I/DEBUG   (  279):     #01  pc 005e349c  /data/app-lib/com.[company].[app]-1/libunity.so
I/DEBUG   (  279):     #02  pc 005eec14  /data/app-lib/com.[company].[app]-1/libunity.so
I/DEBUG   (  279):     #03  pc 000204cc  /system/lib/libdvm.so (dvmPlatformInvoke+112)
I/DEBUG   (  279):     #04  pc 000512af  /system/lib/libdvm.so (dvmCallJNIMethod(unsigned int const*, JValue*, Method const*, Thread*)+398)
I/DEBUG   (  279):     #05  pc 00029960  /system/lib/libdvm.so
I/DEBUG   (  279):     #06  pc 00030ec8  /system/lib/libdvm.so (dvmMterpStd(Thread*)+76)
I/DEBUG   (  279):     #07  pc 0002e560  /system/lib/libdvm.so (dvmInterpret(Thread*, Method const*, JValue*)+184)
I/DEBUG   (  279):     #08  pc 00063795  /system/lib/libdvm.so (dvmCallMethodV(Thread*, Method const*, Object*, bool, JValue*, std::__va_list)+336)
I/DEBUG   (  279):     #09  pc 000637b9  /system/lib/libdvm.so (dvmCallMethod(Thread*, Method const*, Object*, JValue*, ...)+20)
I/DEBUG   (  279):     #10  pc 0005848f  /system/lib/libdvm.so
I/DEBUG   (  279):     #11  pc 0000d2e0  /system/lib/libc.so (__thread_entry+72)
I/DEBUG   (  279):     #12  pc 0000d478  /system/lib/libc.so (pthread_create+240)

I also still get this line, now appearing after the seg fault:

W/ActivityManager(  980): Scheduling restart of crashed service com.[company].[app]/com.onesignal.SyncService in 1000ms
jkasten2 commented 7 years ago

@paulmriordan Can you try removing the Kii plugin but leave all the <activity> tag entries in your AndroidManifest.xml? This will determine if the issue is related to the plugin's code or it's configuration on your project.

paulmriordan commented 7 years ago

I have discovered what was causing the problem.

I was using deprecated UnityPlayerProxyActivity & UnityPlayerNativeActivity in my manifest (I first started the project for Unity 4). I have removed these and now use UnityPlayerActivity, and the issue is fixed.

Before:

<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" android:screenOrientation="portrait">
  <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
  </intent-filter>
  <intent-filter>
    <action android:name="PACKAGE_NAME.MESSAGE" />
    <category android:name="android.intent.category.DEFAULT" />
  </intent-filter>
  <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="true" />
</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" android:screenOrientation="portrait">
</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" android:screenOrientation="portrait">
  <meta-data android:name="android.app.lib_name" android:value="unity" />
  <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="true" />
</activity>

After:

<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" android:screenOrientation="portrait">
  <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
  </intent-filter>
  <intent-filter>
    <action android:name="PACKAGE_NAME.MESSAGE" />
    <category android:name="android.intent.category.DEFAULT" />
  </intent-filter>
  <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="true" />
</activity>

Kii can be left as is. That was a bit of red herring. I didn't notice I was using UnityPlayerProxyActivity for the test with kii, and UnityPlayerActivity for the test without.