microsoft / appcenter-sdk-android

Development repository for the App Center SDK for Android
Other
277 stars 134 forks source link

NullPointerException on app resume #1610

Closed kvpt closed 2 years ago

kvpt commented 2 years ago

Description

We have a lot of crashs in the last update of our application, and this seems to come from AppCenter SDK.

Java.Lang.NullPointerException: Attempt to invoke interface method 'boolean android.content.SharedPreferences.getBoolean(java.lang.String, boolean)' on a null object reference at void Java.Interop.JniEnvironment+InstanceMethods.CallNonvirtualVoidMethod(JniObjectReference instance, JniObjectReference type, JniMethodInfo method, JniArgumentValue args) at void Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualVoidMethod(string encodedMember, IJavaPeerable self, JniArgumentValue parameters) at void Android.App.Activity.OnResume() at void Xamarin.Forms.Platform.Android.FormsAppCompatActivity.OnResume() at void Mobile.App.Droid.MainActivity.OnResume() at void Android.App.Activity.n_OnResume(IntPtr jnienv, IntPtr native__this) at java.lang.NullPointerException: Attempt to invoke interface method 'boolean android.content.SharedPreferences.getBoolean(java.lang.String, boolean)' on a null object reference at com.microsoft.appcenter.utils.storage.SharedPreferencesManager.getBoolean(Unknown Source:2) at com.microsoft.appcenter.AbstractAppCenterService.isInstanceEnabled(Unknown Source:6) at com.microsoft.appcenter.distribute.Distribute.registerReceiver(Unknown Source:1) at com.microsoft.appcenter.distribute.Distribute.onActivityResumed(Unknown Source:10) at android.app.Application.dispatchActivityResumed(Application.java:455) at android.app.Activity.dispatchActivityResumed(Activity.java:1413) at android.app.Activity.onResume(Activity.java:1945) at androidx.fragment.app.FragmentActivity.onResume(Unknown Source:0) at crc642f107985f75a869d.MainActivity.n_onResume(Native Method) at crc642f107985f75a869d.MainActivity.onResume(Unknown Source:0) at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1456) at android.app.Activity.performResume(Activity.java:8353) at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4897) at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4944) at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:52) at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2325) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:246) at android.app.ActivityThread.main(ActivityThread.java:8633) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)

Repro Steps

Nothing special, the app randomly crash on resume

Details

  1. Which SDK version are you using?
    • DotNet 4.5, Android 4.4.2 ?
  2. Which OS version did you experience the issue on?
    • No specific version
  3. What device version did you see this error on? Were you using an emulator or a physical device?
    • No specific device
  4. What third party libraries are you using?
    • Xamarin Forms
  5. Please enable verbose logging for your app using AppCenter.setLogLevel(Log.VERBOSE) before your call to AppCenter.start(...) and include the logs here:
DmitriyKirakosyan commented 2 years ago

Hi @kvpt , thank you for bringing this issue to our attention!

Can you please share verbose logs? Also, could you list the changes in your app in the last update and check if anything could potentially trigger this issue?

kvpt commented 2 years ago

Hi,

For this version the log level is on default level I will enable the verbose log in the next version to debug that.

For the changes, The Microsoft.AppCenter nuget packages has been passed from 4.4.0 to 4.5.0 and the Xamarin Android target Framework as been passed from version 11 to 12 (api 30 to 31).

Another information that I discovered is that all the crashs are triggered at the launch because all crashs occurred after 0 or 1 second.

I tried to reproduce it locally but failed to trigger the issue, but I have a theory.

It's an enterprise app deployed on a fleet of phones, certain phones are enrolled in a central management tool that also can deploy the application. Is it possible that if the application is deployed by another app than AppCenter this bypass the init of the SharedPreferences and when app start it crash ?

DmitriyKirakosyan commented 2 years ago

Hi @kvpt , thank you for the details! I'll mark it as a bug. Please let us know when you get verbose logs. I've found a similar issue https://github.com/microsoft/appcenter-sdk-android/issues/929, might be related.

DmitriyKirakosyan commented 2 years ago

The fix has been released! I'm closing the issue, but feel free to reopen if you face it again.