简体   繁体   English

将预建的Java类包含到android项目中

[英]including pre-built java classes into an android project

i'm trying to include a maven java project into my android project. 我正在尝试将Maven Java项目包含到我的Android项目中。 the maven project is the greader-unofficial project which allows developers access to google reader accounts, and handles all of the http transactions and URI/URL building, making grabbing feeds and items from google reader transparent to the developer. Maven项目是一个非官方的greader项目,它使开发人员可以访问google阅读器帐户,并处理所有http交易和URI / URL的构建,从而使抓取feed和项目对于Google开发者是透明的。 the project is available here: 该项目在这里可用:

http://code.google.com/p/greader-unofficial/ http://code.google.com/p/greader-unofficial/

the code is originally written for the standard jdk and uses classes from java.net that are not a part of the standard Android SDK. 该代码最初是为标准jdk编写的,并使用java.net中的类,这些类不是标准Android SDK的一部分。 i actually tried to manually resolve all dependencies and ran into a problem when i got as far as including com.sun.syndication pieces required by the class be.lechtitseb.google.reader.api.util.AtomUtil.java... some of the classes in java.net that are in the standard jdk (i'm using 1.6) are not in the Android SDK. 我实际上试图手动解决所有依赖关系,并在遇到包括be.lechtitseb.google.reader.api.util.AtomUtil.java类所需的com.sun.syndication片段时遇到了问题。标准jdk(我正在使用1.6)中的java.net中的类不在Android SDK中。 in addition, resolving all of these dependencies manually is just ridiculous when i'm compiling a maven project that should be pretty simple. 另外,当我正在编译应该非常简单的Maven项目时,手动解决所有这些依赖关系是荒谬的。

however, i can use maven to compile the sources with no issue. 但是,我可以使用maven毫无问题地编译源代码。 how can i include this maven project, which is dependent on the complete jdk, into my android project in such a way that it will compile so that i can access the GoogleReader class from my android project? 我如何将依赖完整jdk的maven项目包含到我的android项目中,使其能够编译,以便我可以从我的android项目访问GoogleReader类? and for the record, i don't have the expertise to rewrite this entire api to work with the standard Android SDK. 记录下来,我不具备重写整个api的专业知识,无法与标准Android SDK一起使用。

If the third party library requires standard JRE classes to compile it likely requires them to run as well. 如果第三方库需要标准JRE类进行编译,则可能要求它们也运行 Try removing the third party methods/classes from your build that access the unavailable JRE classes. 尝试从构建中删除访问不可用JRE类的第三方方法/类。 If your app still works with a stripped down library then deliver that (assuming the license is compatible with the change.) Likely, your only other option for that third party library is to replace the offending JRE calls with workarounds. 如果您的应用仍然可以使用简化的库,则可以交付该库(假设许可证与更改兼容)。很可能,该第三方库的唯一其他选择是用替代方法来替换有问题的JRE调用。

Unfortunately there are several problems using Eclipse with M2Eclipse/maven, most notably that the ADT does not package the JAR file dependencies into the APK file 不幸的是,将Eclipse与M2Eclipse / maven结合使用时会遇到一些问题,最值得注意的是ADT不会将JAR文件依赖项打包到APK文件

Fortunately, I've written a plug-in which resolves these issues: 幸运的是,我编写了一个插件来解决这些问题:

https://code.google.com/a/eclipselabs.org/p/m2eclipse-android-integration/ https://code.google.com/a/eclipselabs.org/p/m2eclipse-android-integration/

The issue isn't building / compiling the code, right? 问题不是构建/编译代码,对不对? It compiles just fine, as you say. 正如您所说,它编译得很好。 It uses classes, directly or indirectly, that are not available in Android. 它使用直接或间接在Android中不可用的类。 (And, I do stress that even if it compiles, it doesn't mean it will run on Android, as it may need classes at runtime that aren't in Android.) So the issue is getting these classes into your .apk. (而且,我确实强调,即使可以编译,也并不意味着它将在Android上运行,因为它可能在运行时需要的类不在Android中。)因此,问题在于将这些类放入您的.apk中。

You can have the Android build inject copies of third-party libraries by adding them to external-libs . 您可以通过将Android第三方库的副本添加到external-libs来构建Android注入。 However I don't know that it works to just put the JDK's rt.jar file there (which has all java.net classes and everything else too). 但是我不知道将JDK的rt.jar文件放在那里(它具有所有java.net类以及其他所有内容)是否起作用。 Your app will have second copies of standard Java libraries classes that will almost surely not be compatible in some way. 您的应用将具有标准Java库类的第二份副本,这些副本几乎肯定在某种程度上不兼容。

I strongly suspect it won't work, or if it happens to, will be fragile. 我强烈怀疑它不起作用,或者碰巧会很脆弱。

Is modifying the library so hard? 修改库这么难吗? If there are just a few java.net classes that aren't available, perhaps in a separate question you can solicit ideas about ways to work around not having them. 如果只有几个java.net类不可用,也许在一个单独的问题中,您可以征求有关如何解决这些问题的想法。 Because actually in my experience Android has all the java.net classes so I'd be curious what's missing. 因为实际上以我的经验,Android具有所有java.net类,所以我很想知道缺少什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM