programing

Android java.lang.VerifyError?

nasanasas 2020. 8. 21. 07:50
반응형

Android java.lang.VerifyError?


내 Android 앱에서는 항상 VerifyErrors가 발생합니다! 그리고 나는 이유를 알 수 없습니다. 외부 JAR을 포함 할 때마다 앱을 시작하려고 할 때 항상 VerifyErrors가 발생합니다 (Apache Log4j를 포함한 경우는 한 번 제외).

나는 일반적으로 라이브러리의 소스를 가져와 내 프로젝트에 추가 하여이 문제를 해결하지만 GData 클라이언트 라이브러리 를 넣으려고합니다 .

나는 이것을 소스에서 얻을 수 있지만 종속성 (mail.jar, activation.jar, servlet-api.jar)입니다. 할 수 없으므로 확인 오류가 발생합니다. 이 문제의 근원에 대해 단번에 이해하고 싶습니다. 인터넷에서 봤는데 모두 불완전한 수업 파일에 대해 이야기하는 것 같나요? 내가 모르는.


Android는 다른 클래스 파일 형식을 사용합니다. Android SDK와 함께 제공되는 "dx"도구를 통해 타사 JAR 파일을 실행하고 있습니까?


LogCat을보고 확인 오류의 원인을 확인하십시오. 사용중인 Android SDK 수준 (예 : String.isEmpty ())에서 지원되지 않는 java.lang 클래스의 일부 메서드 일 수 있습니다.


에서 안드로이드 개발자 :

"adb logcat"의 출력은 찾을 수없는 클래스와 잘못된 참조가있는 클래스를 나타냅니다. 위치는 특정 Dalvik 지침에 따라 식별됩니다. 트릭은 예외 위의 로그를 살펴 보는 것입니다.


작동하려면 라이브러리의 jar를 소스 폴더 중 하나에 추가해야합니다 (이미 eclipse 라이브러리로 추가 한 경우에도 소스로 추가해야합니다).

  1. 프로젝트에 디렉토리 (예 : "libs")를 만들고 거기에 라이브러리 jar를 넣습니다.
  2. (폴더에서 마우스 오른쪽 버튼을 클릭하고 "빌드 경로"-> "소스 폴더로 사용"을 선택)하여 빌드 클래스 경로에 디렉토리를 추가하십시오.
  3. 프로젝트를 다시 빌드하십시오.

바로 지금 나에게 일어났습니다. 내 장치에있는 최신 SDK의 메서드를 사용했기 때문에 오류가 발생했습니다.

Android 1.5 기기는 다음을 사용하여 apk를 설치했습니다.

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

흥미로운 사례를 찾았습니다. 나는 사용한다:

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

따라서 새로운 Android 4 기능 중 일부는 Android 2.3에서 ImageView.setLayerType. 런타임 오류를 방지하려면 다음을 수행하십시오.

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

이 접근 방식은 예외 처리에도 사용해야합니다.

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

NetworkOnMainThreadExceptionAndroid 2.3에서는 구현되지 않으므로 클래스가로드 될 때 (이전이 아님) 예외 java.lang.VerifyError가 발생합니다.


Retrolambda를 사용하는 경우 인터페이스에 정적 메서드를 추가했을 수 있습니다 (Java 8에서만 허용됨).


이는 Lollypop 이하 버전에서 최대 65K 크기로 제한되는 제한 오류를 참조하기 때문에 발생할 수도 있습니다.

위 문제에 대한 가능한 해결책

1 단계: 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

2 단계 : MultiDexApplication으로 애플리케이션 확장

public class MyApplication extends MultiDexApplication

3 단계 : attachBaseContext 재정의

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

4 단계 : 다음 단계는 앱 build.gradle의 Android 부분에 다음을 추가하는 것입니다.

 dexOptions {
      preDexLibraries = false
   }

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'
      }
   }
}

자세한 내용은 체크 아웃하세요.

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


제 경우에는 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. So, I needed to do the following:

Right click on Android project -> Build path -> Configure build path

Now, go to tab "Order and Export" and make "MyUtils" checked. That's it: I got rid of this annoying exception.


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


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.


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.


In Eclipse 4.x, if you encounter this problem, try below:

  1. migrate all included 3th-party jars into the User-Libaray
  2. move up the user lib before the android lib and check it in the Order and Export tab
  3. clean and rebuild to run

I have this issue after a SDK update. 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".


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.


I had very similar problem. I had added Apache POI jars and problem appeared when I updated to android SDK 22.3.

I had Android Private Libraries checked so this was not the common problem with android SDK. I unchecked all Apache POI jars and added one by one. I found that poi-3.9-20121203.jar should be before poi-ooxml-3.9-20121203.jar. Otherwise it will not work.


If you have tests, try commenting out this line from your build.grade file:

testCoverageEnabled = true

For me this caused VerifyError exceptions on classes which use Java 1.7 features, particularly string switch statements.


I had the same problem after making a git pull.

Solution: Build -> Clean Project.

Hope this helps.


I have found another case.

Conditions:

  • Use Retrolambda (not sure if it's necessary);
  • 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. Looks like Android (4.4.* in my case) doesn't like static methods in interfaces. Removing the static method from interface makes VerifyError go away.


java.lang.VerifyError means your compiled bytecode is referring to something that Android cannot find at runtime. 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. when I used jackson json parser of older version it shows 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. which means the Methods and other contents of core is migrated to the latest version of 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'

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

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. So i got that error.

SOLUTION: Changed it to correct emulator version.

THIS WORKED FOR ME.. Thanks.


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();
    }
};

I had to remove dependent projects and instead compile dependent projects are jar's and include them in the libs folder.


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.

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


In my case, this error occur because my google-play-service is not the newest.

If your project does not support some class in the .jar, this error occurs(ex. ImageView.setLayerType, AdvertisingIdClient, etc.).


I just identified another situation that it occurs, not only due to libs not dx'ed. I have a AsyncTask with a very long doInBackground mehtod. For some reason this method with more than 145 lines started to break. It happened on a 2.3 app. 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.


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.


For me it was in correlation between compileSdkVersion and 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. When I used the API level 21 in a specific android application (https://github.com/android10/Android-AOPExample):

compileSdkVersion 21

the java.lang.verifyerror happened. So I changed the compileSdkVersion to 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.

참고URL : https://stackoverflow.com/questions/668788/android-java-lang-verifyerror

반응형