Unity-Technologies / com.unity.mobile.notifications

Mobile Notifications Package
https://docs.unity3d.com/Packages/com.unity.mobile.notifications@2.1/manual/index.html
Other
132 stars 42 forks source link

Resources$NotFound exception on start (Android 7.0) #196

Closed AntonPetrov83 closed 2 years ago

AntonPetrov83 commented 2 years ago

For LG (LG K10, LG K10 Power, LG G5 SE) phones with Android 7 we see:

Fatal Exception: java.lang.RuntimeException: Unable to start receiver com.unity.androidnotifications.UnityNotificationRestartOnBootReceiver: android.content.res.Resources$NotFoundException: failed to add asset path /data/app/com.colossi.survival.gladiators-2/base.apk
       at android.app.ActivityThread.handleReceiver(ActivityThread.java:3152)
       at android.app.ActivityThread.-wrap18(ActivityThread.java)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1612)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:154)
       at android.app.ActivityThread.main(ActivityThread.java:6312)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:872)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762)

Caused by android.content.res.Resources$NotFoundException: failed to add asset path /data/app/com.colossi.survival.gladiators-2/base.apk
       at android.app.ResourcesManager.createAssetManager(ResourcesManager.java:267)
       at android.app.ResourcesManager.createResourcesImpl(ResourcesManager.java:324)
       at android.app.ResourcesManager.getOrCreateResources(ResourcesManager.java:585)
       at android.app.ResourcesManager.getResources(ResourcesManager.java:659)
       at android.app.ActivityThread.getTopLevelResources(ActivityThread.java:1918)
       at android.app.LoadedApk.getResources(LoadedApk.java:812)
       at android.app.ContextImpl.<init>(ContextImpl.java:2043)
       at android.app.ContextImpl.createApplicationContext(ContextImpl.java:1817)
       at android.content.ContextWrapper.createApplicationContext(ContextWrapper.java:792)
       at android.content.ContextWrapper.createApplicationContext(ContextWrapper.java:792)
       at android.app.Notification$Builder.recoverBuilder(Notification.java:3806)
       at com.unity.androidnotifications.UnityNotificationUtilities.recoverBuilder(UnityNotificationUtilities.java:517)
       at com.unity.androidnotifications.UnityNotificationManager.loadSavedNotifications(UnityNotificationManager.java:499)
       at com.unity.androidnotifications.UnityNotificationRestartOnBootReceiver.rescheduleSavedNotifications(UnityNotificationRestartOnBootReceiver.java:26)
       at com.unity.androidnotifications.UnityNotificationRestartOnBootReceiver.onReceive(UnityNotificationRestartOnBootReceiver.java:21)
       at android.app.ActivityThread.handleReceiver(ActivityThread.java:3141)
       at android.app.ActivityThread.-wrap18(ActivityThread.java)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1612)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:154)
       at android.app.ActivityThread.main(ActivityThread.java:6312)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:872)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762)

And for HUAWEI phones with Android 7.0 too:

Fatal Exception: java.lang.RuntimeException: Unable to start receiver com.unity.androidnotifications.UnityNotificationManager: android.content.res.Resources$NotFoundException: failed to add asset path /data/app/com.colossi.survival.gladiators-2/base.apk
       at android.app.ActivityThread.handleReceiver(ActivityThread.java:3184)
       at android.app.ActivityThread.-wrap18(ActivityThread.java)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1653)
       at android.os.Handler.dispatchMessage(Handler.java:105)
       at android.os.Looper.loop(Looper.java:156)
       at android.app.ActivityThread.main(ActivityThread.java:6523)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:941)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:831)

Caused by android.content.res.Resources$NotFoundException: failed to add asset path /data/app/com.colossi.survival.gladiators-2/base.apk
       at android.app.ResourcesManager.createAssetManager(ResourcesManager.java:275)
       at android.app.ResourcesManager.createResourcesImpl(ResourcesManager.java:332)
       at android.app.ResourcesManager.getOrCreateResources(ResourcesManager.java:612)
       at android.app.ResourcesManager.getResources(ResourcesManager.java:690)
       at android.app.ActivityThread.getTopLevelResources(ActivityThread.java:1989)
       at android.app.LoadedApk.getResources(LoadedApk.java:799)
       at android.app.ContextImpl.<init>(ContextImpl.java:2217)
       at android.app.ContextImpl.createApplicationContext(ContextImpl.java:1986)
       at android.content.ContextWrapper.createApplicationContext(ContextWrapper.java:792)
       at android.content.ContextWrapper.createApplicationContext(ContextWrapper.java:792)
       at android.app.Notification$Builder.recoverBuilder(Notification.java:3961)
       at com.unity.androidnotifications.UnityNotificationUtilities.recoverBuilder(UnityNotificationUtilities.java:517)
       at com.unity.androidnotifications.UnityNotificationManager.getNotificationOrBuilderForIntent(UnityNotificationManager.java:844)
       at com.unity.androidnotifications.UnityNotificationManager.onReceive(UnityNotificationManager.java:641)
       at android.app.ActivityThread.handleReceiver(ActivityThread.java:3177)
       at android.app.ActivityThread.-wrap18(ActivityThread.java)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1653)
       at android.os.Handler.dispatchMessage(Handler.java:105)
       at android.os.Looper.loop(Looper.java:156)
       at android.app.ActivityThread.main(ActivityThread.java:6523)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:941)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:831)
