首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >安卓VerifyError异常

安卓VerifyError异常
EN

Stack Overflow用户
提问于 2017-02-03 19:29:02
回答 2查看 748关注 0票数 2

我在我的应用程序中使用指纹传感器。我知道api可用于棉花糖和更高版本的操作系统。因此,当在我的类中运行时,我会动态检查sdk版本。

即使是指纹不能执行的代码,我在4.0 android操作系统上也会遇到以下异常,而在5.0和更高版本上也是如此。

代码语言:javascript
复制
**java.lang.VerifyError: com/cloudzon/gratzeez1/GiveGratuityActivity
                                                                        at java.lang.Class.newInstanceImpl(Native Method)
                                                                        at java.lang.Class.newInstance(Class.java:1215)
                                                                        at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
                                                                        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2265)
                                                                        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417)
                                                                        at android.app.ActivityThread.access$800(ActivityThread.java:151)
                                                                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1342)
                                                                        at android.os.Handler.dispatchMessage(Handler.java:110)
                                                                        at android.os.Looper.loop(Looper.java:193)
                                                                        at android.app.ActivityThread.main(ActivityThread.java:5322)
                                                                        at java.lang.reflect.Method.invokeNative(Native Method)
                                                                        at java.lang.reflect.Method.invoke(Method.java:515)
                                                                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:829)
                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:645)
                                                                        at dalvik.system.NativeStart.main(Native Method)**

我发现因为在我的类中使用了下面的代码,所以我面临着这个问题。

代码语言:javascript
复制
public boolean cipherInit() {
    try {
        cipher = Cipher.getInstance(KeyProperties.KEY_ALGORITHM_AES + "/" + KeyProperties.BLOCK_MODE_CBC + "/" + KeyProperties.ENCRYPTION_PADDING_PKCS7);
    } catch (NoSuchAlgorithmException | NoSuchPaddingException e) {
        throw new RuntimeException("Failed to get Cipher", e);
    }

    try {
        keyStore.load(null);
        SecretKey key = (SecretKey) keyStore.getKey(KEY_NAME,
                null);
        cipher.init(Cipher.ENCRYPT_MODE, key);
        return true;
    } catch (KeyPermanentlyInvalidatedException e) {
        return false;
    } catch (KeyStoreException | CertificateException | UnrecoverableKeyException | IOException | NoSuchAlgorithmException | InvalidKeyException e) {
        throw new RuntimeException("Failed to init Cipher", e);
    }
}
EN

回答 2

Stack Overflow用户

发布于 2017-02-08 01:54:10

我也遇到了这个问题,另一个答案让我走上了正确的道路;How to Use Unsupported Exception for Lower Platform Version

我将该方法更改为;

代码语言:javascript
复制
public boolean cipherInit() {
    try {
        cipher = Cipher.getInstance(KeyProperties.KEY_ALGORITHM_AES + "/" + KeyProperties.BLOCK_MODE_CBC + "/" + KeyProperties.ENCRYPTION_PADDING_PKCS7);
    } catch (NoSuchAlgorithmException | NoSuchPaddingException e) {
        throw new RuntimeException("Failed to get Cipher", e);
    }

    try {
        keyStore.load(null);
        SecretKey key = (SecretKey) keyStore.getKey(KEY_NAME, null);
        cipher.init(Cipher.ENCRYPT_MODE, key);
        return true;
    } catch (Exception e) {
        if(e instanceof KeyPermanentlyInvalidatedException)
            return false;
        else if(e instanceof KeyStoreException|e instanceof CertificateException|e instanceof UnrecoverableKeyException|e instanceof IOException|e instanceof NoSuchAlgorithmException|e instanceof InvalidKeyException)
            throw new RuntimeException("Failed to init Cipher",e);
    }
    return false;
}

出于某种原因,将(KeyPermanentlyInvalidatedException的KeyPermanentlyInvalidatedException的catch块从KeyPermanentlyInvalidatedException)的e)更改为(e实例)似乎解决了这个问题。

票数 7
EN

Stack Overflow用户

发布于 2019-01-22 23:12:32

我只需更改catch异常块即可解决此问题。KeyPermanentlyInvalidatedExceptionInvalidKeyException的子类,如果我们使用KeyPermanentlyInvalidatedException,就会得到VerifyError。

代码语言:javascript
复制
catch (KeyPermanentlyInvalidatedException e) {
(...)
}

相反,请使用InvalidKeyException

代码语言:javascript
复制
catch (InvalidKeyException e) {
(...)
}

@opt05 answer帮助我解决我的问题,但我不喜欢他使用instance of的方法。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42023211

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档