java - Android 外部库项目上的 NoClassDefFoundError

标签 java android eclipse android-library

我使用 eclipse 进行 Google Android 开发。

我创建了一个库项目(Android 设置中的 [x] Is Library),其中包含一个外部 jar 文件(引用库)。此库项目在另一个项目(将使用库项目的实际项目)中引用。这是通过在 Android-settings 下添加项目来完成的。

源代码编译,但如果我想在设备上执行它,我会得到一个类的 NoClassDefFoundError,该类在库项目中包含的 jar 文件中

编辑: jar 文件添加到导出的条目(Order and Export-Tab 上的[x] my.jar来自图书馆项目)

有没有一种干净的方法可以让它工作?

最佳答案

官方API中有明确说明here :

A library project can include a JAR library

You can develop a library project that itself includes a JAR library, however you need to manually edit the dependent application project's build path and add a path to the JAR file

jar lib 必须手动添加到依赖应用程序项目的构建路径中,而不仅仅是库项目构建路径本身。

从 SDK r17 更新:

现在由 ADT 自动处理,查看 ADT 17.0.0 版本的新功能 here :

Added feature to automatically setup JAR dependencies. Any .jar files in the /libs folder are added to the build configuration (similar to how the Ant build system works). Also, .jar files needed by library projects are also automatically added to projects that depend on those library projects. (more info)

关于java - Android 外部库项目上的 NoClassDefFoundError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7994715/

相关文章:

java - Java数组中的某些字段为空,处理这些

java - android.view.InflateException : Binary XML file line #2: Binary XML file line #2: Error inflating class android. 部件.RelativeLayout

java - 无法在 Eclipse IDE 中更改 Maven 版本

java - 不确定如何在 Java Slick 游戏中实现子弹系统?

android - App更新时是否删除了内部存储文件?

Android INSERT语句问题

android - 如何检查是否存在 GPS 传感器?

eclipse - 将 window tester 与 eclipse 集成以测试 UI

java - 为什么导入到eclipse中的maven项目没有得到 "Maven Dependencies"列表?

eclipse - eclipse中当前日期和时间的命令行参数