dhamelin commented 2 years ago

I'm seeing a lot of this crash too (in Play Console) and always on Android 7.0

AntonPetrov83 commented 2 years ago

@dhamelin I have included com.unity.mobile.notifications source files to the project and added try-catch here:

    protected static Notification.Builder recoverBuilder(Context context, Notification notification) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            try {
                Notification.Builder builder = Notification.Builder.recoverBuilder(context, notification);
                // extras not recovered, transfer manually
                builder.setExtras(notification.extras);
                return builder;
            } catch (Exception e) {
                Log.e(TAG_UNITY, "Failed to recover builder", e);
            } catch (OutOfMemoryError e) {
                Log.e(TAG_UNITY, "Failed to recover builder", e);
            }

            return null;
        }
        else {
            return recoverBuilderPreNougat(context, notification);
        }
    }

I will confirm that it works in Production in a couple of days.

korober commented 2 years ago

Same issues for my users, common conditions: Android 7 & Device Vendor: Samsung

java.lang.RuntimeException: at android.app.ActivityThread.handleReceiver (ActivityThread.java:3366) at android.app.ActivityThread.-wrap20 (ActivityThread.java) at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1723) at android.os.Handler.dispatchMessage (Handler.java:102) at android.os.Looper.loop (Looper.java:154) at android.app.ActivityThread.main (ActivityThread.java:6780) at java.lang.reflect.Method.invoke (Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1496) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1386) Caused by: android.content.res.Resources$NotFoundException: at android.app.ResourcesManager.createAssetManager (ResourcesManager.java:281) at android.app.ResourcesManager.createResourcesImpl (ResourcesManager.java:359) at android.app.ResourcesManager.getOrCreateResources (ResourcesManager.java:638) at android.app.ResourcesManager.getResources (ResourcesManager.java:730) at android.app.ActivityThread.getTopLevelResources (ActivityThread.java:2049) at android.app.LoadedApk.getResources (LoadedApk.java:787) at android.app.ContextImpl. (ContextImpl.java:2266) at android.app.ContextImpl.createApplicationContext (ContextImpl.java:1946) at android.content.ContextWrapper.createApplicationContext (ContextWrapper.java:881) at android.content.ContextWrapper.createApplicationContext (ContextWrapper.java:881) at android.app.Notification$Builder.recoverBuilder (Notification.java:3885) at com.unity.androidnotifications.UnityNotificationUtilities.recoverBuilder at com.unity.androidnotifications.UnityNotificationManager.loadSavedNotifications (UnityNotificationManager.java) at com.unity.androidnotifications.UnityNotificationRestartOnBootReceiver.rescheduleSavedNotifications at com.unity.androidnotifications.UnityNotificationRestartOnBootReceiver.onReceive at android.app.ActivityThread.handleReceiver (ActivityThread.java:3359) at android.app.ActivityThread.-wrap20 (ActivityThread.java) at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1723) at android.os.Handler.dispatchMessage (Handler.java:102) at android.os.Looper.loop (Looper.java:154) at android.app.ActivityThread.main (ActivityThread.java:6780) at java.lang.reflect.Method.invoke (Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1496) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1386)

dhamelin commented 2 years ago

@dhamelin I have included com.unity.mobile.notifications source files to the project and added try-catch here:

    protected static Notification.Builder recoverBuilder(Context context, Notification notification) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            try {
                Notification.Builder builder = Notification.Builder.recoverBuilder(context, notification);
                // extras not recovered, transfer manually
                builder.setExtras(notification.extras);
                return builder;
            } catch (Exception e) {
                Log.e(TAG_UNITY, "Failed to recover builder", e);
            } catch (OutOfMemoryError e) {
                Log.e(TAG_UNITY, "Failed to recover builder", e);
            }

            return null;
        }
        else {
            return recoverBuilderPreNougat(context, notification);
        }
    }

I will confirm that it works in Production in a couple of days.

Thanks for that. I have just pushed an update including this. I will keep you posted once more players have adopted this version and have played with it a bit.

AntonPetrov83 commented 2 years ago

@dhamelin Hi! I confirm that this worked for us, no more crashes like that.

vaidasma commented 2 years ago

Also reproducible on Samsung Galaxy s8 (OS:7):

