简体   繁体   English

Android java.lang.VerifyError?

[英]Android java.lang.VerifyError?

In my Android app, I always get VerifyErrors! 在我的Android应用程序中,我总是得到VerifyErrors! And I cannot figure out why. 我无法弄清楚原因。 Whenever I include a external JAR, I always get VerifyErrors when I try to launch my app (except for once, when I included Apache Log4j.) 每当我包含一个外部JAR时,我总是在尝试启动我的应用程序时获得VerifyErrors(除了一次,当我包含Apache Log4j时)。

I usually get around this by taking the source of the library and adding it to my project, but I am trying to put the GData client library . 我通常通过获取库的源代码并将其添加到我的项目来解决这个问题,但我正在尝试放置GData客户端库

I can get this in source, but it's dependencies (mail.jar, activation.jar, servlet-api.jar) I cannot, so I get verify errors. 我可以在源代码中获取它,但它的依赖项(mail.jar,activation.jar,servlet-api.jar)我不能,所以我得到验证错误。 I would like to get to the root of this problem once and for all. 我想一劳永逸地找到这个问题的根源。 I looked on the internet, but they all seem to talk about incomplete class files? 我在互联网上看了一下,但他们似乎都在谈论不完整的类文件? which I do not know of. 我不知道。

Look at LogCat and see what's causing the verifyerror. 查看LogCat,看看是什么导致了verifyerror。 It's probably some method in a java.lang class that is not supported on the android SDK level you are using (for instance, String.isEmpty()). 它可能是java.lang类中的一些方法,在您正在使用的android SDK级别上不受支持(例如,String.isEmpty())。

From android-developers : 来自android-developers

The output from "adb logcat" indicates the class that could not be found as well as the class that has the bad reference. “adb logcat”的输出表示无法找到的类以及具有错误引用的类。 The location is identified down to the specific Dalvik instruction. 该位置被识别为特定的Dalvik指令。 The trick is to look in the logs above the exception. 诀窍是查看异常上方的日志。

Android uses a different class file format. Android使用不同的类文件格式。 Are you running the 3rd party JAR files through the "dx" tool that ships with the Android SDK? 您是否通过Android SDK附带的“dx”工具运行第三方JAR文件?

To make it work you need to add jar of the library to one of the source folders (even if you have already added it as eclipse library, you still need to add it as source). 要使其工作,您需要将库的jar添加到其中一个源文件夹中(即使您已将其添加为eclipse库,您仍需要将其添加为源代码)。

  1. Create a directory in your project (ex "libs") and put library jar there. 在项目中创建一个目录(例如“libs”)并将库jar放在那里。
  2. Add the directory to the build class path by (click right button on the folder and select "Build path"->"Use as source folder"). 将目录添加到构建类路径中(单击文件夹上的右键并选择“构建路径” - >“用作源文件夹”)。
  3. Rebuild your project. 重建您的项目。

I found an interesting case. 我发现了一个有趣的案例。 I use: 我用:

<uses-sdk
   android:minSdkVersion="9"
   android:targetSdkVersion="18" />

So some of new Android 4 capabilities are not implenented in Android 2.3 like ImageView.setLayerType . 因此,一些新的Android 4功能并未在Android 2.3中实现,如ImageView.setLayerType To avoid runtime error simply: 要简单地避免运行时错误:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
   setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}

This approach should be used also with exceptions handling: 这种方法也应该用于异常处理:

} catch (NetworkOnMainThreadException nomte) {
   // log this exception
} catch (SocketTimeoutException socketTimeoutException) {
   // log this exception
}

NetworkOnMainThreadException is not implemented in Android 2.3 so when the class is loaded (and not before!) the exception java.lang.VerifyError occurs. NetworkOnMainThreadException未在Android 2.3中实现,因此当加载类 (而不是之前!)时,会发生异常java.lang.VerifyError

It happened to me right now. 它现在发生在我身上。 The error was caused because I was using methods from a newer SDK that my device had. 导致该错误是因为我使用的是我的设备所具有的较新SDK中的方法。

