56

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 4.x device.

java.lang.VerifyError: Verifier rejected class com.myapp.android.ui.activity.MainActivity$$ViewInjector due to bad method void com.myapp.android.ui.activity.MainActivity$$ViewInjector.reset(com.myapp.android.ui.activity.MainActivity) (declaration of 'com.myapp.android.ui.activity.MainActivity$$ViewInjector' appears in /data/app/com.myapp.android-2/base.apk)
       at java.lang.Class.classForName(Class.java)
       at java.lang.Class.forName(Class.java:308)
       at java.lang.Class.forName(Class.java:272)
       at butterknife.ButterKnife.findInjectorForClass(ButterKnife.java:298)
       at butterknife.ButterKnife.inject(ButterKnife.java:271)
       at butterknife.ButterKnife.inject(ButterKnife.java:184)
       at com.myapp.android.ui.activity.MyDrawerActivity.onCreate(MyDrawerActivity.java:31)

I inject my Toolbar and a custom NavigationDrawer in the class.

@InjectView(R.id.toolbar) Toolbar mToolbar;
@InjectView(R.id.nav_drawer) MyNavigationDrawer mNavigationDrawer;

Line 31:

ButterKnife.inject(this);

Is there something that would be different with the Butterknife codegen when using gradle assembleRelease? I am not using ProGuard at all.

Here are my other Android build settings:

# Android SDK settings
ANDROID_BUILD_MIN_SDK_VERSION=14
ANDROID_BUILD_TARGET_SDK_VERSION=21
ANDROID_BUILD_SDK_VERSION=21
ANDROID_BUILD_TOOLS_VERSION=21.1.2

Logcat

I/art     (21354): Verification error in void com.myapp.android.ui.activity.MainActivity$$ViewInjector.inject(butterknife.ButterKnife$Finder, com.myapp.android.ui.activity.MainActivity, java.lang.Object)
I/art     (21354): void com.myapp.android.ui.activity.MainActivity$$ViewInjector.inject(butterknife.ButterKnife$Finder, com.myapp.android.ui.activity.MainActivity, java.lang.Object) failed to verify: register v4 has type Reference: com.myapp.android.ui.activity.MainActivity but expected Reference: com.myapp.android.ui.activity.LoggedInNavActivitya.lang.Object): [0x0]
I/art     (21354): Verification error in void com.myapp.android.ui.activity.MainActivity$$ViewInjector.reset(com.myapp.android.ui.activity.MainActivity)
I/art     (21354): void com.myapp.android.ui.activity.MainActivity$$ViewInjector.reset(com.myapp.android.ui.activity.MainActivity) failed to verify: register v1 has type Reference: com.myapp.android.ui.activity.MainActivity but expected Reference: com.myapp.android.ui.activity.LoggedInNavActivity
E/art     (21354): Verification failed on class com.myapp.android.ui.activity.MainActivity$$ViewInjector in /data/app/com.myapp.android-1/base.apk because: Verifier rejected class com.myapp.android.ui.activity.MainActivity$$ViewInjector due to bad method void com.myapp.android.ui.activity.MainActivity$$ViewInjector.reset(com.myapp.android.ui.activity.MainActivity)
Austyn Mahoney
  • 11,398
  • 8
  • 64
  • 85
  • Can you show the logcat output? There may be some additional information in the log before the exception. (There was in Dalvik, not sure what Art shows.) – fadden Jan 19 '15 at 19:15
  • I added the logs that show up right before the error. I see one problem right away. Line 2 shows an parent class called `LoggedInNavActivitya`, the `a` is not in the actual name. The other glaring issue that that `LoggedInNavActivity` is no longer even in my codebase... I deleted that file a while ago. – Austyn Mahoney Jan 19 '15 at 19:54

11 Answers11

82

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.

Austyn Mahoney
  • 11,398
  • 8
  • 64
  • 85
22

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.

Community
  • 1
  • 1
Sebastiano
  • 12,289
  • 6
  • 47
  • 80
  • 2
    +1. This one solved my issue and I sure wouldn't have found the root cause this easily without your Answer. Thanks a lot! – dbm Apr 08 '15 at 07:51
  • 1
    Bug marked as fixed when it is still here in 2022 – John Glen Jun 11 '22 at 01:37
  • +1 your answer works. I wrapped some code inside try/catch, and then Dagger code crashed app. At now everything works – kirkadev Feb 06 '23 at 09:27
