amplify
amplify copied to clipboard
java.lang.IllegalStateException: You must call initSharedInstance before calling getSharedInstance
Got a crash on one customer device.
Amplify: 1.5.1 Android version: Android 6.0 Device: Galaxy A3(2016) (a3xeltekx)
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.alexvas.dvr/com.alexvas.dvr.activity.ManageCamerasActivity}: android.view.InflateException: Binary XML file line #11: Binary XML file line #1: Error inflating class com.github.stkent.amplify.prompt.DefaultLayoutPromptView
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)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: android.view.InflateException: Binary XML file line #11: Binary XML file line #1: Error inflating class com.github.stkent.amplify.prompt.DefaultLayoutPromptView
at android.view.LayoutInflater.inflate(LayoutInflater.java:551)
at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
at android.view.LayoutInflater.inflate(LayoutInflater.java:380)
at android.support.v7.app.m.b(SourceFile:288)
at android.support.v7.app.e.setContentView(SourceFile:140)
at com.alexvas.dvr.activity.ManageCamerasActivity.onCreate(SourceFile:232)
at android.app.Activity.performCreate(Activity.java:6904)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1136)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3266)
... 9 more
Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class com.github.stkent.amplify.prompt.DefaultLayoutPromptView
at android.view.LayoutInflater.createView(LayoutInflater.java:657)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:776)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:966)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:843)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810)
at android.view.LayoutInflater.inflate(LayoutInflater.java:527)
... 17 more
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at android.view.LayoutInflater.createView(LayoutInflater.java:631)
... 22 more
Caused by: java.lang.IllegalStateException: You must call initSharedInstance before calling getSharedInstance.
at com.github.stkent.amplify.b.a.b(SourceFile:101)
at com.github.stkent.amplify.prompt.a.<init>(SourceFile:113)
at com.github.stkent.amplify.prompt.DefaultLayoutPromptView.<init>(SourceFile:52)
at com.github.stkent.amplify.prompt.DefaultLayoutPromptView.<init>(SourceFile:44)
... 24 more
This is the code used for initialising Amplify
DefaultLayoutPromptView promptView
= (DefaultLayoutPromptView) findViewById(R.id.prompt_view);
if (promptView != null) {
promptView.addPromptEventListener(new IEventListener() {
@Override
public void notifyEventTriggered(@NonNull final IEvent event) {
// My code
}
});
Amplify.getSharedInstance().promptIfReady(promptView);
}
@alexeyvasilyev where and how is your Amplify instance initialized?
This may be related to #166 also.
It is initialized in Application class in onCreate() method
Amplify.initSharedInstance(this)
.setFeedbackEmailAddress(getString(R.string.email_support))
.setFeedbackEmailContentProvider(new AmplifyEmailContentProvider())
.setAlwaysShow(Features.isDebug())
.applyAllDefaultRules()
.setLastUpdateTimeCooldownDays(3);
Hmm, this is a real puzzler. That exception is thrown when the DefaultLayoutPromptView is inflated, but I have no idea how that inflation can possibly be occurring before the Application class is created 😕
Are you able to reliably reproduce this locally? I'll have a play with the test app and see if I can force the issue there. I'm guessing if you're only seeing it rarely and in the wild then it's due to the app process being killed to reclaim resources. Do you have any additional data about the customer device that could be relevant (e.g. is it rooted? is it definitely running an app version that includes the latest Amplify version? etc.). Thanks in advance for any info you can provide!
No. Cannot reproduce that at all. No additional data available.
@alexeyvasilyev are you using multi dex in your application?
No.
On Wed, Jul 5, 2017, 15:26 Stuart Kent [email protected] wrote:
Reopened #167 https://github.com/stkent/amplify/issues/167.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/stkent/amplify/issues/167#event-1150808680, or mute the thread https://github.com/notifications/unsubscribe-auth/AA6y3NgI67eJddVAGBwc_rsk07eGjvbJks5sK4EFgaJpZM4L3Hu3 .
-- Best regards, Alex.
No multidex.
Are you still only seeing this crash on a single device, or is it reported on different devices/API levels?
I do not see more crashes.
Ah, interesting; thanks!
Now I am seeing this crash in my application in production version 2.2.1
@yomiyusuf Any clues as to the cause? Does it happen only on specific API levels/specific devices? As you can see from the history of the issue, we had a hard time tracking it down before, so any patterns you can see would be appreciated!
I'm assuming you're using the latest version of the library?
@stkent , thanks for the fast response. I have 3 crashes now within a day Android 9 Samsung Android 8 Huawei Android 6 Redmi
Hmm, weird. Did anything change on your side when these crashes started appearing? Do you know if those devices were rooted or not?
They are not rooted. I just deployed to production. There are thousands of devices. So it means its happening randomly. As far as I can tell
So it's happening at most once per user? Not consistently happening to the same users?
So far, yes, once per user.
Hmm. Could you please try calling Amplify.initSharedInstance(this)... before calling super.onCreate() in your Application subclass? (Based on this suggestion: https://stackoverflow.com/questions/44891750/crash-when-creating-view-that-relies-on-initialized-singleton#comment76764539_44891776). If you are consistently seeing errors right now, and feel comfortable deploying the suggested change to production, it would help a lot in tracking this one down.
@yomiyusuf any update? Did the suggestion last year resolve the crashes?