Android java.lang.VerifyError?

2019-01-01 08:59发布

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

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.

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.

30条回答
路过你的时光
2楼-- · 2019-01-01 09:41

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. I only saw the problems when I moved the class in question over to my Android project -- then the error was highlighted.

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:

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

private static final ThreadLocal<DaoConfigArray> daoConfigLevelLocal
    = new ThreadLocal<DaoConfigArray>() {
    @Override
    protected DaoConfigArray initialValue() {
        return new DaoConfigArray();
    }
};
查看更多
旧时光的记忆
3楼-- · 2019-01-01 09:42

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+). So it would crash with VerifyError on all pre-19 devices.

查看更多
泛滥B
4楼-- · 2019-01-01 09:49

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?

查看更多
ら面具成の殇う
5楼-- · 2019-01-01 09:52

I downgrade gradle version from 2.0.0-alpha2 to 1.5.0 that solved this problem.

查看更多
ら面具成の殇う
6楼-- · 2019-01-01 09:53

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:

  1. created a libs/ folder and added the jars.
  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. 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.

查看更多
墨雨无痕
7楼-- · 2019-01-01 09:54

It happened to me right now. The error was caused because I was using methods from a newer SDK that my device had.

Android 1.5 device installed an apk using this:

<uses-sdk android:minSdkVersion="3" android:targetSdkVersion="4"/>
查看更多
登录 后发表回答