java.lang.VerifyError: 使用发布APK时,验证器拒绝了棒棒糖上的类

2022-08-31 20:08:37

当我在设备上安装我的版本APK时收到此错误。当我从Android Studio推送相同的代码时,或者在设备上运行它时,不会发生此错误。5.x4.x

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)

我在类中注入了我的工具栏和自定义导航草稿。

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

第31行:

ButterKnife.inject(this);

使用时,Butterknife codegen有什么不同吗?我根本没有使用 ProGuard。gradle assembleRelease

以下是我的其他 Android 构建设置:

# 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

日志猫

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)

答案 1

清除文件夹解决了问题。不知道为什么ART有问题,但Dalvik没有。build

运行 gradle 任务并没有完全清除我的文件夹。我不得不手动完成,但可能对某些人有效。cleanbuildclean


答案 2

就我而言,原因略有不同。

显然,在块中放置语句会导致 ,如 SO 和官方 bug 跟踪器所述。synchronizedtry/catchVerifyError


推荐