最近的項目Application類初始化okhttp給拋出這個錯誤NoClassDefFoundError: okhttp3.OkHttpClient$Builder。
依賴沒有?no
衝突?反正我沒找到
重複構建?沒有。。。
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 siteto 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>
通過上面的方法我解決了我目前的問題,不知道你們是不是一樣