java.lang.NoClassDefFoundError: okhttp3.internal.Util
java.lang.NoClassDefFoundError: okhttp3.internal.Util
[在此处输入图片描述][1]
我的程序可以 运行 Android 5.1 phone ,但是 phone 将无法 运行 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.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.access0(Socket.java:30)
>at io.socket.engineio.client.Socket.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.access0(Polling.java:17)
>at>io.socket.engineio.client.transports.Polling.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.run(PollingXHR.java:113)
>at io.socket.thread.EventThread.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')
我的构建
您已启用 "multiDexEnabled true",很可能您并未将其安装在应用程序 class 中。
这就是你应该做的
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
[在此处输入图片描述][1]
我的程序可以 运行 Android 5.1 phone ,但是 phone 将无法 运行 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.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.access0(Socket.java:30)
>at io.socket.engineio.client.Socket.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.access0(Polling.java:17)
>at>io.socket.engineio.client.transports.Polling.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.run(PollingXHR.java:113)
>at io.socket.thread.EventThread.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')
我的构建
您已启用 "multiDexEnabled true",很可能您并未将其安装在应用程序 class 中。
这就是你应该做的
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