Caused by: java.lang.ClassNotFoundException: Didn't find class "okhttp3.internal.Platform"

错误日志

Caused by: java.lang.ClassNotFoundException: Didn’t find class “okhttp3.internal.Platform” on path: DexPathList
完整错误日志:

    java.lang.IllegalStateException: Fatal Exception thrown on Scheduler.Worker thread.
        at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:62)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
        at java.util.concurrent.FutureTask.run(FutureTask.java:237)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:152)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:265)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
        at java.lang.Thread.run(Thread.java:831)
     Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lokhttp3/internal/Platform;
        at okhttp3.logging.HttpLoggingInterceptor$Logger$1.log(HttpLoggingInterceptor.java:109)
        at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:157)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
        at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:185)
        at okhttp3.RealCall.execute(RealCall.java:69)
        at retrofit2.OkHttpCall.execute(OkHttpCall.java:180)
        at retrofit2.adapter.rxjava.RxJavaCallAdapterFactory$RequestArbiter.request(RxJavaCallAdapterFactory.java:171)
        at rx.internal.operators.OperatorSubscribeOn$1$1$1$1.call(OperatorSubscribeOn.java:85)
        at rx.internal.schedulers.CachedThreadScheduler$EventLoopWorker$1.call(CachedThreadScheduler.java:222)
        at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422) 
        at java.util.concurrent.FutureTask.run(FutureTask.java:237) 
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:152) 
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:265) 
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
        at java.lang.Thread.run(Thread.java:831) 
     Caused by: java.lang.ClassNotFoundException: Didn't find class "okhttp3.internal.Platform" on path: DexPathList[[zip file "/data/app/com.augurit.agmobile.agwater-1/base.apk"],nativeLibraryDirectories=[/data/app/com.augurit.agmobile.agwater-1/lib/arm, /vendor/lib, /system/lib]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
        at okhttp3.logging.HttpLoggingInterceptor$Logger$1.log(HttpLoggingInterceptor.java:109) 
        at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:157) 
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92) 
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67) 
        at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:185) 
        at okhttp3.RealCall.execute(RealCall.java:69) 
        at retrofit2.OkHttpCall.execute(OkHttpCall.java:180) 
        at retrofit2.adapter.rxjava.RxJavaCallAdapterFactory$RequestArbiter.request(RxJavaCallAdapterFactory.java:171) 
        at rx.internal.operators.OperatorSubscribeOn$1$1$1$1.call(OperatorSubscribeOn.java:85) 
        at rx.internal.schedulers.CachedThreadScheduler$EventLoopWorker$1.call(CachedThreadScheduler.java:222) 
        at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55) 
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422) 
        at java.util.concurrent.FutureTask.run(FutureTask.java:237) 
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:152) 
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:265) 
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
        at java.lang.Thread.run(Thread.java:831) 
    	Suppressed: java.lang.ClassNotFoundException: okhttp3.internal.Platform
        at java.lang.Class.classForName(Native Method)
        at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
        at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
        		... 19 more
     Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

产生背景

移植老项目某一个功能模块到新项目中,启动那个功能时报错

分析原因

  1. 根据错误日志描述,大致意思是说 找不到 类:okhttp3.internal.Platform;
  2. 手动检查包里面是否真的没有这个类;
    打开项目的external Libraries;
    找到 okhttp3的gradle;
    查看包的详情;
    Caused by: java.lang.ClassNotFoundException: Didn't find class
  3. 由上图可知,并没有 okhttp3.internal.Platform 这个类,既然没有这个类,错误原因就是,代码中引用了这个不存在的类!
  4. 知道原因接下来就好办,继续看错误日志,找到引用这个类的代码!
    查找错误日志,点进去;
    Caused by: java.lang.ClassNotFoundException: Didn't find class
  5. 果然问题就在HttpLoggingInterceptor这个类里面!as都显示红色的PlatformCaused by: java.lang.ClassNotFoundException: Didn't find class
  6. 到这里,已经定位到错误原因了:HttpLoggingInterceptor 这个类引用了不存在的Platform 这个类!所以猜想我们自己的代码使用了HttpLoggingInterceptor这个类导致报错!点开这个类,查看有哪些地方使用了这个HttpLoggingInterceptor类;
    Caused by: java.lang.ClassNotFoundException: Didn't find class
  7. 由上图可知,自己写的类AMOKHttpManager 使用了HttpLoggingInterceptor;剩下的就是修改自己的代码啦!

解决办法

方法1

升级com.suquareup.ohttp3:loggin-interceptor:3.1.2(太老了);
后面的3.1.2与 com.squareup.ohttp3:okhttp:3.8.0 版本保持一致;
一般在app的build.gradle里面修改dependencies即可;
Caused by: java.lang.ClassNotFoundException: Didn't find class

方法2

由于我的是新旧老项目一块的。okhttp也是间接引入,所以另想他法;
【按两下shift】搜索 HttpLoggingInterceptor
Caused by: java.lang.ClassNotFoundException: Didn't find class
由上图可知,我这里存在两个HttpLoggingInterceptor,又想到这是两个项目的合并,所以大致可能猜到:项目中倒错了包,导致这个错误的发生;=所以解决办法就是找到引用文件,换个包就行啦!

总结

写项目;导包的时候要注意啦,不能随手不看乱导一个!

你可能感兴趣的:(android_error,okhttp,Platform)