(This is not a duplicate of other similar questions, as this only happens on a small percentage of users, and can't be recreated by me)
In my latest production release, I suddenly see a huge peak in crashes of type java.lang.VerifyError
coming from a line in my Application
class.
The line is simply:
Settings.init(this);
Where Settings
is a convenience wrapper class around SharedPreferences
. It seems that on less then one percent of users it can't find that class.
We are unable to recreate the crash on any my team's devices, and Google Play's pre-launch report shows 0 errors.
This is the full stack trace:
java.lang.VerifyError:
at com.my_package.MyApplication.onCreate (MyApplication.java:74)
at android.app.Instrumentation.callApplicationOnCreate (Instrumentation.java:1036)
at android.app.ActivityThread.handleBindApplication (ActivityThread.java:6321)
at android.app.ActivityThread.access$1800 (ActivityThread.java:222)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1861)
at android.os.Handler.dispatchMessage (Handler.java:102)
at android.os.Looper.loop (Looper.java:158)
at android.app.ActivityThread.main (ActivityThread.java:7229)
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)
Settings.init
:
public static void init(Context context) {
sPrefs = PreferenceManager.getDefaultSharedPreferences(context);
}
I should add that this issue happened 97% on a single production app version I had, I couldn't recreate this crash running that version, or any version since, but it seems only that version was affected and so far all versions since have almost none of this crash.
However, I'm still seeing crashes in Google Play from that app version, and I worry that it might come back in a future version as well, because I don't think I've changed anything in that version that was in any way related to the stack-trace.
SharedPreferences
object is not ready at the time you are callingSettings.init(this)
in the Application subclassonCreate()
? Are you able to consider lazy initialisation of that object? – ZelaVerifyError
caused by a missing cast (https://mcmap.net/q/1629615/-enums-implementing-interface-are-rejected-by-verifier-java-lang-verifyerror), so maybe you could try something likesPrefs = (SharedPreferences) PreferencesManager.getDefaultSharedPreferences(context);
- there could be a warning of aredundant cast
but just ignore it. That's just an idea.. – Acquittance