Android 外部库项目上的 NoClassDefFoundError [英] NoClassDefFoundError on external library project for Android

查看:28
本文介绍了Android 外部库项目上的 NoClassDefFoundError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 eclipse 进行 Google Android 开发.

I use eclipse for Google Android development.

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

I've created a library project ([x] Is Library in the Android-settings), which includes an external jar-file (Referenced Libraries). This library project are referenced in another Project (the actual project which will use the library project). This is done by add the project under the Android-settings.

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

the source compiles but if I want to execute it on the device, I get the NoClassDefFoundError for a class which is inside the jar-file which is included in the library project.

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

The jar-file ist added to the exported entries ([x] my.jar on the Order and Export-Tab from the library project)

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

Is there a clean way to get this working?

推荐答案

官方API中已经明确说明此处:

It has been clearly stated in offcial API here:

一个库项目可以包含一个 JAR 库

A library project can include a JAR library

您可以开发一个本身包含 JAR 库的库项目,但是您需要手动编辑依赖应用程序项目的构建路径并添加 JAR 文件的路径

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 必须手动添加到依赖应用程序项目的构建路径中,而不仅仅是库项目构建路径本身.

The jar lib must be manually added to the dependent application project's build path, not only the library project build path itself.

从 SDK r17 更新:

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

This is automatically handled by ADT now, check out new feature for ADT 17.0.0 release here:

添加了自动设置 JAR 依赖项的功能./libs 文件夹中的任何 .jar 文件都会添加到构建配置中(类似于 Ant 构建系统的工作方式).此外,库项目所需的 .jar 文件也会自动添加到依赖于这些库项目的项目中.(更多信息)

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)

这篇关于Android 外部库项目上的 NoClassDefFoundError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