Android uses Eclipse to encounter "Java.lang.ClassNotFoundException"

Source: Internet
Author: User

Recently encountered an Android jar problem, found a few days to find root cause. Under this record.

Our Android project requires the use of a vendor's jar.

The development environment we are using is: Eclipse + ADT Plugin (this is not the year for Android Studio ... )。

Put the downloaded jar in the "Libs" folder, and Eclipse will automatically recognize it. Launch apk, direct crash. Logcat newspaper: "Java.lang.ClassNotFoundException" error.

Viewing the project's Java Build Path, Android Private Libraries and Android Dependencies are both correct and tick.

The next crazy Googling, tried a lot of methods, or not.

After three days ...

An article was found that could be caused by incompatible versions of the Java jar. Will report:

Dx bad class file magic (cafebabe) or version (0033.0000)

Looking at the console output of Eclipse, there was a mistake.

Mom, finally know why, waste so many days of time.

The original vendor's jar was exported using Android Studio, and Android Studio was compiled by default with Java 1.7, while Eclipse's ADT tool DX supported up to 1.5 and 1.6 (no authoritative data found).

As a result, Java 1.6 virtual machines cannot parse Java 1.7 bytecode files.

I looked under the file *.class command under Windows with the Cygwin console and did see that the vendor's Jar was Java 1.7.

I tried to transfer Java Compliance to JDK 1.7 in eclipse. But the compiled apk is still crash. It seems that ADT does support up to 1.6.

Workaround:

Need to be configured in the export jar, so in order to be compatible you need to add the Build.gradle in the project

    compileOptions {        sourceCompatibility = JavaVersion.VERSION_1_6        targetCompatibility = JavaVersion.VERSION_1_6    }

It seems that the supplier has to be changed.

Lessons learned:

Don't just look at the Logcat error output, the console output is sometimes important.

Reference Links:

Http://www.jianshu.com/p/f789fe4bcacd

Http://www.eoeandroid.com/thread-312955-1-1.html

Android uses Eclipse to encounter "Java.lang.ClassNotFoundException"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.