最近遇到个Android Jar的问题,找了几天才找到root cause. 在此记录下。

我们的Android项目需要使用一个供应商的Jar.

我们使用的开发环境为:Eclipse + ADT插件(这年头居然不用Android Studio...)。

把下载好的Jar放入"libs"文件夹内,Eclipse就会自动识别。 启动APK,直接crash. Logcat 报:"java.lang.ClassNotFoundException"错误。

查看项目的 Java Build Path, Android Private Libraries and Android Dependencies 都正确并且都打勾了。

接下来就疯狂Googling,试了很多方法,还是不行。

三天之后。。。

搜到一篇文章,里面提到了有可能是因为Java Jar版本不兼容导致的。会报:

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

看了一下Eclipse的Console输出,果然有上面的错误。

妈呀,终于知道为什么了,浪费了这么多天时间。

原来供应商的Jar使用的是Android Studio导出的,而Android Studio默认使用Java 1.7编译的,而Eclipse的ADT工具Dx最多只支持1.5和1.6(这点没有找到权威的资料).

所以导致了Java 1.6虚拟机无法解析Java 1.7字节码文件。

我用在Windows下用Cygwin控制台的file *.class 命令看了下,确实看到供应商的Jar是Java 1.7的。

我试着在Eclipse中把Java Compliance 调到Jdk 1.7. 但是编出来的APK还是Crash.看来ADT确实最多只支持1.6.

解决方法:

需要在导出Jar中配置的,所以为了兼容需要在工程的build.gradle中添加

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

看来要让供应商改下了。

经验教训:

不要只看Logcat的错误输出,Console的输出有时也很重要。

参考链接:

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

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

Android使用Eclipse遇到"java.lang.ClassNotFoundException"的更多相关文章

  1. 真正解决问题:maven eclipse tomcat java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener--转

    原文地址:http://www.cnblogs.com/amosli/p/4067665.html 在使用eclipse进行整合springmvc时经常会碰到这样的异常: java.lang.Clas ...

  2. 真正解决问题:maven eclipse tomcat java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener

    在使用eclipse进行整合springmvc时经常会碰到这样的异常: java.lang.ClassNotFoundException:org.springframework.web.context ...

  3. eclipse java项目中明明引入了jar包 为什么项目启动的时候不能找到jar包 项目中已经 引入了 com.branchitech.app 包 ,但时tomcat启动的时候还是报错? java.lang.ClassNotFoundException: com.branchitech.app.startup.AppStartupContextListener java.lang.ClassN

    eclipse java项目中明明引入了jar包 为什么项目启动的时候不能找到jar包 项目中已经 引入了 com.branchitech.app 包 ,但时tomcat启动的时候还是报错?java. ...

  4. android 自定义View Caused by: java.lang.ClassNotFoundException: Didn't find class

    在android studio中, 自定义View 时,出现 Caused by: java.lang.ClassNotFoundException: Didn't find class 在查看包名和 ...

  5. myeclipe eclipse 常遇问题:Some projects cannot be imported 、java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver、The file connot be validate

    1.Some projects cannot be imported because they already exist in the workspace 2.Some projects were ...

  6. Eclipse报错:java.lang.ClassNotFoundException: ContextLoaderListener

    Eclipse中tomcat部署工程启动后报错: 严重: Error configuring application listener of class org.springframework.web ...

  7. java.lang.ClassNotFoundException: org.eclipse.jetty.plus.webapp.EnvConfiguration

    最近刚接触jetty,在myeclipse8.6中加入了一个项目,运行时就出了这个java.lang.ClassNotFoundException: org.eclipse.jetty.plus.we ...

  8. eclipse中启动tomcat报错 java.lang.ClassNotFoundException

    之前启动还好好的,某次启动tomcat就莫名其妙的报了这个java.lang.ClassNotFoundException的错.   检查maven依赖包,发现这个类是存在的. 然后一通clean操作 ...

  9. Eclipse报错:java.lang.ClassNotFoundException: ContextLoaderListener(Maven工程)

    Eclipse中tomcat部署工程启动后报错: 严重: Error configuring application listener of class org.springframework.web ...

随机推荐

  1. oracle数据库对date字段类型存在空值进行排序的处理方法

    oracle数据库对date字段类型存在空值进行排序的处理方法      oracle 数据库,如果表中有一个字段类型为date,且该字段类型存在空值,并且需要排序,     解决方法为使用oracl ...

  2. [转]OPENSOLARIS 2009.06 REPOSITORY ISO IMAGES NOW AVAILABLE

    Source: http://hosam.wordpress.com/2009/07/25/opensolaris-2009-06-repository-iso-images-now-availabl ...

  3. iOS: JS和Native交互的两种方法

    背景: UIWebView: iOS 用来展示 web 端内容的控件. 1. 核心方法: - (NSString*)stringByEvaluatingJavaScriptFromString:(NS ...

  4. linux 安装svn,并设置钩子来同步更新

    linux安装svn下载 http://subversion.tigris.org/downloads/subversion-1.6.6.tar.gz 和 http://subversion.tigr ...

  5. Cocos2d学习之路五(Box2d使用CCPhysicsSprite时编译不通过解决方法)

    cocos2d使用box2d引擎,在使用CCPhysicsSprite添加精灵的时候会出现编译不通过错误. 需要注意以下几点: 1.sprite.position=ccp(p.x,p.y);这行代码一 ...

  6. UISearchDisplayController UISearchBar

    分组表+本地搜索 UISearchDisplayController  UISearchBar 的使用 效果图 @interface CityListViewController :UIViewCon ...

  7. Dynamic CRM 2013 on Windows Azure VM

    三个A2 Size的VM,运行Windows Server 2012: AD Server,SQL Server,App Server 将AD Server的ip地址填写到Windows Azure虚 ...

  8. Ubuntu12.04安装配置Theano

    上次写了一个关于DL的开篇内容,本来说是要继续跟进的,后来教研室里面出了一些事情,加上写论文.和隔壁教研室做实验,就一直拖到现在.早就让小K配置环境研究研究Theano,这货和我一样也发拖延症了,理由 ...

  9. SystemTray文字颜色问题

    今天想给SystemTray的ForegroundColor设置为白色,但是模拟器正确,真机仍为黑色.经过一番折腾,发现是微软做了限制,背景是什么颜色,ForegroundColor就不能为什么颜色. ...

  10. 关于JS函数的bind

    昨天被人问到js的bind的作用是什么? 这个倒还能回答出来,bind 之后返回一个新的函数,这个函数可以保持传递的this上下文. 接着又问了,那么bind两次不同的上下文会怎样? 这个一下子就蒙了 ...