java.lang.NoClassDefFoundError:okhttp3.internal.Util

时间:2016-08-10 09:15:37

标签: okhttp3

[在此处输入图像说明] [1]

我的程序可以运行Android 5.1手机,但手机将无法运行Android 4.3,并且会在错误的底部用完



> E/AndroidRuntime: FATAL EXCEPTION: EventThread
>java.lang.NoClassDefFoundError: okhttp3.internal.Util
>at okhttp3.OkHttpClient.<clinit>(OkHttpClient.java:65)
>at okhttp3.OkHttpClient$Builder.<init>(OkHttpClient.java:381)>
at>io.socket.engineio.client.transports.WebSocket.doOpen(WebSocket.java:51)
    >at io.socket.engineio.client.Transport$1.run(Transport.java:75)
    >at io.socket.thread.EventThread.exec(EventThread.java:50)
    >at io.socket.engineio.client.Transport.open(Transport.java:70)
    >at io.socket.engineio.client.Socket.probe(Socket.java:458)
    >at io.socket.engineio.client.Socket.onOpen(Socket.java:471)
    >at io.socket.engineio.client.Socket.onHandshake(Socket.java:512)
    >at io.socket.engineio.client.Socket.onPacket(Socket.java:485)
    >at io.socket.engineio.client.Socket.access$900(Socket.java:30)
    >at io.socket.engineio.client.Socket$5.call(Socket.java:299)
    >at io.socket.emitter.Emitter.emit(Emitter.java:117)
    >at io.socket.engineio.client.Transport.onPacket(Transport.java:127)
    >at>io.socket.engineio.client.transports.Polling.access$700(Polling.java:17)
    >at>io.socket.engineio.client.transports.Polling$2.call(Polling.java:124)
    >at io.socket.engineio.parser.Parser.decodePayload(Parser.java:251)
>at>.socket.engineio.client.transports.Polling._onData(Polling.java:134)
    >at> io.socket.engineio.client.transports.Polling.onData(Polling.java:106)
    >at>io.socket.engineio.client.transports.PollingXHR$5$1.run(PollingXHR.java:113)
    >at io.socket.thread.EventThread$2.run(EventThread.java:75)
    >at>java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
    >at >java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
    >at java.lang.Thread.run(Thread.java:841)



my build.gradle


compileSdkVersion 24
    buildToolsVersion "24.0.0"
    // For customization of Volley to build.
    useLibrary 'org.apache.http.legacy'
    defaultConfig {
        applicationId "my---"
        minSdkVersion 16
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }

    packagingOptions {
        exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/dependencies.txt'
        exclude 'META-INF/LGPL2.1'
    }

    repositories {
        flatDir {
            dirs '../Libraries/aar'
        }
    }

    testOptions {
        unitTests.returnDefaultValues = true
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
     compile fileTree(include: ['*.jar'], dir: 'libs')
        compile 'com.android.support:appcompat-v7:24.1.1'
        compile 'com.android.support:design:24.1.1'
        compile 'com.android.support:cardview-v7:24.1.1'
        compile 'com.android.support:customtabs:24.1.1'
        compile 'com.android.support:preference-v7:24.1.1'
        compile 'com.android.support:preference-v14:24.1.1'
        compile 'com.android.support:recyclerview-v7:24.1.1'
        compile 'com.android.support:support-v4:24.1.1'
        compile 'com.android.support:support-annotations:24.1.1'
        compile 'com.nineoldandroids:library:2.4.0'
        compile 'com.malinskiy:materialicons:1.0.1'
        compile 'com.google.zxing:core:3.2.1'
        compile 'com.google.guava:guava:19.0'
        compile 'com.android.volley:volley:1.0.0'
        compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha4'
        compile 'com.squareup.okhttp3:okhttp:3.3.1'
        compile 'com.roughike:bottom-bar:1.4.0.1'
        compile 'com.malinskiy:superrecyclerview:1.1.4'
        compile 'com.github.bumptech.glide:glide:3.7.0'
        compile 'com.dmitrymalkovich.android:material-design-dimens:1.2'
        compile 'com.eowise:recyclerview-stickyheaders:0.5.0@aar'
        compile('com.vincentbrison.openlibraries.android:dualcache:2.2.2@jar') {
            transitive = true
        }
        compile(name: 'com.leenanxi.android.open.qrcode', ext: 'aar')
        testCompile 'junit:junit:4.12'
        compile 'com.google.code.gson:gson:2.7'
        compile('io.socket:socket.io-client:0.7.0') {
            exclude group: 'org.json', module: 'json'
        }
        compile project(':imui')
        androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
        androidTestCompile 'com.android.support.test:runner:0.5'
        androidTestCompile 'com.android.support:support-annotations:24.1.1'
        compile files('libs/pushservice-5.1.0.48.jar')
&#13;
&#13;
&#13;

我的构建

1 个答案:

答案 0 :(得分:3)

您已启用&#34; multiDexEnabled true&#34;并且很可能你没有在Application类中安装它。

这就是你应该做的事情

android {
    compileSdkVersion 22
    buildToolsVersion "23.0.0"

         defaultConfig {
             minSdkVersion 14 //lower than 14 doesn't support multidex
             targetSdkVersion 22

             // Enabling multidex support.
             multiDexEnabled true       //You have already did this 
         }
}


dependencies {
    compile 'com.android.support:multidex:1.0.1'   // add this in  dependencies
}

最后扩展应用程序

public class YouApplication extends Application {

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

}

这是一本很好的指南https://developer.android.com/studio/build/multidex.html