java.lang.VerifyError in Application class for a small percentage of users
Asked Answered
B

1

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

Biotic answered 1/8, 2017 at 7:17 Comment(14)
Seems like a bug.Check this issuetracker.google.com/issues/38217608Amador
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 ROMsBiotic
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?Zela
the stack shows the error on the Settings class itself, not getting in to the Settings constructor and falling on initialising SharedPreferencesBiotic
Do you mind sharing the piece of code related to Settings.init(this); ?Kendall
@Kendall i've added the method to the question, it's just one line of getting the shared prefs objectBiotic
Okay cool. Is this issue happening with only low (old) APIs phone users ?Kendall
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/phoneSmearcase
Mainly it is due to library issue mismatch build environment https://mcmap.net/q/126604/-causes-of-getting-a-java-lang-verifyerror/2700586Smearcase
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 yearsBiotic
I once had a VerifyError 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 like sPrefs = (SharedPreferences) PreferencesManager.getDefaultSharedPreferences(context); - there could be a warning of a redundant cast but just ignore it. That's just an idea..Acquittance
what SDK version (android & java) are you using to complie the code? do you use any special parameters? Code is obfuscated?Awe
@Toorop: compileSdkVersion=25, targetSdkVersion=23, I use proguard to minimize and obfuscate the code. Also, check out my update with additional info from Google PlayBiotic
@Biotic 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? ThxKillough
K
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.

Karolyn answered 10/8, 2017 at 1:13 Comment(3)
Can you please add an English summary of the problem and possible solutions?Zela
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.Biotic
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 dexKarolyn

© 2022 - 2024 — McMap. All rights reserved.