Android java.lang.VerifyError?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/668788/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 17:39:55  来源:igfitidea点击:

Android java.lang.VerifyError?

javaandroidgdataverifyerror

提问by Isaac Waller

In my Android app, I always get 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.)

在我的 Android 应用程序中,我总是收到验证错误!我不知道为什么。每当我包含外部 JAR 时,当我尝试启动我的应用程序时,我总是会收到验证错误(除了一次,当我包含 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. 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.

我可以在源代码中获得它,但它的依赖项(mail.jar、activation.jar、servlet-api.jar)我不能,所以我得到了验证错误。我想一劳永逸地找到这个问题的根源。我在网上看了一下,好像都是说class文件不全?我不知道。

采纳答案by TofuBeer

Android uses a different class file format. Are you running the 3rd party JAR files through the "dx" tool that ships with the Android SDK?

Android 使用不同的类文件格式。您是否通过 Android SDK 附带的“dx”工具运行 3rd 方 JAR 文件?

回答by Alex

Look at LogCat and see what's causing the 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()).

查看 LogCat,看看是什么导致了验证错误。它可能是您使用的 android SDK 级别不支持的 java.lang 类中的某些方法(例如,String.isEmpty())。

回答by asdf wer

I get the VerfiyError as well... can't find a real reason. It helps to wrap the new lines of code into a method (Eclipse, 'Extract Method...'). So in my case the reason is not an unsupported method.

我也收到了 VerfiyError ......找不到真正的原因。它有助于将新的代码行包装到一个方法中(Eclipse,'Extract Method...')。所以在我的情况下,原因不是不受支持的方法。

回答by Macarse

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"/>

回答by ADB

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. The location is identified down to the specific Dalvik instruction. The trick is to look in the logs above the exception.

“adb logcat”的输出指示找不到的类以及引用错误的类。该位置被识别到特定的 Dalvik 指令。诀窍是查看异常上方的日志。

回答by Maksim Golivkin

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 (e.x. "libs") and put library jar there.
  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.
  1. 在您的项目中创建一个目录(例如“libs”)并将库 jar 放在那里。
  2. 通过(单击文件夹上的右键并选择“构建路径”->“用作源文件夹”)将目录添加到构建类路径。
  3. 重建你的项目。

回答by Benjamin Lambe

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

祝你好运

回答by Piyush Patel

I have coded Android API methods/class that are in SDK 2.1, and was trying to run it on Android 1.6 emulator. So i got that error.

我编写了 SDK 2.1 中的 Android API 方法/类,并试图在 Android 1.6 模拟器上运行它。所以我得到了那个错误。

SOLUTION:Changed it to correct emulator version.

解决方案:将其更改为正确的模拟器版本。

THIS WORKEDFOR ME..Thanks.

有用..谢谢。

回答by ZeroOne

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. 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.

该问题也可能是由两个 androids 项目之间的不匹配引起的。例如,如果您使用包“com.yourcompany”开发了一个 android 库,那么主应用程序的项目使用与基本包相同的包。然后假设您要更改主应用程序的版本,因此您更改清单文件的值:版本代码和版本名称。如果您在不更改库的这些值的情况下运行您的应用程序,则在对库中对象的任何方法调用时,您都会收到验证错误。

回答by ThumbsDP

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. Here is how i solved the issue:

我遇到过同样的问题。我用 2.1 r1 构建并使用新的 adt 17 更新到 2.1 r3。我在 javamail 的 mail.jar 上验证了错误,这让我发疯。这是我解决问题的方法:

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

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. Then i added the libs/ folder again, and added each jar in the libs/ folder to the build path. Now it works as expected. This is a weird workaround but it worked for me.

我尝试了重建,但失败了。我删除了 libs/ 目录作为源文件夹,并删除了对构建路径中 3 个 jar 文件的引用。然后我再次添加了 libs/ 文件夹,并将 libs/ 文件夹中的每个 jar 添加到构建路径。现在它按预期工作。这是一个奇怪的解决方法,但它对我有用。