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"