Crash reports caused by android.app.Fragment$InstantiationException

Hi to all,
Lately I’m checking the issues that our game has on several android devices and I’m checking all the data reported by Android Vitals in the Google Play Console.

I found that a lot of crashes were due to a java.lang.RuntimeException and Caused by: android.app.Fragment$InstantiationException:
this is a sample of what the data looks like.

java.lang.RuntimeException:
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2440)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2500)
at android.app.ActivityThread.access$900(ActivityThread.java:163)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1362)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5585)
at java.lang.reflect.Method.invoke(Native Method:0)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
Caused by: android.app.Fragment$InstantiationException:
at android.app.Fragment.instantiate(Fragment.java:628)
at android.app.FragmentState.instantiate(Fragment.java:106)
at android.app.FragmentManagerImpl.restoreAllState(FragmentManager.java:1858)
at android.app.FragmentController.restoreAllState(FragmentController.java:122)
at android.app.Activity.onCreate(Activity.java:919)
at com.unity3d.player.UnityPlayerActivity.onCreate(Unknown Source:0)
at com.unity3d.player.UnityPlayerNativeActivity.onCreate(Unknown Source:0)
at android.app.Activity.performCreate(Activity.java:6279)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2393)

The version of Unity3D is 5.6.0f3 and all the crashes (so far) are on Android 6.0 devices.
Supported OpenGL Version reported by Internals goes from OpenGL ES 2.0 to ES 3.1.

Unfortunately:

  • I do not experience crashes on the devices I use for testing so I haven’t a logcat or can’t replicate the bug.
  • I’m not expert of Unity3D internals so I do not know what I may do wrong. Seems it’s a crash during the startup phase. Seems it is ‘fragment’ creation but what can I check to pinpoint the problem? I don’t see any common factor in the 100+ crash reports (all RuntimeException in Fragment$InstantiationException).

What can I do to solve a bug like this?

No one has any idea?
What I’m supposed to do? Update Unity version and pray?

I saw a crash with one of my apps reported on the Google Play Console with this same exception reported. It is an older app of mine built with Unity 4.6 and I have never seen a crash reported until now. Therefore, I am thinking this is not a straightforward update-Unity problem but something specific to a device or an Android version. I have no solution but I wanted to provide my info

crash occurred on: Android 7.0
Device: Galaxy Note5 (noblelte)
Native platform armeabi-v7a
OpenGL ES version 3.1
CPU make Samsung
CPU model Exynos 7420

Here is my exception log that the Google Play console provided me:

java.lang.RuntimeException:
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2927)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988)
at android.app.ActivityThread.-wrap14(ActivityThread.java:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Native Method:0)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
Caused by: android.app.Fragment$InstantiationException:
at android.app.Fragment.instantiate(Fragment.java:637)
at android.app.FragmentState.instantiate(Fragment.java:111)
at android.app.FragmentManagerImpl.restoreAllState(FragmentManager.java:1946)
at android.app.FragmentController.restoreAllState(FragmentController.java:136)
at android.app.Activity.onCreate(Activity.java:1037)
at android.app.NativeActivity.onCreate(NativeActivity.java:185)
at com.unity3d.player.UnityPlayerNativeActivity.onCreate(Unknown Source:0)
at android.app.Activity.performCreate(Activity.java:6942)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2880)

Any solution? It’s same here +1.
We use unity3d 5.6.1p2, crash on Android 6.0 devices.

Galaxy J7(2016) (j7xelte) 27 5.5%
Galaxy J5 Prime (on5xelte) 26 5.3%
Galaxy J2 Prime (grandpplte) 25 5.1%
Galaxy J7 (j7elte) 20 4.1%
Other 389 79.9%

