问题描述
在5.x
设备上安装发行版APK时出现此错误.当我从Android Studio推送相同的代码或在4.x
设备上运行该代码时,不会发生该错误.
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)
我将我的工具栏和自定义的NavigationDrawer注入类中.
I inject my Toolbar and a custom NavigationDrawer in the class.
@InjectView(R.id.toolbar) Toolbar mToolbar;
@InjectView(R.id.nav_drawer) MyNavigationDrawer mNavigationDrawer;
第31行:
ButterKnife.inject(this);
在使用gradle assembleRelease
时,Butterknife代码生成器是否有某些不同之处?我根本没有使用ProGuard.
Is there something that would be different with the Butterknife codegen when using gradle assembleRelease
? I am not using ProGuard at all.
这是我的其他Android构建设置:
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)
推荐答案
清除build
文件夹即可解决此问题.不知道为什么ART有问题,但Dalvik没有.
Cleaning out the build
folder resolved the problem. Not sure why ART had an issue but Dalvik did not.
运行gradle clean
任务并未完全清除我的build
文件夹.我必须手动执行此操作,但是clean
可能对某些人有用.
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.
这篇关于java.lang.VerifyError:使用发行版APK时,验证程序拒绝了Lollipop上的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!