java.lang.VerifyError: Verifier 在使用发布版 APK 时拒绝了 Lollipop 上的类
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28031905/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
java.lang.VerifyError: Verifier rejected class on Lollipop when using release APK
提问by Austyn Mahoney
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.
当我在5.x
设备上安装我的发行版 APK 时出现此错误。当我从 Android Studio 推送相同的代码或在4.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)
I inject my Toolbar and a custom NavigationDrawer in the class.
我在类中注入了我的工具栏和自定义 NavigationDrawer。
@InjectView(R.id.toolbar) Toolbar mToolbar;
@InjectView(R.id.nav_drawer) MyNavigationDrawer mNavigationDrawer;
Line 31:
第 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.
使用时 Butterknife 代码生成器有什么不同gradle assembleRelease
吗?我根本没有使用 ProGuard。
Here are my other Android build settings:
这是我的其他 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
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)
采纳答案by Austyn Mahoney
Cleaning out the build
folder resolved the problem. Not sure why ART had an issue but Dalvik did not.
清理build
文件夹解决了问题。不知道为什么 ART 有问题,但 Dalvik 没有。
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.
运行 gradleclean
任务并没有完全清除我的build
文件夹。我不得不手动完成,但clean
可能对某些人有用。
回答by Sebastiano
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 SOand on the official bug tracker.
显然,将synchronized
语句放入try/catch
块中会导致VerifyError
,如在 SO和官方错误跟踪器上报告的那样。
回答by user1452641
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:
就我而言,原因是proguard。我在 sumsung note3 上关闭的应用程序是 android 5.0。
我导入了android-async-http-1.4.9.jar,proguard是:
-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.
所以如果你遇到这个bug,深层次的原因可能并不明显,要注意proguard文件。
回答by Irshu
I had the same issue thrown by GoogleTagManager
.
我遇到了同样的问题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'
java.lang.VerifyError: 验证器拒绝类 com.google.android.gms.tagmanager.TagManager: com.google.android.gms.common.api.PendingResult com.google.android.gms.tagmanager.TagManager.loadContainerDefaultOnly(java. lang.String, int) 验证失败:com.google.android.gms.common.api.PendingResult com.google.android.gms.tagmanager.TagManager.loadContainerDefaultOnly(java.lang.String, int): [0x11] 返回'参考:com.google.android.gms.tagmanager.zzp',但预期来自声明'参考: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.
它发生在合并之后。我的同事将图书馆从 更新10.0.1
为10.2.1
。清洁构建不起作用。
Due to time constraints, i rollback to the older version, and it worked.
由于时间限制,我回滚到旧版本,并且成功了。
回答by ahmed_khan_89
In my case, I simply disabled the "Instant Run" option from my "Build, Execution, Deployment" settings. Unfortunately the Android studio feature "Instant Run" is still far from being stable...
就我而言,我只是从“构建、执行、部署”设置中禁用了“即时运行”选项。不幸的是,Android Studio 的“即时运行”功能还远未稳定……
To do so:
这样做:
- go to "File" > "Settings" > "Build, Execution, Deployment" > "Instant Run"
- uncheck the box "Enable Instant Run..." and click "OK" button
- 转到“文件”>“设置”>“构建、执行、部署”>“即时运行”
- 取消选中“启用即时运行...”框,然后单击“确定”按钮
回答by Marius Kohmann
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.
在我的情况下,错误消息所说的方法“不好”,有一些未知的错误。从 Kotlin lambda 更改为常规循环解决了我的问题。
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
}
回答by Ali Nawaz
Simple (3) stepsworked for me:
简单的(3) 步骤对我有用:
1 -from top menu of android studio build --> clean project
1 -从 android studio build 的顶部菜单 ->清理项目
2 -from top menu of android studio build --> make project
2 -从 android studio build 的顶部菜单 -> make project
3 -from top menu of android studio build --> rebuild project
3 -从 android studio build 的顶部菜单 ->重建项目
All set up..
都设置好了。。
回答by Georgie
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.
我的应用程序可以在大多数平台上运行,但在 Android 5.1 上立即崩溃。在阅读谷歌关于它有多棒的信息后,我开始怀疑新的 D8 dex 编译器。禁用 D8,因此它使用原始 DX 编译器,是唯一对我有用的方法。项目清理/无效缓存没有修复它。我有一些同步块,但删除它们并没有解决它。关闭即时运行并没有解决它。禁用 proguard 并没有解决它。
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
以下是禁用 D8 的方法: -
在项目的根目录中创建一个名为 gradle.properties 的文件,如果它不存在
- 在其中输入以下行: 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
您将收到已弃用的警告。希望 Google 在完全删除已弃用的 DX 之前确实修复了 D8。我不知道我的代码中是什么触发了它。我正在使用 Android Studio 3.2.1 和 gradle 版本 4.6。编辑:我已经报告了这个错误,谷歌开发人员正在积极调查
回答by mannu
May be this can help some one who is facing this issue in Debug Build as well.
可能这也可以帮助在 Debug Build 中遇到此问题的人。
I was also facing the same error.I missed to Configure Google API Console project. So Configure Google API Console projectfollowing thisand specify your app's package name when prompted. You will also need to provide the SHA-1 hashof your signing certificate. See Authenticating Your Client for information.
我也遇到了同样的错误。我错过了配置 Google API 控制台项目。因此,请按照此配置 Google API 控制台项目,并在出现提示时指定您的应用程序包名称。您还需要提供签名证书的SHA-1 哈希值。有关信息,请参阅验证您的客户端。
回答by Anuj Garg
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.
如果我们更改类 A 的定义,则会在某些情况下主要抛出验证错误,但是类 B 是使用类 A 的旧版本编译的。这就是为什么如果我们清除我们的项目并使用相同的类重新构建所有类,它就会得到解决Java 版本。
Following link lists some of the scenarios where Verify error might occur. java.lang.VerifyError – How to solve VerifyError
以下链接列出了可能发生验证错误的一些场景。 java.lang.VerifyError – 如何解决VerifyError