Android 1.5 device installed an apk using this: Android 1.5设备安装了一个apk使用此:

<uses-sdk android:minSdkVersion="3" android:targetSdkVersion="4"/>

如果您正在使用Retrolambda,则可能已向接口添加了静态方法(仅在Java 8中允许)。

This can also occur because of referencing limit error on Lollypop below versions, where it is limited upto max 65K size 这也可能是因为在Lollypop下面的版本引用了限制错误,它被限制到最大65K大小

Possible solution for above issue 上述问题的可能解决方案

Step1: Add android-support-multidex.jar to your project. The jar can be found in your Android SDK folder /sdk/extras/android/support/multidex/library/libs Add android-support-multidex.jar to your project. The jar can be found in your Android SDK folder /sdk/extras/android/support/multidex/library/libsAdd android-support-multidex.jar to your project. The jar can be found in your Android SDK folder /sdk/extras/android/support/multidex/library/libs Add android-support-multidex.jar to your project. The jar can be found in your Android SDK folder /sdk/extras/android/support/multidex/library/libs

Step2: Extend your application with MultiDexApplication, for eg 第2步:使用MultiDexApplication扩展您的应用程序,例如

public class MyApplication extends MultiDexApplication

Step3: Override attachBaseContext 第3步:覆盖attachBaseContext

protected void attachBaseContext(Context base) {
 super.attachBaseContext(base);
 MultiDex.install(this);
}

Step4: The next step is to add the following to the android part of your apps build.gradle Step4:下一步是将以下内容添加到应用程序build.gradle的android部分

 dexOptions {
      preDexLibraries = false
   }

Step5: Lastly, following to the general part of your apps build.gradle 第5步:最后,关注应用build.gradle的一般部分

afterEvaluate {
   tasks.matching {
      it.name.startsWith('dex')
   }.each { dx ->
      if (dx.additionalParameters == null) {
         dx.additionalParameters = ['--multi-dex']
      } else {
         dx.additionalParameters += '--multi-dex'
      }
   }
}

For details, please checkout 有关详细信息,请结帐

https://developer.android.com/tools/building/multidex.html https://developer.android.com/tools/building/multidex.html

In my case, it happened when I updated from Eclipse Indigo to Eclipse Juno: I'm not sure what is the true reason, but, my Android project that I'm working on for a long time stopped work because of that exception. 就我而言,当我从Eclipse Indigo更新到Eclipse Juno时发生了这种情况:我不确定是什么原因,但是,我正在研究的Android项目因为该异常而停止工作了很长时间。

After many hours of trying to fix that, I found the solution for me. 经过几个小时的努力来解决这个问题,我找到了解决方案。

In my Android project, I use other project (say, "MyUtils") that is in the same workspace. 在我的Android项目中,我使用位于同一工作区中的其他项目(例如,“MyUtils”)。 So, I needed to do the following: 所以,我需要做以下事情:

Right click on Android project -> Build path -> Configure build path 右键单击Android项目 - >构建路径 - >配置构建路径

Now, go to tab "Order and Export" and make "MyUtils" checked. 现在,转到“订购和导出”选项卡并选中“MyUtils”。 That's it: I got rid of this annoying exception. 就是这样:我摆脱了这个烦人的异常。

我将gradle版本从2.0.0-alpha2降级到1.5.0解决了这个问题。

In Eclipse 4.x , if you encounter this problem, try below: Eclipse 4.x ,如果遇到此问题,请尝试以下操作:

  1. migrate all included 3th-party jars into the User-Libaray 将所有包含的第三方罐子迁移到User-Libaray中
  2. move up the user lib before the android lib and check it in the Order and Export tab 在android lib之前移动用户lib并在Order and Export选项卡中检查它
  3. clean and rebuild to run 清理并重建以运行

I have this issue after a SDK update. SDK更新后我遇到此问题。 The compiler had problems with my external librarys. 编译器与我的外部库存有问题。 I did this: right click on project, then "android Tools > add suport library..." this install on my project library "android-support-v4.jar". 我这样做了:右键单击项目,然后“android工具>添加支持库......”这个安装在我的项目库“android-support-v4.jar”上。