4

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
}
Marius Kohmann
  • 713
  • 1
  • 8
  • 11
3

My app was working on most platforms but crashing immediately on Android 5.1. I started to suspect the new D8 dex compiler after reading Google info on how great it is. Disabling D8, so it uses the original DX compiler, is the only thing that worked for me. Project clean/invalidate caches didn't fix it. I had some synchronized blocks, but removing them didn't fix it. Turning off instant run didn't fix it. Disabling proguard didn't fix it.

Here is how you disable D8:
-Create a file called gradle.properties in the root of your project, if it doesn't exist
-In it put this line: android.enableD8=false

You'll get deprecated warnings. Hopefully Google actually fixes D8 before they fully remove the deprecated DX. I don't know what in my code triggers it. I'm using Android Studio 3.2.1 with gradle version 4.6. Edit: I've reported this bug and Google developers are actively investigating

Community
  • 1
  • 1
Georgie
  • 2,448
  • 2
  • 17
  • 13
2

Verify Error is majorly thrown in certain scenarios which occurs if we changed definition of class A, but class B was compiled using an older version of the class A. That's why it gets resolved if we clear our project and rebuild all the classes together with same version of Java.

Following link lists some of the scenarios where Verify error might occur. java.lang.VerifyError – How to solve VerifyError

Anuj Garg
  • 959
  • 10
  • 12
1

I had the same issue thrown by GoogleTagManager.

java.lang.VerifyError: Verifier rejected class com.google.android.gms.tagmanager.TagManager: com.google.android.gms.common.api.PendingResult com.google.android.gms.tagmanager.TagManager.loadContainerDefaultOnly(java.lang.String, int) failed to verify: com.google.android.gms.common.api.PendingResult com.google.android.gms.tagmanager.TagManager.loadContainerDefaultOnly(java.lang.String, int): [0x11] returning 'Reference: com.google.android.gms.tagmanager.zzp', but expected from declaration 'Reference: com.google.android.gms.common.api.PendingResult'

It happened after the merge. My collegue updated the library from 10.0.1 to 10.2.1. Clean build didn't work.

Due to time constraints, i rollback to the older version, and it worked.

Irshu
  • 8,248
  • 8
  • 53
  • 65
1

Edit: As people are still voting this answer, I want to mention that it is from 2017. I am not sure if it's still correct... I hope it's still useful for some of you...

In my case, I simply disabled the "Instant Run" option from my "Build, Execution, Deployment" settings.

To do so:

  1. go to "File" > "Settings" > "Build, Execution, Deployment" > "Instant Run"
  2. uncheck the box "Enable Instant Run..." and click "OK" button
ahmed_khan_89
  • 2,755
  • 26
  • 49
0

In my case, the cause is proguard. My app shutdown on sumsung note3 whick is android 5.0.
I imported the android-async-http-1.4.9.jar, the proguard is:

-dontwarn com.loopj.android.http.**
-keep class com.loopj.android.http.**{*;}

It is not enough. I added:

-dontwarn cz.msebera.**
-keep class cz.msebera.**{*;}

the bug gone.

so if you come into this bug, the deep-seated reason maybe not obvious, it is to be noted the proguard file.

Sergey Glotov
  • 20,200
  • 11
  • 84
  • 98
0

Simple (3) steps worked for me:

1 - from top menu of android studio build --> clean project

2 - from top menu of android studio build --> make project

3 - from top menu of android studio build --> rebuild project

All set up..

Ali Nawaz
  • 2,016
  • 20
  • 30
0

May be this can help some one who is facing this issue in Debug Build as well.

I was also facing the same error.I missed to Configure Google API Console project. So Configure Google API Console project following this and specify your app's package name when prompted. You will also need to provide the SHA-1 hash of your signing certificate. See Authenticating Your Client for information.

mannu
  • 17
  • 3
0

I've had this issue with stable version of Android Studio Arctic Fox Patch 3 (AGP 7.0.3) while using Kotlin 1.5.x or 1.6.x. When I was setting "1.5" or "1.6" as my Kotlin language version most of classes written in Kotlin were encountering VerifyError. Turned out the language version was the culprit, reducing it to "1.4" (while using Kotlin 1.5.x) fixed the errors for me:

app build.gradle.kts:

kotlinOptions {
    languageVersion = "1.4"
    jvmTarget = "11"
}
Sdghasemi
  • 5,370
  • 1
  • 34
  • 42