7

(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.

The statistics I get for this crash

marmor
  • 25,207
  • 10
  • 99
  • 145
  • Seems like a bug.Check this https://issuetracker.google.com/issues/38217608 – Zohra Khan Aug 01 '17 at 08:03
  • I don't think that reported bug is relevant, it's for a custom ROM, I don't imagine so many of my users are users faulty ROMs – marmor Aug 01 '17 at 08:13
  • Could it be that the `SharedPreferences` object is not ready at the time you are calling `Settings.init(this)` in the Application subclass `onCreate()`? Are you able to consider lazy initialisation of that object? – David Rawson Aug 05 '17 at 05:19
  • the stack shows the error on the Settings class itself, not getting in to the Settings constructor and falling on initialising SharedPreferences – marmor Aug 05 '17 at 07:22
  • Do you mind sharing the piece of code related to Settings.init(this); ? – user3793589 Aug 08 '17 at 16:55
  • @user3793589 i've added the method to the question, it's just one line of getting the shared prefs object – marmor Aug 08 '17 at 19:28
  • Okay cool. Is this issue happening with only low (old) APIs phone users ? – user3793589 Aug 08 '17 at 19:58
  • This error happens when you try to access API which is not available in low API phones, I suggest you to check minimum SDK version on manifest file and run the release build on least supported API on emulator/phone – Mani Aug 09 '17 at 02:08
  • Mainly it is due to library issue mismatch build environment https://stackoverflow.com/q/100107/2700586 – Mani Aug 09 '17 at 02:10
  • Thanks, but that's not the issue, (a) it happens on a small number of users, with different and tested api versions (b) it complains about accessing MY class, not Android API (c) this class is not new, been in production for years – marmor Aug 09 '17 at 04:42
  • I once had a `VerifyError` caused by a missing cast (https://stackoverflow.com/a/45170140/3979479), so maybe you could try something like `sPrefs = (SharedPreferences) PreferencesManager.getDefaultSharedPreferences(context);` - there could be a warning of a `redundant cast` but just ignore it. That's just an idea.. – mbo Aug 09 '17 at 08:52
  • what SDK version (android & java) are you using to complie the code? do you use any special parameters? Code is obfuscated? – Toorop Aug 09 '17 at 13:01
  • @Toorop: compileSdkVersion=25, targetSdkVersion=23, I use proguard to minimize and obfuscate the code. Also, check out my update with additional info from Google Play – marmor Aug 09 '17 at 13:28
  • @marmor I'am facing the same issue, I've made couple of new builds but none of them resolved VerifyError that affects only a small percentage of our users. How did you manage to get rid of this problem? You have mentioned that the new versions of your app don't have this problem. Have you made some changes in your build process or updated the libraries? Thx – stevo.mit Feb 23 '18 at 10:27

1 Answers1

0

it's a art code error, it mean can't find some class, you can see this java.lang.VerifyError in Application class for a small percentage of users , this issue sound like the right solution.

LinWei
  • 71
  • 2
  • Can you please add an English summary of the problem and possible solutions? – David Rawson Aug 10 '17 at 01:21
  • thanks, but the link doesn't seem to have a solution, it just says "try again with version 1.8.0" meaning they've fixed it in some version, but don't explain how. – marmor Aug 10 '17 at 07:09
  • the link above say that VerifyError come from this situation: you app has more than one dex, and your Setting class may not be in the first dex (or in the same dex with MyApplication class), so i guess you can try to keep Setting in the first / main dex – LinWei Aug 10 '17 at 07:30