拒绝类,因为它未通过编译时验证Android

问题描述:

我的一个应用程序在启动时突然失败,并显示以下错误消息:

One of my application suddenly fails on startup, with the following error message :

java.lang.VerifyError:拒绝类 com.sample.BufferManagerImpl,因为它失败了 编译时验证(声明 'com.sample.BufferManagerImpl'出现在 /data/app/com.sample.myapp-1/base.apk)

java.lang.VerifyError: Rejecting class com.sample.BufferManagerImpl because it failed compile-time verification (declaration of 'com.sample.BufferManagerImpl' appears in /data/app/com.sample.myapp-1/base.apk)

它只会在使用ART虚拟机的设备上失败,而不会在Dalvik上

It only fails on devices using the ART virtual machine, but not on Dalvik

问题是由于try-catch块中有一个synchronized块,例如:

The issue is due to having a synchronized block inside a try-catch block, for example :

try {
    synchronized (mLock) {
        updateState();
    }
} catch (IllegalStateException e) {
}

显然,这不是一个好习惯,但是只要我这样更改它,它就会起作用:

Apparently this is not a good practice, but as soon as I change it like this it works :

synchronized(mLock) {
    try {
        updateState();
    } catch (IllegalStateException e) {
    }
}