The problem could also be caused by a mismatch between two androids projects. 这个问题也可能是由两个机器人项目之间的不匹配引起的。 For example if you have developed an android library using the package "com.yourcompany", Then you have the main application's project using the same package as base package. 例如,如果您使用“com.yourcompany”包开发了一个android库,那么您的主应用程序项目使用与基础包相同的包。 Then let say you want to change the version of your main app, so you change the manifest file's values: Version Code and Version name. 然后,假设您要更改主应用程序的版本,以便更改清单文件的值:版本代码和版本名称。 If you run your app without changing those values for the library, you would get a verify error on any call of a method on a object from the library. 如果您在不更改库的这些值的情况下运行应用程序,则在从库中对象的任何方法调用时都会收到验证错误。

I had the same issue. 我遇到过同样的问题。 I was building with 2.1 r1 and updated to 2.1 r3 with the new adt 17. I had verify errors on javamail's mail.jar and it was driving me crazy. 我用2.1 r1构建并使用新的adt 17更新到2.1 r3。我在javamail的mail.jar上验证了错误,这让我发疯了。 Here is how i solved the issue: 这是我如何解决这个问题:

  1. created a libs/ folder and added the jars. 创建了一个libs /文件夹并添加了jar。
  2. right click > add as source folder 右键单击>添加为源文件夹

i tried a rebuild and it failed. 我尝试重建,但失败了。 I removed the libs/ directory as a source folder and removed refs to the 3 jar files in the build path. 我删除了libs /目录作为源文件夹,并删除了refs到构建路径中的3个jar文件。 Then i added the libs/ folder again, and added each jar in the libs/ folder to the build path. 然后我再次添加了libs /文件夹,并将libs /文件夹中的每个jar添加到构建路径中。 Now it works as expected. 现在它按预期工作。 This is a weird workaround but it worked for me. 这是一个奇怪的解决方法,但它对我有用。

I had very similar problem. 我有类似的问题。 I had added Apache POI jars and problem appeared when I updated to android SDK 22.3. 当我更新到android SDK 22.3时,我添加了Apache POI jar并出现了问题。

I had Android Private Libraries checked so this was not the common problem with android SDK. 我检查了Android私有库,所以这不是android SDK的常见问题。 I unchecked all Apache POI jars and added one by one. 我取消选中所有Apache POI jar并逐个添加。 I found that poi-3.9-20121203.jar should be before poi-ooxml-3.9-20121203.jar . 我发现poi-3.9-20121203.jar应该在poi-ooxml-3.9-20121203.jar之前 Otherwise it will not work. 否则它将无法工作。

I get the VerfiyError as well... can't find a real reason. 我也得到了VerfiyError ......找不到真正的原因。 It helps to wrap the new lines of code into a method (Eclipse, 'Extract Method...'). 它有助于将新的代码行包装到一个方法中(Eclipse,'Extract Method ...')。 So in my case the reason is not an unsupported method. 所以在我的情况下,原因不是一个不受支持的方法。

If you have tests, try commenting out this line from your build.grade file: 如果您有测试,请尝试从build.grade文件中注释掉这一行:

testCoverageEnabled = true

For me this caused VerifyError exceptions on classes which use Java 1.7 features, particularly string switch statements. 对我来说,这会导致使用Java 1.7功能的类的VerifyError异常,特别是字符串切换语句。

I had the same problem after making a git pull. 在做一个git pull之后我遇到了同样的问题。

Solution: Build -> Clean Project. 解决方案:构建 - >清理项目。

Hope this helps. 希望这可以帮助。

I have found another case. 我找到了另一个案例。

