在 Android 上使用 EWS Java API 时出现问题
我尝试在 Android 应用程序中使用 EWS Java API v1.1.5 (http://archive.msdn.microsoft.com/ewsjavaapi),但遇到了许多问题。 我下载了源代码,并按照提供的说明在 Eclipse 中编译 EWS Java API。在这些说明中,您被告知下载并 添加以下预先要求的 jar 文件依赖项:
- commons-codec-1.4.jar
- commons-httpclient-3.1.jar
- commons-logging-1.1.1.jar
- jcifs-1.3.15.jar
我这样做了,并按照构建说明进行操作生成了以下 jar 文件:
- EWSAPI-1.1.0.jar
- EWSAPIWithJars-1.1.0
接下来,我构建了一个全新的 Android 应用程序,向清单添加了适当的权限,然后然后将以下源添加到主要活动的 OnCreate 中:
ExchangeService service = new ExchangeService();
ExchangeCredentials credentials = new WebCredentials("emailaddress", "password");
service.setCredentials(credentials);
try
{
service.autodiscoverUrl("emailaddress", this);
}
catch (Exception e)
{
e.printStackTrace();
}
我首先尝试使用 EWSAPI-1.1.0.jar 文件作为依赖项来运行此应用程序。当我这样做时,我得到了以下致命错误:
未捕获的处理程序:线程主线程由于未捕获的异常而退出 java.lang.NoClassDefFoundError: org.apache.commons.httpclient.MultiThreadedHttpConnectionManager 位于 microsoft.exchange.webservices.data.ExchangeServiceBase。(未知 来源)于 microsoft.exchange.webservices.data.ExchangeServiceBase。(未知 来源)于 microsoft.exchange.webservices.data.ExchangeService。(未知 来源)于 com.meshin.exchange.ExchangeDiscoveryActivity.onCreate(ExchangeDiscoveryActivity.java:40)
根据我的研究,似乎会生成此错误,因为 Android 附带了 Apache HttpClient 4.0,但它没有出现 不再有 MultiThreadedHttpConnectionManager 类。
如果我删除 EWSAPI-1.1.0.jar,并使用 EWSAPIWithJARS-1.1.0.jar 文件作为依赖项,则会收到以下错误:
VFY:无法解析静态方法 908:Ljavax/xml/stream/XMLOutputFactory; newInstance()Ljavax/xml/stream/XMLOutputFactory; VFY:L 中的死代码 0x0008-006a microsoft/exchange/webservices/data/EwsUtilities;.formatLogMessage (Ljava/lang/String;Ljava/lang/String;) Ljava/lang/String; VFY:无法找到签名中引用的类(Ljavax/xml/stream/XMLStreamWriter;)
然后最终...
致命异常:主要 java.lang.VerifyError: microsoft.exchange.webservices.data.AutodiscoverService 位于 microsoft.exchange.webservices.data.ExchangeService.getAutodiscoverUrl(未知 来源)于 microsoft.exchange.webservices.data.ExchangeService.autodiscoverUrl(未知 来源)于 com.meshin.exchange.ExchangeDiscoveryActivity.onCreate(ExchangeDiscoveryActivity.java:41)
我假设是因为现在我包含了 HttpClient 3.1 jar,它与 Android 库中包含的 HttpClient 4.0 jar 冲突。
我的问题是,是否有一种方法可以让我在 Android 项目中使用 EWS Java API,而不必重写其中引用的部分 HttpClient 3.1 特有的东西在 4.0 中不再存在。
I am trying to use the EWS Java API v1.1.5 (http://archive.msdn.microsoft.com/ewsjavaapi) in an Android application, and have run into a number of issues.
I downloaded the source, and followed the instructions provided to compile the EWS Java API in Eclipse. In those instructions you are told to download and
add the following pre-requiste jar file dependencies:
- commons-codec-1.4.jar
- commons-httpclient-3.1.jar
- commons-logging-1.1.1.jar
- jcifs-1.3.15.jar
I did this, and followed the build instructions with produced the following jar files:
- EWSAPI-1.1.0.jar
- EWSAPIWithJars-1.1.0
Next, I built a brand new Android application, added the appropriate permissions to the manifest, and then added the following source to the primary activity's OnCreate:
ExchangeService service = new ExchangeService();
ExchangeCredentials credentials = new WebCredentials("emailaddress", "password");
service.setCredentials(credentials);
try
{
service.autodiscoverUrl("emailaddress", this);
}
catch (Exception e)
{
e.printStackTrace();
}
I first tried running this application with the EWSAPI-1.1.0.jar file as a dependency. When I did that, I obtained the following fatal error:
Uncaught handler: thread main exiting due to uncaught exception
java.lang.NoClassDefFoundError:
org.apache.commons.httpclient.MultiThreadedHttpConnectionManager at
microsoft.exchange.webservices.data.ExchangeServiceBase.(Unknown
Source) at
microsoft.exchange.webservices.data.ExchangeServiceBase.(Unknown
Source) at
microsoft.exchange.webservices.data.ExchangeService.(Unknown
Source) at
com.meshin.exchange.ExchangeDiscoveryActivity.onCreate(ExchangeDiscoveryActivity.java:40)
From what I've researched, it seems like this error is being generated because Android comes with the Apache HttpClient 4.0, which doesn't appear
to have the MultiThreadedHttpConnectionManager class anymore.
If I instead remove the EWSAPI-1.1.0.jar, and instead use the EWSAPIWithJARS-1.1.0.jar file as a dependency, I get the following error:
VFY: unable to resolve static method 908: Ljavax/xml/stream/XMLOutputFactory;
newInstance()Ljavax/xml/stream/XMLOutputFactory;
VFY: dead code 0x0008-006a in L
microsoft/exchange/webservices/data/EwsUtilities;.formatLogMessage
(Ljava/lang/String;Ljava/lang/String;) Ljava/lang/String;
VFY: unable to find class referenced in signature (Ljavax/xml/stream/XMLStreamWriter;)
And then eventually...
FATAL EXCEPTION: main java.lang.VerifyError:
microsoft.exchange.webservices.data.AutodiscoverService at
microsoft.exchange.webservices.data.ExchangeService.getAutodiscoverUrl(Unknown
Source) at
microsoft.exchange.webservices.data.ExchangeService.autodiscoverUrl(Unknown
Source) at
com.meshin.exchange.ExchangeDiscoveryActivity.onCreate(ExchangeDiscoveryActivity.java:41)
I am assuming because now I am including the HttpClient 3.1 jar and it is conflicting with the HttpClient 4.0 jar included with the Android libraries.
My question is if there is a way for me to use the EWS Java API in an Android project without having to re-write the parts of it which reference
HttpClient 3.1-specific things which are no longer in 4.0.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以通过执行以下步骤来使用适用于 Android 的微软 EWS api,
下载 URL 中提供的源代码,
http://archive.msdn.microsoft.com/ewsjavaapi
EWSJavaAPI_1.1.5.zip
对上述 api 进行更改,使其适用于 eclipse 中的 JDK 1.4,如删除覆盖注释等
在下面的 URL 中下载 javax.* 包的源代码,
http://www.java2s.com/Code/ JarDownload/jsr173/jsr173_1.0_src.jar.zip
下载stax api可用的源代码在下面的网址中,
http://dist.codehaus.org/stax/ distributions/stax-src-1.2.0.zip
将所有源保留在 eclipse 中的单个 java 项目下
打开项目资源管理器并选择以“javax”开头的包并重命名为您的公司名称,例如:com。 注意: Eclipse 将询问所有要更改的命名上下文,然后单击“确定”。
将所有 java 源导出到一个 jar 文件。
那么您就可以在 Android 应用程序中使用该 jar 了,没有任何问题。
我使用了上面解释的相同方法,它在 Android 应用程序中 100% 完美地工作。
You can use microsoft's EWS api for android by doing the following steps,
download the source code available in the URL,
http://archive.msdn.microsoft.com/ewsjavaapi
EWSJavaAPI_1.1.5.zip
Make the changes to above api to work for JDK 1.4 in eclipse like remove override annotations e.t.c
Download source code of javax.* package available in below URL,
http://www.java2s.com/Code/JarDownload/jsr173/jsr173_1.0_src.jar.zip
Download source code of stax api available in below URL,
http://dist.codehaus.org/stax/distributions/stax-src-1.2.0.zip
Keep all the sources under the single java project in eclipse
Open the project explorer and select the package which are starts with "javax" and rename to your company name eg: com. Note: Eclipse will ask for all the naming contexts will change then click OK.
Export all the java sources to one single jar file.
Then You good to go to use the jar in Android application with out any problems.
I used the same way explained above and it worked in android application 100% perfectly.
这不是一个有用的答案,但过去几周我一直在努力查看 EWS API,但没有成功。
我发现的主要问题是它引用了许多 Android 上没有的 javax API。你可以找到一个 hack 来解释如何“重新分类”这些,但我还没有让它工作;此外,DnsClient 引用了 jarsearches 仅返回 rt.jar(主运行时)的一些命名空间。如果将其包含在 Android 应用程序中,那就太疯狂了!
在找到 API 之前,我尝试使用 KSOAP 与 EWS 进行通信,但再次遇到了问题 - 您需要能够执行 NTLM 和 SSL,但我找不到任何方法以任何简单的方式将所有这些与 KSOAP 结合起来。
EWS API 看起来是可行的方法(为什么要重新发明轮子),但让它在 Android 上运行看起来非常棘手(如果不是不可能的话)
This isn't a useful answer but I've also been struggling to look at the EWS API over the last couple of weeks, with no success.
The main issue I've found is it references a lot of the javax APIs which aren't on Android. There's a hack you can find that explains how to "re-class" these but I've not got it working yet; in addition, the DnsClient references some namespaces that jarsearches only return for rt.jar - the main runtime. And including this in an Android app would just be crazy!
Before finding the API I was trying to use KSOAP to communicate with EWS but again ran into problems - you need to be able to do NTLM and SSL and I couldn't find any way of combining all these with KSOAP in any simple way.
The EWS API looks the way to go (why re-invent the wheel) but getting it working on Android looks very tricky (if not impossible)
请检查此库以获取解决方案
Please check this library for the solution