java.lang.VerifyError: Verifier rejected class on Lollipop when using release APK
Cleaning out the build
folder resolved the problem. Not sure why ART had an issue but Dalvik did not.
Running a gradle clean
task was not clearing out my build
folder all the way. I had to do it manually, but clean
may work for some people.
In my case, the cause was slightly different.
Apparently, putting a synchronized
statement inside a try/catch
block causes the VerifyError
, as reported here on SO and on the official bug tracker.
In my case the method that the error message said was 'bad', had some unknown faults. Changing from a Kotlin lambda to a regular loop solved my issue.
Before (With Error):
fun validZipCode(zipcode: String): Boolean {
val validRegexes = arrayOf(
"0[0-9]{1}[0-9]{2}",
"1[0-2]{1}[0-9]{2}",
"1[3-4]{1}[0-9]{2}",
"19[0-9]{2}",
"2[0-1]{1}[0-9]{2}"
)
return validRegexes.any { zipcode.matches(it.toRegex()) }
After:
fun validZipCode(zipcode: String): Boolean {
val validRegexes = arrayOf(
"0[0-9]{1}[0-9]{2}",
"1[0-2]{1}[0-9]{2}",
"1[3-4]{1}[0-9]{2}",
"19[0-9]{2}",
"2[0-1]{1}[0-9]{2}"
)
for (regex in validRegexes) {
if (zipcode.matches(regex.toRegex())) {
return true
}
}
return false
}