Smack 4.1 Readme and Upgrade Guide

Florian Schmaus edited this page Nov 2, 2015 · 14 revisions

Smack 4.1 Readme and Upgrade Guide

Smack 4.1 release highlights include support for XEP-198: Stream Management (SMACK-333) and native support for Android. Smack 4.1 obsoletes and is the legitimate successor of aSmack.

Stream Management (XEP-198)

Stream Management is disabled per default in Smack 4.1. You can set it to enabled with XMPPTCPConnection.setUseStreamManagement(true).

More about XEP-198

API Changes

Warning: This list may not be complete

  • XMPPConnection is now an interface. Use either AbstractXMPPConnection or one of its subclasses as static type when declaring the connection
  • SASL authentication was reworked, if you use custom SASL mechanisms then you may have to adopt your code
  • IQ request handler API added. Packet listeners and collectors are no longer able to listen for IQ requests, i.e. IQs of type 'get' or 'set'.
  • XMPPConnection.addPacketListener is deprecated: use either addAsyncPacketListener or addSyncPacketListener and their remove counterparts
  • StringUtils is now to be found as XmppStringUtils in jxmpp-core (which Smack 4.1 automatically pulls in). The method names changed a bit, e.g. parseName became parseLocalpart and so on.
  • AccountManager is now in smackx, since its specification is no longer part of the XMPP RFC(s), but instead a XEP. Use find . -type f -name '*.java' |xargs sed -i 's/import org.jivesoftware.smack.AccountManager;/import org.jivesoftware.smackx.iqregister.AccountManager;/' to change your source code accordingly.
  • MessageListener has been renamed to ChatMessageListener. Attention: MessageListener still exists with a different interface contract!
  • ConnectionConfiguration uses the builder pattern
  • FormField.getType and Form.getType became Enums. Watch out for broken comparisons like formField.getType().equals("hidden")
  • Packet became a deprecated interface. Use the new Stanza class and getStanzaId instead of getPacketID
  • Roster now follows the Manager pattern (use Roster.getInstanceFor(XMPPConnection) to obtain an instance, XMPPConnection.getRoster() is no longer available)
  • ConnectionListener.authenticated adds a new boolean parameter resumed
  • XMPPTCPConnection.addStanzaAcknowledgedListener does not throw StreamManagementNotEnabledException anymore - use XMPPTCPConnection.isSmEnabled
  • Use ConnectionConfiguration.Builder.allowEmptyOrNullUsernames if you use SASL EXTERNAL
  • SmackConfiguration.DEBUG_ENABLED became SmackConfiguration.DEBUG

Including Smack 4.1 into your project

Compared to Smack 4.0, Smack 4.1 provides two artifacts as entry points that you can refer to when including Smack in your project. A typical Smack setup may also want to additional declare dependencies on smack-tcp, smack-extensions and smack-experimental

Projects that target a JVM supporting Java7

With Gradle

repositories {
  maven {
    url 'https://oss.sonatype.org/content/repositories/snapshots'
  }
  mavenCentral()
}
dependencies {
   compile "org.igniterealtime.smack:smack-java7:4.1.0"
   // Optional for XMPPTCPConnection
   compile "org.igniterealtime.smack:smack-tcp:4.1.0"
   // Optional for XMPP-IM (RFC 6121) support (Roster, Threaded Chats, …)
   compile "org.igniterealtime.smack:smack-im:4.1.0"
   // Optional for XMPP extensions support
   compile "org.igniterealtime.smack:smack-extensions:4.1.0"
}

With Maven

<dependency>
        <groupId>org.igniterealtime.smack</groupId>
        <artifactId>smack-java7</artifactId>
        <version>4.1.0</version>
</dependency>
<dependency>
        <groupId>org.igniterealtime.smack</groupId>
        <artifactId>smack-tcp</artifactId>
        <version>4.1.0</version>
</dependency>
<dependency>
        <groupId>org.igniterealtime.smack</groupId>
        <artifactId>smack-im</artifactId>
        <version>4.1.0</version>
</dependency>
<dependency>
        <groupId>org.igniterealtime.smack</groupId>
        <artifactId>smack-extensions</artifactId>
        <version>4.1.0</version>
</dependency>

With Ivy

<dependency org="org.igniterealtime.smack" name="smack-java7" rev="4.1.0"/>
<dependency org="org.igniterealtime.smack" name="smack-tcp" rev="4.1.0"/>
<dependency org="org.igniterealtime.smack" name="smack-extensions" rev="4.1.0"/>

Projects that target Android

With Gradle

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

Smack configuration with smack-extensions for XMPP over TCP

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

Minimal Smack configuration for XMPP over TCP

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

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

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

Using Eclipse's Android Development Tools (ADT) Ant based build

We recommend using the MavenToAndroidAnt Python3 script to fetch the required artifacts from maven central. Use the following artifact definition file

org.igniterealtime.smack,smack-android,4.1.1,1357B01865B2503C18453D208CAC2A9678548E35
org.igniterealtime.smack,smack-android-extensions,4.1.1,1357B01865B2503C18453D208CAC2A9678548E35
org.igniterealtime.smack,smack-core,4.1.1,1357B01865B2503C18453D208CAC2A9678548E35
org.igniterealtime.smack,smack-tcp,4.1.1,1357B01865B2503C18453D208CAC2A9678548E35
org.igniterealtime.smack,smack-extensions,4.1.1,1357B01865B2503C18453D208CAC2A9678548E35
org.igniterealtime.smack,smack-experimental,4.1.1,1357B01865B2503C18453D208CAC2A9678548E35
org.igniterealtime.smack,smack-resolver-minidns,4.1.1,1357B01865B2503C18453D208CAC2A9678548E35
org.igniterealtime.smack,smack-sasl-provided,4.1.1,1357B01865B2503C18453D208CAC2A9678548E35
org.jxmpp,jxmpp-core,0.4.2-beta1,1357B01865B2503C18453D208CAC2A9678548E35
org.jxmpp,jxmpp-util-cache,0.4.2-beta1,1357B01865B2503C18453D208CAC2A9678548E35
de.measite.minidns,minidns,0.1.1,4677EF84C286721DA33C09C98D2028BA8AF1E192

and save it as artifacts.csv. Now run

getMavenArtifactsNg.py -f artifacts.csv -p <projectdir>

to let the script download and install the artifacts into your Android Ant project.