oppia / oppia-android

A free, online & offline learning platform to make quality education accessible for all.
https://www.oppia.org
Apache License 2.0
315 stars 517 forks source link

Bazel Binary APK frozen on Splash Screen #3810

Closed anandwana001 closed 3 years ago

anandwana001 commented 3 years ago

Describe the bug Launching the testing APK gets frozen on SplashActivity.

To Reproduce Internal Testing

Expected behavior Work smoothly on all devices.

Screenshots If applicable, add screenshots or videos to help explain your problem.

Device

Additional context

2021-09-16 23:30:37.740 I/ActivityTaskManager: START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=org.oppia.android/.app.splash.SplashActivity bnds=[439,80][641,379]} from uid 10064
2021-09-16 23:30:37.747 E/statsd: Predicate 5980654721335871649 dropping data for dimension key (10)0x2010101->10437[I] (10)0x30000->*launch*[S] 
2021-09-16 23:30:37.767 I/ActivityManager: Start proc 3893:org.oppia.android/u0a437 for pre-top-activity {org.oppia.android/org.oppia.android.app.splash.SplashActivity}
2021-09-16 23:30:37.778 E/g.oppia.androi: Not starting debugger since process cannot load the jdwp agent.
2021-09-16 23:30:37.813 W/g.oppia.androi: JIT profile information will not be recorded: profile file does not exist.
2021-09-16 23:30:37.826 I/MultiDex: VM with version 2.1.0 has multidex support
2021-09-16 23:30:37.826 I/MultiDex: Installing application
2021-09-16 23:30:37.826 I/MultiDex: VM has multidex support, MultiDex support library is disabled.
2021-09-16 23:30:37.841 W/DynamiteModule: Local module descriptor class for com.google.android.gms.measurement.dynamite not found.
2021-09-16 23:30:37.841 W/DynamiteModule: Failed to load module via V2: java.lang.NoSuchFieldException: No field sClassLoader in class Lbg/b; (declaration of 'bg.b' appears in /data/app/~~1o1OMvmxLfLRH6EbQQ7Ovg==/org.oppia.android-eHdGVSc-FveRZnY884YTBg==/base.apk)
2021-09-16 23:30:37.853 I/FirebaseCrashlytics: Initializing Crashlytics 17.1.1
2021-09-16 23:30:37.857 I/g.oppia.androi: The ClassLoaderContext is a special shared library.
2021-09-16 23:30:37.864 I/g.oppia.androi: The ClassLoaderContext is a special shared library.
2021-09-16 23:30:37.870 I/FirebaseInitProvider: FirebaseApp initialization successful
2021-09-16 23:30:37.887 I/TetheringManager: registerTetheringEventCallback:org.oppia.android
2021-09-16 23:30:37.902 I/DynamiteModule: Considering local module com.google.android.gms.measurement.dynamite:0 and remote module com.google.android.gms.measurement.dynamite:51
2021-09-16 23:30:37.902 I/DynamiteModule: Selected remote version of com.google.android.gms.measurement.dynamite, version >= 51
anandwana001 commented 3 years ago

Removing the livedata observer on SplashActivityPrsenter fix the issue.

anandwana001 commented 3 years ago

@BenHenning still issue on latest internal testing live app on Android 11.

BenHenning commented 3 years ago

@srushtirk also hit this, and I can now repro on an Android 11 device. I was hoping that #3795 would fix this, but I think it primarily fixed #3817. I found that this seems to only occur in the Proguard-optimized version of the app, and the logs are still unhelpful so I'm iterating locally with extra logs in the app to try and investigate. My best guess is that Android 11 (& 12) might be relying on some new reflection that is being stripped out by Proguard (though I'd expect that to trigger a crash, not a hang).

Interestingly, @srushtirk mentioned that MR2 works fine on her Android 11 device so it does seem like this is somehow tied to the splash screen changes (namely that we're now blocking on both language retrieval & onboarding state to proceed). Will keep this thread updated with my findings.

BenHenning commented 3 years ago

Some new notes:

BenHenning commented 3 years ago

FWIW, the comment above regarding Proguard might actually be more likely than at first glance since MR3 is using custom Proguard rules vs. MR2's Gradle (AGP)-generated ones.

Further, Jetpack's Lifecycle relies on some reflection for certain observers (that leverage the annotations). LiveData isn't one of them, but I wonder if something in the Jetpack components library that ties into LiveData does (which could cause a silent failure rather than a crash depending on how it was implemented). Really weird that this wouldn't repro on other versions of Android, though, given AndroidX isn't part of Android.

I'm working to confirm this one way or another now.

Edit: adding exemptions along the lines of https://stackoverflow.com/a/44688917 (but for AndroidX versions) didn't work, so it's probably not the LiveData<->Proguard situation.

BenHenning commented 3 years ago

Spoke too soon. https://stackoverflow.com/a/59162111 fixes the issue, and I suspect the finding is the actual issue. It seems LifecycleObserver might depend on reflection to verify subscriptions are valid, but it's not clear to me at all why this is an Android 11-specific issue.

BenHenning commented 3 years ago

Aha! This might repro on 28+ per the comment here: https://android.googlesource.com/platform/frameworks/support/+/refs/heads/androidx-master-release/lifecycle/lifecycle-runtime/proguard-rules.pro#18. Just confirming...

Edit: confirming that exact line is the issue (it fixes exactly with that line being present). Simple PR & rebuild coming.

Edit2: for posterity (in case the link above ever breaks), the comment & line of code that fixes this:


# Also this rule prevents registerIn from being inlined.
-keepclassmembers class androidx.lifecycle.ReportFragment$LifecycleCallbacks { *; }```
BenHenning commented 2 years ago

For searching context, this issue was found in 0.6-alpha (MR3).