Conditions: 条件:

  • Use Retrolambda (not sure if it's necessary); 使用Retrolambda(不确定是否有必要);
  • Make a static method in an interface. 在接口中创建静态方法。

And the result is boom! 结果就是繁荣! java.lang.VerifyError when trying to access the class that uses that interface. 尝试访问使用该接口的类时java.lang.VerifyError。 Looks like Android (4.4.* in my case) doesn't like static methods in interfaces. 看起来像Android(4.4。*在我的情况下)不喜欢接口中的静态方法。 Removing the static method from interface makes VerifyError go away. 从接口中删除静态方法会使VerifyError消失。

java.lang.VerifyError means your compiled bytecode is referring to something that Android cannot find at runtime. java.lang.VerifyError意味着您编译的字节码指的是Android在运行时无法找到的内容。 This verifyError Issues me only with kitkat4.4 and lesser version not in above version of that even I ran the same build in both Devices. 这个verifyError只发布了kitkat4.4和较小版本的版本,而不是上面版本的版本 ,即使我在两个设备中运行相同的版本。 when I used jackson json parser of older version it shows java.lang.VerifyError 当我使用旧版本的jackson json解析器时,它显示了java.lang.VerifyError

compile 'com.fasterxml.jackson.core:jackson-databind:2.2.+'
compile 'com.fasterxml.jackson.core:jackson-core:2.2.+'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.2.+'

Then I have changed the Dependancy to the latest version 2.2 to 2.7 without the core library (when I include core2.7 it gives the verifyError), then it works. 然后我将Dependancy更改为最新版本2.2到2.7而没有核心库 (当我包含core2.7时它给出了verifyError),然后它可以工作。 which means the Methods and other contents of core is migrated to the latest version of Databind2.7 . 这意味着核心的方法和其他内容将迁移到最新版本的Databind2.7 This fix my Issues. 这解决了我的问题。

compile 'com.fasterxml.jackson.core:jackson-annotations:2.7.0-rc3'
compile 'com.fasterxml.jackson.core:jackson-databind:2.7.0-rc3'

For posterity, I just got this error because I was using Arrays.copyOf() which is not a method supported by Java 1.5 which corresponds to Android Level 4. Because I was running including libraries developed under 1.6 they compiled fine. 对于后代,我刚收到此错误,因为我使用的是Arrays.copyOf() ,它不是Java 1.5支持的方法,它对应于Android Level 4.因为我在运行包括在1.6下开发的库,所以它们编译得很好。 I only saw the problems when I moved the class in question over to my Android project -- then the error was highlighted. 当我将有问题的课程移到我的Android项目时,我才看到问题 - 然后突出显示错误。

Uncaught handler: thread main exiting due to uncaught exception
java.lang.VerifyError: com.j256.ormlite.dao.BaseDaoImpl$DaoConfigArray
  at com.j256.ormlite.dao.BaseDaoImpl$1.initialValue(BaseDaoImpl.java:71)
  at com.j256.ormlite.dao.BaseDaoImpl$1.initialValue(BaseDaoImpl.java:1)
  at java.lang.ThreadLocal$Values.getAfterMiss(ThreadLocal.java:429)
  at java.lang.ThreadLocal.get(ThreadLocal.java:66)

On that line I was trying to do a new DaoConfigArray and that class had the following line: 在那一行,我试图做一个new DaoConfigArray ,该类有以下行:

// copyOf is only supported in Java >= 1.6
doArray = Arrays.copyOf(daoArray, newLength);

What made it even more complicated is that line 71 was pointing to a ThreadLocal initialization which I thought was the reason for the problem initially. 让它变得更复杂的是第71行指向ThreadLocal初始化,我认为这是初始问题的原因。

private static final ThreadLocal<DaoConfigArray> daoConfigLevelLocal
    = new ThreadLocal<DaoConfigArray>() {
    @Override
    protected DaoConfigArray initialValue() {
        return new DaoConfigArray();
    }
};

我不得不删除依赖项目,而是编译依赖项目是jar,并将它们包含在libs文件夹中。

I'm sure that my cause was different than yours, but since this is one of the top hits when searching for "Android java.lang.VerifyError", I thought I'd record it here for posterity. 我确信我的原因与你的不同,但由于这是搜索“Android java.lang.VerifyError”时的热门点击之一,我想我会把它记录下来作为后代。

I had some classes along the lines of: 我有一些课程:

public class A { ... }
public class B extends A { ... }
public class C extends A { ... }

And a method that did: 并且做了一个方法:

A[] result = null;
if (something)
    result = new B[cursor.getCount()];
else
    result = new C[cursor.getCount()];

// Fill result
...

As long as this code was present in the file, I would get a VerifyError the first time the class containing this method was loaded. 只要该代码存在于文件中,我就会在第一次加载包含此方法的类时获得VerifyError。 Splitting it out into two separate methods (one that dealt only with B's, and one that dealt only with C's) fixed the problem. 将它拆分为两个单独的方法(一个只处理B的方法,另一个只处理C的方法)解决了这个问题。

In my case, this error occur because my google-play-service is not the newest . 在我的情况下,出现此错误是因为我的google-play-service不是最新的

If your project does not support some class in the .jar, this error occurs(ex. ImageView.setLayerType, AdvertisingIdClient, etc.). 如果您的项目不支持.jar中的某个类,则会发生此错误(例如ImageView.setLayerType,AdvertisingIdClient等)。

I just identified another situation that it occurs, not only due to libs not dx 'ed. 我刚刚发现了它发生的另一种情况,不仅仅是因为libs不是dx'ed I have a AsyncTask with a very long doInBackground mehtod. 我有一个非常长的doInBackground mehtod AsyncTask。 For some reason this method with more than 145 lines started to break. 出于某种原因,超过145行的这种方法开始破裂。 It happened on a 2.3 app. 它发生在2.3应用程序上。 When I just encapsulated some parts into methods, it worked fine. 当我将一些部分封装到方法中时,它工作正常。

So for those that could not find the class that was not correctly dx 'ed, try reducing the length of your method. 因此,对于那些找不到正确dx的类,请尝试减少方法的长度。

For me, the issue ended up actually being that I was using multi-catch clause somewhere in the class which is a Java 7 feature (and API 19+). 对我来说,问题最终实际上是我在类中的某个地方使用了多个catch子句,这是一个Java 7特性(和API 19+)。 So it would crash with VerifyError on all pre-19 devices. 所以它会在所有19版之前的设备上与VerifyError一起崩溃。

For me it was in correlation between compileSdkVersion and buildToolsVersion. 对我来说,它是在compileSdkVersion和buildToolsVersion之间的相关性。 I had: 我有:

compileSdkVersion 21
buildToolsVersion '19.1.0'

I changed it to: 我改成了:

compileSdkVersion 21
buildToolsVersion '21.1.2'

For me, it is the problem of compileSdkVersion. 对我来说,这是compileSdkVersion的问题。 When I used the API level 21 in a specific android application ( https://github.com/android10/Android-AOPExample ): 当我在特定的Android应用程序中使用API​​级别21时( https://github.com/android10/Android-AOPExample ):

compileSdkVersion 21

the java.lang.verifyerror happened. 发生了java.lang.verifyerror。 So I changed the compileSdkVersion to 19 所以我将compileSdkVersion更改为19

compileSdkVersion 19

It worked well. 它运作良好。 I think that it might be the problem of SDK buildTools, and it seems OK when API level < 21. 我认为它可能是SDK buildTools的问题,当API级别<21时似乎没问题。

I also had this problem, as had my jars in a user library... 我也有这个问题,就像我在用户库中的罐子一样......

The way I solved this was to add them to the lib folder and then add them in the build properties in eclipse... 我解决这个问题的方法是将它们添加到lib文件夹中,然后将它们添加到eclipse中的构建属性中...

The first time i did this it did not work, but then i removed them and readded them again and it started working... 我第一次这样做它没有用,但后来我删除了它们并再次读取它们开始工作......

bit of a strange one! 有点奇怪! but now working all the time. 但现在一直在工作。

Good Luck 祝好运

I have coded Android API methods/class that are in SDK 2.1, and was trying to run it on Android 1.6 emulator. 我编写了SDK 2.1中的Android API方法/类,并试图在Android 1.6模拟器上运行它。 So i got that error. 所以我得到了那个错误。

SOLUTION: Changed it to correct emulator version. 解决方案:将其更改为更正的仿真器版本。

THIS WORKED FOR ME.. Thanks. 这为我工作 ..谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM