Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

java.lang.InstantiationException Xamarin Forms Android Crash on start-up Error Debug R8 / ProGuard

Noobxamarin103Noobxamarin103 Member ✭✭
edited October 6 in Xamarin.Forms

Hi All
My app keeps crashing and i cant figure out how to properly debug. It's been released to the play store and I'm seeing numerous crashes and reports with the error java.lang.InstantiationException on the Play store.

Screenshot of the error is here.

I have a feeling its to do with the R8/ Proguard configuration but cannot nail down which class is causing the error or how to properly debug. I have tried Device-Logcat within Visual studio but that does not display the error. Starting the app in debug mode loads the app and just quits so no help there.

The error message is not helpful at all, and I do not want to disable PROGUARD/R8 as it helps with APK size and obfuscation.

Any ideas?

Answers

  • JohnHardmanJohnHardman GBUniversity admin

    @Noobxamarin103

    Is there a pattern in which Android versions are being used on the devices where the exception is happening? If it's old Android versions, then it's likely that your app is using an API that isn't supported on those older Android versions.

  • Noobxamarin103Noobxamarin103 Member ✭✭

    Hi John.
    Nope, its occurring for all android devices. Its intermittent which is driving me nuts. I use android 10 and it sometimes happens there. I've attached my proguard-custom.cfg file.

    Is there any way for me to accurately debug this? I just cant reproduce the error or get an accurate error message?

    -keep public class com.bugsee.library.send.SendBundleActivity
    -keep public class com.google.firebase.iid.FirebaseInstanceIdReceiver
    -keep public class com.google.firebase.messaging.FirebaseMessagingService
    -keep public class com.google.firebase.iid.FirebaseInstanceIdService
    -keep public class com.onesignal.OneSignal
    -keep class android.support.v7.widget.FitWindowsFrameLayout { *; }
    -dontwarn android.support.v7.widget.FitWindowsFrameLayout
    -keep class androidx.appcompat.widget.FitWindowsFrameLayout { *; }
    -dontwarn androidx.appcompat.widget.FitWindowsFrameLayout
    -keep class android.support.design.** { *; }
    -keep class android.support.multidex.MultiDexApplication { *; }
    -keep class androidx.multidex.MultiDexApplication { *; }
    -keep class android.support.design.internal.BaselineLayout { *; }
    -dontwarn android.support.design.internal.BaselineLayout
    -keep class com.google.android.material.internal.BaselineLayout { *; }
    -dontwarn com.google.android.material.internal.BaselineLayout
    -keep class com.google.firebase.provider.FirebaseInitProvider { *; }
    -keep class androidx.appcompat.widget.AlertDialogLayout { *; }
    -keep class androidx.appcompat.widget.DialogTitle { *; }
    -keep class androidx.appcompat.widget.ButtonBarLayout { *; }
    -keep class android.support.v7.widget.AlertDialogLayout { *; }
    -keep class android.support.v7.widget.DialogTitle { *; }
    -keep class android.support.v7.widget.ButtonBarLayout { *; }
    -keep class android.support.v7.widget.FitWindowsLinearLayout { *; }
    -dontwarn android.support.v7.widget.FitWindowsLinearLayout

  • JohnHardmanJohnHardman GBUniversity admin

    @Noobxamarin103 said:
    Hi John.
    Nope, its occurring for all android devices. Its intermittent which is driving me nuts.

    Just to confirm - when you say that it's intermittent, you mean that it sometimes works on a device and sometimes fails on that same device? If that's the case, it's not just a Linker or Proguard problem (assuming that's what it is), but also a question of why there are different execution paths at startup. Is it that it fails when started from a notification, but is fine when started from the start icon? If you can identify the reason for the different paths, it might help with debugging.

  • Noobxamarin103Noobxamarin103 Member ✭✭

    Yes exactly. Sometimes works and then sometimes fails on that device. Not sure on the different execution paths. Works when clicking on a notification.
    The work around I've given to users is that they need to clear 'Data' and clear 'cache' from within settings in android. Are you starting to think its not an error with proguard at all?
    Thanks for your help on this.

  • LeonLuLeonLu Member, Xamarin Team Xamurai

    It is hard to re-produce this issue and it is hard to assume this issue, I suggest you to open an support ticket(not free) for this issue.

    https://support.serviceshub.microsoft.com/supportforbusiness/onboarding?origin=/supportforbusiness/create?sapId=211dd84f-3474-c3c5-79bf-66db630c92a6

  • JohnHardmanJohnHardman GBUniversity admin

    @Noobxamarin103 said:
    Yes exactly. Sometimes works and then sometimes fails on that device. Not sure on the different execution paths. Works when clicking on a notification.
    The work around I've given to users is that they need to clear 'Data' and clear 'cache' from within settings in android. Are you starting to think its not an error with proguard at all?
    Thanks for your help on this.

    If clearing the data and cache makes a difference, then that should give you a clue as to what execution paths in your startup code to check. If no cached data works, but starting with cached data fails, then debug the path that uses cached data on startup. It is likely that somewhere on that path a call is being made to a method that the Linker or ProGuard has removed. No guarantees, but that's what it sounds like based on what you have said.

Sign In or Register to comment.