java.lang.RuntimeException:
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.access$900(ActivityThread.java:150)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
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:0)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.app.Fragment$InstantiationException:
at android.app.Fragment.instantiate(Fragment.java:628)
at android.app.FragmentState.instantiate(Fragment.java:106)
at android.app.FragmentManagerImpl.restoreAllState(FragmentManager.java:1858)
at android.app.FragmentController.restoreAllState(FragmentController.java:122)
at android.app.Activity.onCreate(Activity.java:923)
at com.unity3d.player.UnityPlayerActivity.onCreate(Unknown Source:0)
at com.atom.utils.atomapp.AtomAppUtil.onCreate(AtomAppUtil.java:91)
at android.app.Activity.performCreate(Activity.java:6285)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)

any update?

We have got the same problem on wide rangle Android 6.0 devices:

java.lang.RuntimeException:
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3319)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3415)
at android.app.ActivityThread.access$1100(ActivityThread.java:229)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7325)
at java.lang.reflect.Method.invoke(Native Method:0)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: android.app.Fragment$InstantiationException:
at android.app.Fragment.instantiate(Fragment.java:642)
at android.app.FragmentState.instantiate(Fragment.java:114)
at android.app.FragmentManagerImpl.restoreAllState(FragmentManager.java:1880)
at android.app.FragmentController.restoreAllState(FragmentController.java:123)
at android.app.Activity.onCreate(Activity.java:1048)
at com.unity3d.player.UnityPlayerActivity.onCreate(Unknown Source:0)
at android.app.Activity.performCreate(Activity.java:6904)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1136)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3266)

Do you use plugins in your application?

Hi,

Anyone an update?

Same here. Android 6.0 only. Wide range of devices.

We are using Chartboost, Applovin, Google Mobile ads and a few other like UTNOtificationmanager and some of our own plugings.

I’ve seen it happening. It is during the start of the app. The good news is that it doesn’t really crash the app, although google play tells us so. But… as we all know google provides information with a reason. Therefore we try to minimize the number of crashes, as it probably is, a minor, factor for ranking.

java.lang.RuntimeException:
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2423)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2483)
at android.app.ActivityThread.access$900(ActivityThread.java:157)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1351)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5476)
at java.lang.reflect.Method.invoke(Native Method:0)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.app.Fragment$InstantiationException:
at android.app.Fragment.instantiate(Fragment.java:628)
at android.app.FragmentState.instantiate(Fragment.java:106)
at android.app.FragmentManagerImpl.restoreAllState(FragmentManager.java:1858)
at android.app.FragmentController.restoreAllState(FragmentController.java:122)
at android.app.Activity.onCreate(Activity.java:923)
at com.unity3d.player.UnityPlayerActivity.onCreate(Unknown Source:0)
at android.app.Activity.performCreate(Activity.java:6285)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2376)

I am seeing the same “Caused by: android.app.Fragment$InstantiationException:” crash the last weeks increasing.

Build using unity 4.7.1

We have received same crash reports on Android 7.0 at this week:

java.lang.RuntimeException:
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:159)
at android.app.ActivityThread.main(ActivityThread.java:6097)
at java.lang.reflect.Method.invoke(Native Method:0)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: android.app.Fragment$InstantiationException:
at android.app.Fragment.instantiate(Fragment.java:637)
at android.app.FragmentState.instantiate(Fragment.java:111)
at android.app.FragmentManagerImpl.restoreAllState(FragmentManager.java:1942)
at android.app.FragmentController.restoreAllState(FragmentController.java:135)
at android.app.Activity.onCreate(Activity.java:982)
at com.unity3d.player.UnityPlayerActivity.onCreate(Unknown Source:0)
at android.app.Activity.performCreate(Activity.java:6743)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)

I’ve already asked this question on SO.

Exception occurs when the UnityPlayer creates its main activity. This could happen if the game was just started, or if the user switches between apps and then goes back to the game (for example tapped on advertisement, goes to the PlayMarket and then goes back). I am using 3rd party advertisement engine from Appodeal. Recently I contacted them and asked about this exception pointing out to native plugins for different ad networks. They did some research and told me that they found no connection with native plugins.

