流水不争先,争的是滔滔不绝

Android Studio 使用smack4.2

openfire 云聊IM 2167℃

本文已过时,新的Android Studio+smack4.3开发环境配置:

Android Studio 使用 smack4.3 搭建 Openfire+smack 开源IM开发环境


smack现在已经支持Android了,Android Studio已经成为主流Android开发IDE了,本文就介绍一下,如何在Android Studio 使用smack。

很简单,使用Android Studio导入smack就可以了

repositories {
  maven {
    url 'https://oss.sonatype.org/content/repositories/snapshots'
  }
  mavenCentral()
}

在Android Studio中,只需要将这段代码复制进build.gradle(Module: app)中就行,注意,repositories {} 与 android {}、dependencies {} 同级。

Smack configuration with smack-extensions for XMPP over TCP

dependencies {
  compile "org.igniterealtime.smack:smack-android-extensions:4.2.0"
  compile "org.igniterealtime.smack:smack-tcp:4.2.0"
}

Minimal Smack configuration for XMPP over TCP

dependencies {
  compile "org.igniterealtime.smack:smack-android:4.2.0"
  compile "org.igniterealtime.smack:smack-tcp:4.2.0"
}

这两段的含义是如何选择依赖项,前一个表示带有扩展的smack包,后一个表示最小化配置。

还可以选择带有实验特性的依赖包,如下:

Smack configuration with experimental extensions (XEP-0280, XEP-0352, XEP-0332, XEP-0335)

dependencies {
  compile "org.igniterealtime.smack:smack-android-extensions:4.2.0"
  compile "org.igniterealtime.smack:smack-experimental:4.2.0"
  compile "org.igniterealtime.smack:smack-tcp:4.2.0"
}

在这里本人选取第一个,最终修改的Gradle文件如下:

apply plugin: 'com.android.application'

android {...}

repositories {
    maven {
        url 'https://oss.sonatype.org/content/repositories/snapshots'
    }
    mavenCentral()
}

dependencies {
    compile "org.igniterealtime.smack:smack-android-extensions:4.2.0"
    compile "org.igniterealtime.smack:smack-tcp:4.2.0"
    ...
}

写到这边Gradle文件就算修改好了,然后一定要点击图中的同步按钮,Android Studio才会自动下载smack。

使用默认的配置,在有些android sdk下,会有如下警告:

Warning:WARNING: Dependency xpp3:xpp3:1.1.4c is ignored for release as it may be conflicting with the internal version provided by Android.
In case of problem, please repackage it with jarjar to change the class packages

只需要修改成如下即可:

dependencies {
    compile ("org.igniterealtime.smack:smack-android-extensions:4.2.0") {
        exclude module: 'xpp3'
    }
    compile ("org.igniterealtime.smack:smack-tcp:4.2.0") {
        exclude module: 'xpp3'
    }
}

参考:https://github.com/igniterealtime/Smack/wiki/Smack-4.2-Readme-and-Upgrade-Guide

版权声明:部分文章、图片等内容为用户发布或互联网整理而来,仅供学习参考。如有侵犯您的版权,请联系我们,将立刻删除。
点击这里给我发消息