将外部 .jar 文件导入 Android 项目 [英] Importing external .jar file to Android project

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

问题描述

我有一个标准的 Java 项目,我在其中编写了代码来解析来自 Internet 的一些 BBC Radio XML 数据.该项目称为 BBCSchedules,我感兴趣的课程称为 BBCChannel.

I have a standard Java project in which I've written code to parse some BBC Radio XML data from the internet. The project is called BBCSchedules and the class I'm interested in is called BBCChannel.

我现在正在尝试在 Android 应用程序中使用 BBCChannel 类.我应该怎么做?

I'm now trying to use the BBCChannel class in an Android application. How should I go about doing this?

我尝试了各种方法,遵循互联网上的各种建议,目前我要做的就是将我的 BBCSchedules 项目编译为 .jar 文件,然后使用构建路径/库/添加外部 Jar 选项.但是,Eclipse 仍然无法识别 BBCChannel 类,因此不会让我运行该应用程序.

I've tried various things, following various bits of advice on the internet, and the place I've got to at the moment is compiling my BBCSchedules project to a .jar file, and importing that to the Android project using the Build Path/Library/Add External Jar option. However, Eclipse still doesn't recognise the BBCChannel class, and won't let me run the application because of this.

我想我做了一些愚蠢的错误,但那是什么?

I guess I've done something silly wrong, but what is it?

更新:我已经尝试了 如何在 Android 项目中使用外部 JAR? 以及我发现的其他各种 StackOverflow 问题似乎与此相关,但似乎没有任何效果.还有其他想法吗?

UPDATE: I've tried the steps listed in How can I use external JARs in an Android project? and various other StackOverflow questions I can find that seem to be related to this, but absolutely nothing seems to work. Any other ideas?

更新:我与下面第一个答案的作者进行的讨论表明,这与我如何使用 Eclipse 附加 .jar 文件有关.他发送给我的带有 .jar 文件的项目不起作用.任何人还有其他想法吗?

UPDATE: The discussions I've had with the author of the first answer below suggest that it is something to do with how I am using Eclipse to attach the .jar file. The project he sent me with the .jar file already attached didn't work. Any other ideas anyone?

推荐答案

将 JAR 放在项目的 libs/ 目录中.然后 Build Path -> Library -> Add JAR 应该允许您从项目中选择一个.IIRC,这适用于 Eclipse.

Put the JAR in your project's libs/ directory. Then Build Path -> Library -> Add JAR should allow you to pick the one out of your project. IIRC, this works with Eclipse.

如果您决定某天转储 Eclipse,只需将您的 JAR 放在 libs/ 中就足够了 -- 命令行构建工具会自动获取它.

If you decide someday to dump Eclipse, just having your JAR in libs/ is enough -- the command-line build tools will pick it up automatically.

更新:如果您有 ADT Eclipse 插件的 R17 或更新版本,现在您只需添加一个 libs/ 目录并将您的 JAR 放在那里.它将自动添加到您的构建路径中,就像命令行构建一样.

UPDATE: If you have the R17 or newer version of the ADT Eclipse plugin, now you only need to add a libs/ directory and put your JAR in there. It will automatically be added to your build path, much like with command-line builds.

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

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