NoClassDefFoundError:org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration only API 19

时间:2016-10-30 17:48:55

标签: android exception noclassdeffounderror android-4.4-kitkat smack

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

    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);

我的构建gradle:

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

请帮助,我在修理它时花了两天时间

1 个答案:

答案 0 :(得分:1)

我也面临同样的问题。 尝试添加以下依赖项:

compile 'com.android.support:multidex:1.0.1'

并在您的应用程序类中添加此内容,

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