android - NoClassDefFoundError:org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration 仅 API 19

标签 android exception noclassdeffounderror android-4.4-kitkat smack

一周前,我开始使用 Smack API(4.1.8 版)为我的应用程序实现聊天系统。它也适用于 Lolipop 设备和 Marshmallow。但是在 Kitkat(API 19)上我得到异常 NoClassDefFoundError 登录目录:

    Process: mobi, PID: 23510
    java.lang.NoClassDefFoundError: org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration
    at mobi.networking.ChatXMPPConnection.connect(ChatXMPPConnection.java:76)
    at mobi.networking.ChatXMPPService.initConnection(ChatXMPPService.java:80)
    at mobi.networking.ChatXMPPService.access$100(ChatXMPPService.java:36)
    at mobi.networking.ChatXMPPService$1.run(ChatXMPPService.java:112)
    at java.lang.Thread.run(Thread.java:841)

那么第76行(第一行)是什么:

XMPPTCPConnectionConfiguration.Builder configBuilder = XMPPTCPConnectionConfiguration.builder();
        configBuilder.setUsernameAndPassword(mUsername, mPassword);
        configBuilder.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
        configBuilder.setResource("Android");
        configBuilder.setServiceName(DOMAIN);
        configBuilder.setHost(HOST);
        configBuilder.setPort(PORT);

我的构建等级:

apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.3"
    dataBinding
            {
                enabled = true
            }

    defaultConfig {
        applicationId "mobi"
        minSdkVersion 19
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    allprojects {
        repositories {
            maven { url "https://jitpack.io" }
            maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
            mavenCentral()

        }

    }

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        testCompile 'junit:junit:4.12'
        compile 'com.android.support:appcompat-v7:24.0.1'
        compile 'com.android.support:design:24.0.1'
        compile 'de.hdodenhof:circleimageview:2.1.0'
        compile 'com.google.android.gms:play-services-appindexing:9.8.0'
        compile 'com.android.support:recyclerview-v7:24.0.1'
        compile 'com.zaihuishou:expandablerecycleradapter-databinding:1.0.0'
        compile 'com.bignerdranch.android:expandablerecyclerview:3.0.0-SNAPSHOT'
        compile 'com.kyleduo.switchbutton:library:1.4.1'
        compile 'info.hoang8f:android-segmented:1.0.6'
        compile 'com.github.Kennyc1012:BottomSheet:2.3.1'
        compile 'com.aurelhubert:ahbottomnavigation:1.3.3'
        compile 'com.vk:androidsdk:1.6.5'
        compile 'com.brucetoo.pickview:library:1.2.2'
        compile 'gun0912.ted:tedpermission:1.0.0'
        compile 'com.squareup.okio:okio:1.11.0'
        compile 'com.squareup.okhttp3:okhttp:3.4.1'
        compile 'com.squareup.picasso:picasso:2.5.2'
        compile 'com.basgeekball:awesome-validation:1.3'
        compile 'com.google.code.gson:gson:2.4'
        compile 'com.facebook.android:facebook-android-sdk:[4,5)'
        compile 'com.github.aakira:expandable-layout:1.6.0@aar'
        compile 'fr.xebia.android.freezer:freezer:2.0.3'
        provided 'fr.xebia.android.freezer:freezer-annotations:2.0.3'
        apt 'fr.xebia.android.freezer:freezer-compiler:2.0.3'
        compile "me.henrytao:smooth-app-bar-layout:24.2.1.0"
        compile ("org.igniterealtime.smack:smack-android-extensions:4.1.8") {
            exclude group: 'xpp3', module: 'xpp3'
        }
        compile ("org.igniterealtime.smack:smack-tcp:4.1.8"){
            exclude group: 'xpp3', module: 'xpp3'
        }
        compile ("org.igniterealtime.smack:smack-experimental:4.1.8"){
            exclude group: 'xpp3', module: 'xpp3'
        }
    }
}

另外,我的 libs 文件夹是空的。我不使用 jar 文件

Smack-Wiki 链接 https://github.com/igniterealtime/Smack/wiki/Smack-4.1-Readme-and-Upgrade-Guide#using-eclipses-android-development-tools-adt-ant-based-build

拜托,帮忙,我花了两天时间修好它

最佳答案

我也遇到了同样的问题。 尝试添加以下依赖项:

编译 'com.android.support:multidex:1.0.1'

然后在你的应用程序类中添加这个,

 @Override   
    protected void attachBaseContext(Context base)  
    {   
           super.attachBaseContext(base);  
           MultiDex.install(BaseApplication.this);  
    } 

关于android - NoClassDefFoundError:org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration 仅 API 19,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40331861/

相关文章:

android - android 中的 java.lang.UnsatisfiedLinkError 错误

android - 使用已安装的文件编辑器(如果有)编辑纯文本文件的 Intent

java - Hibernate 3.2.0 Final 中的二级缓存

java.lang.NoClassDefFoundError : occurs after multiple uses of a program

android - java.lang.NoClassDefFoundError 在 Android 1.5 中用我自己的包抛出

安卓电池/使用统计

android - 在 ListView 中查找点击的行并获取数据

c++ - 异常安全 - 可靠回滚对象状态的模式

c# - 在 .NET 中读取 native win32 异常数据/参数

java - Android Exoplayer音频播放异常