This exception shows that onCreate method of activity class is called with non null parameter savedInstanceState. That’s why android trying reinitialize fragments from the saved states.
According to the docs:

From the source code:

if (savedInstanceState != null) {
            Parcelable p = savedInstanceState.getParcelable(FRAGMENTS_TAG);
            mFragments.restoreAllState(p, mLastNonConfigurationInstances != null
                    ? mLastNonConfigurationInstances.fragments : null);
        }

All my users are suffer on Android 6 devices. All apk builds are made up with Unity 5.5.03f. I have several devices with Android 6 and I cannot reproduce this crush/error on any of them.

This is really frustrating bug.

Finally! I am able to reproduce this error! And as I thought from the beginning this is about permissions, sort of :slight_smile:

On the modern devices user being asked about runtime permissions. UnityPlayer at startup checks for permissions and displays dialog for each of them. Unity Player has a class which subclassed from Fragment for this purposes.

Fragment:
According to the docs:

InstantiationException:
According to the docs:

UnityPlayer:
From the decompiled source code of UnityPlayer:

final class d$1
  extends Fragment
{
  d$1(d paramd, List paramList, FragmentManager paramFragmentManager, Runnable paramRunnable) {}
  // Other code is skipped for readability ...
}

As you can see there is just one constructor WITH parameters.

To reproduce this error you have to kill and restore activity while there is a dialog box asking for granting permission. I dont know why players do such things, may be they switch to another app and come back later when OS already killed game thread and trying to recreate it again with saved state for last visible fragment.

Anyway, according to Google documentation UnityPlayer has incorrect implementation of subclassed Fragment class. I understand this is rare situation, but still it has to be fixed somehow.

4 Likes

We have a couple of these in the Play Store crash report as well.

Has anyone submitted the bug to Unity Issue Tracker?

Receiving a lot of these crashes in my Google Play Store - though I can’t seem to replicate on my own tests.

java.lang.RuntimeException:

at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:3256)

at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3352)

at android.app.ActivityThread.access$1100 (ActivityThread.java:223)

at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1797)

at android.os.Handler.dispatchMessage (Handler.java:102)

at android.os.Looper.loop (Looper.java:158)

at android.app.ActivityThread.main (ActivityThread.java:7231)

at java.lang.reflect.Method.invoke (Native Method)

at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1230)

at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1120)
Caused by: android.app.Fragment$InstantiationException:

at android.app.Fragment.instantiate (Fragment.java:642)

at android.app.FragmentState.instantiate (Fragment.java:114)

at android.app.FragmentManagerImpl.restoreAllState (FragmentManager.java:1880)

at android.app.FragmentController.restoreAllState (FragmentController.java:123)

at android.app.Activity.onCreate (Activity.java:1036)

at com.unity3d.player.UnityPlayerActivity.onCreate (Unknown Source)

at android.app.Activity.performCreate (Activity.java:6877)

at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1136)

at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:3209)

Could this have something to do with Everyplay - as it started to happen after installing that?

I did. But unfortunately the guys from Unity cannot reproduce it on they own.

Can someone post devices names from the crash logs?
I’ve sent some names to QA team but they want more …

Here is the list from google play console for my game:

Zmax Pro (urd)
Galaxy J7 (j7e3g)
Redmi Note 4 (nikel)
LG K10 LTE (m253)
Galaxy J5 (j5lte)
Galaxy Tab E 8.0 (gtesltevzw)
LG G Stylo (g4stylusc)

All running Android 6

Thanks.

A little bit of updates:

  1. I haven’t heard from Unity QA team for a while, so I think they won’t do anything.
  2. I have tested my concerns about incorrect implementation of Fragment and it worked. Besides of empty constructor I have made some other corrections to d$1 class - so far fragment instantiation goes well without crashes.

The main question is still open - why dont they fix it? It is quite simple.

Hi there!

Can you please upload the files you modified, so we can also take a look and try it out? Still crash free on this?

Thanks!