java.lang.VerifyError: Verifier rejected class on Lollipop when using release APK

前端 未结 10 2053
渐次进展
渐次进展 2020-12-05 06:22

I get this error when I install my release APK on a 5.x device. The error does not occur when I push the same code from Android Studio, or if I run it on a

10条回答
  •  攒了一身酷
    2020-12-05 07:10

    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
    }
    

提交回复
热议问题