2022/06/21 15:47:34.156 5360 5423 Info Unity Unity.Notifications.Tests.Sample.SafeArea:Awake () (at /Users/vaidasm/Documents/GitHub/com.unity.mobile.notifications/TestProjects/com.unity.mobil 2022/06/21 15:47:34.435 5360 5423 Warn System ClassLoader referenced unknown path: 2022/06/21 15:47:34.435 5360 5423 Warn System ClassLoader referenced unknown path: /data/app/com.unity3d.mobilenotificationtests-1/lib/arm 2022/06/21 15:47:34.436 5360 5423 Warn linker Warning: unable to resolve "/data/app/com.unity3d.mobilenotificationtests-1/base.apk": No such file or directory 2022/06/21 15:47:34.437 5360 5423 Warn asset Asset path /data/app/com.unity3d.mobilenotificationtests-1/base.apk is neither a directory nor file (type=1). 2022/06/21 15:47:34.495 5360 5423 Error Unity AndroidJavaException: android.content.res.Resources$NotFoundException: failed to add asset path /data/app/com.unity3d.mobilenotificationtests-1/base.apk 2022/06/21 15:47:34.495 5360 5423 Error Unity android.content.res.Resources$NotFoundException: failed to add asset path /data/app/com.unity3d.mobilenotificationtests-1/base.apk 2022/06/21 15:47:34.495 5360 5423 Error Unity at android.app.ResourcesManager.createAssetManager(ResourcesManager.java:281) 2022/06/21 15:47:34.495 5360 5423 Error Unity at android.app.ResourcesManager.createResourcesImpl(ResourcesManager.java:359) 2022/06/21 15:47:34.495 5360 5423 Error Unity at android.app.ResourcesManager.getOrCreateResources(ResourcesManager.java:638) 2022/06/21 15:47:34.495 5360 5423 Error Unity at android.app.ResourcesManager.getResources(ResourcesManager.java:730) 2022/06/21 15:47:34.495 5360 5423 Error Unity at android.app.ActivityThread.getTopLevelResources(ActivityThread.java:2052) 2022/06/21 15:47:34.495 5360 5423 Error Unity at android.app.LoadedApk.getResources(LoadedApk.java:787) 2022/06/21 15:47:34.495 5360 5423 Error Unity at android.app.ContextImpl.(ContextImpl.java:2266) 2022/06/21 15:47:34.495 5360 5423 Error Unity at android.app.ContextImpl.createApplicationContext(ContextImpl.java:1946) 2022/06/21 15:47:34.495 5360 5423 Error Unity at android.content.ContextWrapper.createApplicationContext(ContextWrapper.java:881) 2022/06/21 15:47:34.495 5360 5423 Error Unity at android.app.Notification$Builder.recoverBuilder(Notification.java: 2022/06/21 15:47:34.506 5360 5423 Info sensor ASensorEventQueue_enableSensor: handle=1, name=LSM6DSL Accelerometer, ret=0

aurimasc commented 2 years ago

Fixed in master.

Bruno-LKWD commented 2 years ago

Still seeing this on 2.0.2 and Unity 2020.3.34f1:

java.lang.RuntimeException: 
  at android.app.ActivityThread.handleReceiver (ActivityThread.java:3107)
  at android.app.ActivityThread.-wrap18 (ActivityThread.java)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1611)
  at android.os.Handler.dispatchMessage (Handler.java:110)
  at android.os.Looper.loop (Looper.java:203)
  at android.app.ActivityThread.main (ActivityThread.java:6251)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1063)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:924)
Caused by: android.content.res.Resources$NotFoundException: 
  at android.app.ResourcesManager.createAssetManager (ResourcesManager.java:253)
  at android.app.ResourcesManager.createResourcesImpl (ResourcesManager.java:310)
  at android.app.ResourcesManager.getOrCreateResources (ResourcesManager.java:571)
  at android.app.ResourcesManager.getResources (ResourcesManager.java:645)
  at android.app.ActivityThread.getTopLevelResources (ActivityThread.java:1920)
  at android.app.LoadedApk.getResources (LoadedApk.java:771)
  at android.app.ContextImpl.<init> (ContextImpl.java:2059)
  at android.app.ContextImpl.createApplicationContext (ContextImpl.java:1828)
  at android.content.ContextWrapper.createApplicationContext (ContextWrapper.java:792)
  at android.content.ContextWrapper.createApplicationContext (ContextWrapper.java:792)
  at android.app.Notification$Builder.recoverBuilder (Notification.java:3803)
  at com.unity.androidnotifications.UnityNotificationUtilities.recoverBuilder (UnityNotificationUtilities.java:517)
  at com.unity.androidnotifications.UnityNotificationManager.loadSavedNotifications (UnityNotificationManager.java:519)
  at com.unity.androidnotifications.UnityNotificationRestartOnBootReceiver.rescheduleSavedNotifications (UnityNotificationRestartOnBootReceiver.java:26)
  at com.unity.androidnotifications.UnityNotificationRestartOnBootReceiver.onReceive (UnityNotificationRestartOnBootReceiver.java:21)
  at android.app.ActivityThread.handleReceiver (ActivityThread.java:3100)

Saw some information about adding a string.xml https://stackoverflow.com/a/56461957, but this looks really outdated.