[TRENDING CRASH] IllegalArgumentException: No view found for id 0x42dc8 (unknown) for fragment
Occurred 17 times over last 7 days in Open Foris Ground 0.1.9 prod on Android 12, 13, and 14 on multiple devices.
Fatal Exception: java.lang.IllegalArgumentException: No view found for id 0x42dc8 (unknown) for fragment DrawAreaTaskMapFragment{3f3486a} (a77cc8b6-7841-4ca9-a1f3-1a66d701904b id=0x42dc8 tag=DrawAreaTaskMapFragment)
at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:567)
at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:286)
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2164)
at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:2059)
at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:2002)
at androidx.fragment.app.FragmentManager$5.run(FragmentManager.java:702)
at android.os.Handler.handleCallback(Handler.java:958)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:230)
at android.os.Looper.loop(Looper.java:319)
at android.app.ActivityThread.main(ActivityThread.java:8913)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:608)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)
Taking a look now, the initial theory is that it's somewhat related to https://github.com/google/ground-android/issues/2493 which was fixed by https://github.com/google/ground-android/pull/2588.
I did do the prime number magic for this type of DrawAreaTaskFragment to mitigate ID collisions:
https://github.com/google/ground-android/blob/ba60ec72b58f246628b6b7a52e0562a63bc20bc8/ground/src/main/java/com/google/android/ground/ui/datacollection/tasks/polygon/DrawAreaTaskFragment.kt#L61
In this case, I don't think adding the prime number offset is necessarily causing the ID to not be looked up properly, since the normal case seems to work ok. Unfortunately, without a repro, it will be difficult to tell what the main cause is, but I have found some sources online that may point to a general cause, due to nested fragments: https://stackoverflow.com/questions/7508044/android-fragment-no-view-found-for-id
Hm.. I can't repro either, but I suspect it's related to restoring the app from the background, since under normal circumstances the TaskMapFragments are created by the our Fragment rather than the FragmentStateManager. I wonder if this is a side effect of #2725?
@sufyanAbbasi @anandwana001 This is still the most common app crash (51 crashes in the last 7 days). Grabbing time to discuss tomorrow @kenstershiro @jabramowitz5 @lecrabe @jo-spek FYI
@anandwana001 Suggested migrating to compose may help, but I noted it will require significant effort to migrate all data collection tasks and the controlling logic over. In the meantime, we should try to stop the crashes ASAP. Assigning to @anandwana001 to take a look.