我正在尝试使用ejabberd服务器和smack库实现聊天应用,但是在整合所有smack的jar包和依赖方面遇到了一些困难。我的开发环境是Android Studio。
我的build.gradle(module)文件内容:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.example.nit.xmppclient"
minSdkVersion 18
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.0'
compile "org.igniterealtime.smack:smack-android:4.1.0"
compile "org.igniterealtime.smack:smack-tcp:4.1.0"
compile "org.igniterealtime.smack:smack-android-extensions:4.1.0"
compile 'org.ogce:xpp3:1.1.6'
}
一开始我遇到了XMLpullparser错误,然后我添加了xpp3。但是在我添加了xpp3之后,我又遇到了
错误。Error:Gradle: Execution failed for task ':app:preDexDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/usr/lib/jvm/java-7-openjdk-amd64/bin/java'' finished with non-zero exit value 1
build.gradle(项目):
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots'
}
mavenCentral()
}
}
问题:
如何消除错误或错误的原因是什么。我可能会缺少一些依赖关系?
使用smock将增加应用程序的大小。我可以不使用任何库并编写服务器端代码来实现IM吗? 例如,使用node-js的ejabberd库,Android应用程序与nodejs对话而不是ejabberd?
还有一个问题:
public class XMPPClient {
private static int port = 5222;
private static String host = "my-ip";
private static String service = "my.com";
static XMPPTCPConnectionConfiguration conf = XMPPTCPConnectionConfiguration.builder()
.setServiceName(service)
.setPort(port)
.setHost(host)
.setCompressionEnabled(false).build();
static XMPPTCPConnection connection = new XMPPTCPConnection(conf);
public static void register(String username, String password) throws SmackException.NotConnectedException, XMPPException.XMPPErrorException, SmackException.NoResponseException {
AccountManager accountManager = AccountManager.getInstance(connection);
accountManager.createAccount(username,password);
}
public static void main (String args[]) throws SmackException.NotConnectedException, XMPPException.XMPPErrorException, SmackException.NoResponseException {
register("user", "password");
}
}
当我运行XMPPClient类时,出现了错误。