也是一个莫名其妙的问题,不知道怎么导致的,开始okhttp3运行的还好好地,突然抽风似的,出现这个bug。
好在网上有解决办法,我的办法来自:https://stackoverflow.com/questions/36649121/java-lang-noclassdeffounderror-okhttp3-okhttpclientbuilder
down vote
accepted
Yes, finally I find the problem and solve it. I viewed a similar problem here and find that maybe the 64K Methods could cause the problem, so I came to official site to view Building Apps with Over 64K Methods. Now you should compile the multidex library in your build.gradle file:
compile 'com.android.support:multidex:1.0.1'
And don't forget to config your defaultConfig:
android {
defaultConfig {
multiDexEnabled true
}
}
And finally you can write a BaseApplication extends to Application, over write the attachBaseContext(Context base) method as follows:
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
Don't forget to add this to your AndroidManifest.xml file:
<application
android:name=".BaseApplication"
android:allowBackup="true">
</application>
加上上面这些配置,问题解决
1,multidex
compile 'com.android.support:multidex:1.0.1'
2,defaultConfig
android {
defaultConfig {
multiDexEnabled true
}
}
3,attachBaseContext()
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
4,
<application
android:name=".BaseApplication"
android:allowBackup="true">
</application>