如何在Android中使用Smack 4.1? [英] How to use Smack 4.1 in Android?

查看:204
本文介绍了如何在Android中使用Smack 4.1?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在看这个答案使用您自己的XMPP服务器的Android聊天应用程序(Smack API)了解可用的XMPP API。 Smack似乎是一个不错的选择。

I was looking at this answer Using your own XMPP server for android chat app (Smack API) to learn about the available XMPP APIs. Smack seems like a good choice.

在Smack 4.1之前,一个人不得不依靠aSmack。从4.1开始,Smack将在Android上本机运行。我有几个入门的问题。

Prior to Smack 4.1 one had to rely on aSmack. Starting with 4.1, Smack will run natively on Android. I have a couple of "getting started" questions.

问题1:

如何在Eclipse中的Android项目中包含Smack 4.1? strong>

这里的说明 https://github.com/igniterealtime/Smack/wiki/Smack-4.1-Readme-and-Upgrade-Guide 似乎适用于Android Studio

Question 1:
How do I include Smack 4.1 in my Android project in Eclipse?
The instructions here https://github.com/igniterealtime/Smack/wiki/Smack-4.1-Readme-and-Upgrade-Guide seem to be for Android Studio

问题2:

Android的代码是否保持不变?

我在这里指的是他们的官方文档: a href =https://www.igniterealtime.org/builds/smack/docs/latest/documentation/index.html =nofollow noreferrer> https://www.igniterealtime.org/builds/smack/docs /latest/documentation/index.html

我想知道的是API的使用在Android中是否保持不变。

Question 2:
Will the code stay the same for Android?
I am referring to their official documentation here: https://www.igniterealtime.org/builds/smack/docs/latest/documentation/index.html
What I would like to know is whether the usage of the API will stay the same in Android, too.

推荐答案


如何在我的Android项目中包含Smack 4.1在Eclipse中?

How do I include Smack 4.1 in my Android project in Eclipse?

像您将在Eclipse Android项目中包含任何其他Java库。通过在 libs / 目录中放置 .jar 文件,Eclipse Android Ant构建系统将使它们可用于项目类路径,并将它们包含在生成的 .apk 中。

Like you would include any other Java library in Eclipse Android project. By putting the .jar files in the libs/ directory, the Android plugin of Eclipse and the Android Ant build system will make them available to the projects classpath and include them in the resulting .apk.

与Smack 4.1相同的是,它是高度模块化的。如果你想要一个全功能的Smack在Android上,你需要一些大约11 .jar 文件。现在,您可以使用毕业生使用Android Studio,这样包括Smack就像添加

The thing with Smack 4.1 is, that it is heavily modularized. If you want a full featured Smack on Android you need something around 11 .jar files. Now, you could use Android Studio using gradle, this way including Smack as is simple as adding

dependencies {
  compile "org.igniterealtime.smack:smack-android:4.1.0-rc1"
  compile "org.igniterealtime.smack:smack-tcp:4.1.0-rc1"
  // optional features
  compile "org.igniterealtime.smack:smack-android-extensions:4.1.0-rc1"
}

和gradle将负责解决传递依赖关系。

and gradle will take care of resolving the transitive dependencies.

,Android Studio或Android毕业插件精准,不支持使用源附件 1 进行下载和调试。这是您使用开源库时明确要求的。

But, Android Studio, or the Android gradle plugin to be precise, does not support downloading and debugging with source attachments1. And this is something you clearly want when working with open source libraries.

这是我自己不使用毕业插件的原因之一。我不能开发Smack(我也喜欢Eclipse,但这是一个不同的故事)。

That's for example one of the reasons I don't use the gradle plugin myself. I could not develop Smack then (I also like Eclipse, but that's a different story).

所以我们回到Eclipse / Ant进行Android项目的工作。 Smack 4.1自述文件告诉您使用 MavenToAndroidAnt Python3 脚本,它将自动下载工件并删除旧的工件。如果您将其挂接到构建过程中,它几乎和使用gradle 一样好,但也支持源附件

So we are back at working with Eclipse/Ant for our Android project. The Smack 4.1 README tells you to use the MavenToAndroidAnt Python3 script, which will automatically download the artifacts and delete the old ones on an update. If you hook it into your build process, it's nearly as good as using gradle but also supports source attachments.

当然你也可以添加11个 .jar 文件,但是谁想要这样做,并在其源存储库中有二进制文件?

Of course you could also add the 11 .jar files manually, but who wants to do that and have binaries in their source repository?


Android的代码是否保持不变?

Will the code stay the same for Android?

是的,从Smack 4.1开始,Smack是Smack。所以你可以参考相同的javadoc,无论你是否在Android上。请注意,aSmack也是如此,因为它只是Smack到Android的端口。

Yes, starting with Smack 4.1, Smack is Smack. So you can refer to the same javadoc, no matter if you are on Android or not. Note that this was also true for aSmack, since it's just a port of Smack to Android.

1:如果我错了,更正我,但上次我尝试是不可能的在此期间情况可能会更好。

1: Correct me if I'm wrong, but last time I tried it was not possible. The situation may got better in the meantime.

这篇关于如何在Android中使用Smack 4.1?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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