开发者

including pre-built java classes into an android project

i'm trying to include a maven java project into my android project. 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. the project is available here:

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. 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. in addition, resolving all of these dependencies manually is just ridiculous when i'm compiling a maven project that s开发者_StackOverflow社区hould be pretty simple.

however, i can use maven to compile the sources with no issue. 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? and for the record, i don't have the expertise to rewrite this entire api to work with the standard Android SDK.


If the third party library requires standard JRE classes to compile it likely requires them to run as well. Try removing the third party methods/classes from your build that access the unavailable JRE classes. 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.


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

Fortunately, I've written a plug-in which resolves these issues:

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. (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.

You can have the Android build inject copies of third-party libraries by adding them to external-libs. 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). Your app will have second copies of standard Java libraries classes that will almost surely not be compatible in some way.

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. Because actually in my experience Android has all the java.net classes so I'd be curious what's missing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