导入Java项目在Android应用程序? [英] Import Java Project in Android application?

查看:144
本文介绍了导入Java项目在Android应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用Java项目的Andr​​oid项目,即使从Java项目的一些班级在一个正常的Andr​​oid项目不被认可?例如javax.xml包装?

Can I use a Java Project in an Android Project even if some classes from the java project are not recognized in a normal android project? For example javax.xml package?

有两个可能性,因为我看到它:

There are 2 possibilities as I see it:

  1. 无论是创建与Java项目罐子并将其导入机器人
  2. 或者引用的Andr​​oid项目(因为我知道这是可能的)。

但无论哪种方式,都会被发现,在java中,但不是在Android的这些类是确定在我的Andr​​oid应用程序?将这项工作?谢谢。

But in either way, will those classes that are found in java but not in android be ok in my Android Application? Will this work? Thank you.

我做了JavaProject,然后导入它在我的Andr​​oid项目作为参考。我得到一个错误,我没有想到的,它不会从我的Java项目识别我.classes。

I made the JavaProject, and then imported it in my Android Project as a reference. I get an error i did not expect, it does not recognize my .classes from my Java Project.

推荐答案

如果您使用的是Eclipse(与ADT插件),你可以参考Java项目在你的Andr​​oid项目的构建路径。这会在你的apk文件输出封装这些类,并允许您使用它们在你的应用程序。

正如你指出你的意见;引用Java项目作为一个Android库将不会在你的情况下工作,因为使用javax的presence。*包会导致在Eclipse编译时错误。在这种情况下,你需要选择选项1,并从你的Java项目生成一个JAR文件,它包含的这里解释。通过这种方式,需要使用javax类文件。*不应产生任何编译/运行时错误的,除非你试图使用它们。无论哪种方式,使用的 Java构建路径的将无法正常工作,你期望 - 类文件不会被捆绑这样

As you pointed out in your comments; referencing a Java project as an Android library will not work in your case, since the presence of the javax.* packages will result in compile time errors in Eclipse. In this case, you will need to opt for option 1 and build a Jar file from your Java project and include it as explained here. This way, the class files requiring javax.* should not produce any compile/runtime errors unless you try to use them. Either way, using the Java build path will not work as you expect - the class files are not bundled this way.

Android平台提供一些javax.xml 的,但不是整个包(读本文了解更多这方面的细节)。通常情况下,最简单的解决办法是写你的影响的Java code一款Android相当于不需要缺少的依赖关系,并的 2实现所以正确的一个用于每个项目。

The Android platform provides some of javax.xml, but not the whole package (read this document for more detail on this). Often the easiest solution is to write an Android equivalent of your affected Java code that does not require the missing dependencies, and bridge the 2 implementations so the correct one is used for each project.

这篇关于导入Java项目在Android应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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