NoClassDefFoundError: okhttp3.OkHttpClient$Builder

最近的项目Application类初始化okhttp给抛出这个错误NoClassDefFoundError: okhttp3.OkHttpClient$Builder。

依赖没有?no

冲突?反正我没找到

重复构建?没有。。。


以下内容来自https://stackoverflow.com/questions/36649121/java-lang-noclassdeffounderror-okhttp3-okhttpclientbuilder


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>

通过上面的方法我解决了我目前的问题,不知道你们是不是一样

  • 6
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值