OkHttp3 라이브러리 사용시 오류 ClassNotFoundException: Didn’t find class “okhttp3.internal.Platform” on path: DexPathList
Fabric Crashlytics SDK를 제거하고 FireBase Crashlytics SDK를 도입하였더니, 정상적으로 동작하던 OkHttp 라이브러이에서 오류가 발생하여 앱이 중지되는 상황이 벌어졌다.
2020-06-12 10:14:47.947 20240-20432/ddolcat.test E/AndroidRuntime: FATAL EXCEPTION: OkHttp Dispatcher
Process: ddolcat.test, PID: 20240
java.lang.NoClassDefFoundError: Failed resolution of: Lokhttp3/internal/Platform;
at okhttp3.logging.HttpLoggingInterceptor$Logger$1.log(HttpLoggingInterceptor.java:112)
at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:160)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:254)
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:200)
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:919)
Caused by: java.lang.ClassNotFoundException: Didn't find class "okhttp3.internal.Platform" on path: DexPathList[[zip file "/data/app/ddolcat.test-tBZhCODvIaNT-KBSGtWGBg==/base.apk"],nativeLibraryDirectories=[/data/app/ddolcat.test-tBZhCODvIaNT-KBSGtWGBg==/lib/arm64, /system/lib64, /system/product/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at okhttp3.logging.HttpLoggingInterceptor$Logger$1.log(HttpLoggingInterceptor.java:112)
at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:160)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:254)
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:200)
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:919)
2020-06-12 10:14:48.058 20240-20302/ddolcat.test W/at.app.hi.lott: No such thread for suspend: 0x782868a6f8:Crashlytics Report Uploader
2020-06-12 10:14:48.227 20240-20432/ddolcat.test E/UncaughtException: java.lang.NoClassDefFoundError: Failed resolution of: Lokhttp3/internal/Platform;
at okhttp3.logging.HttpLoggingInterceptor$Logger$1.log(HttpLoggingInterceptor.java:112)
at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:160)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:254)
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:200)
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:919)
Caused by: java.lang.ClassNotFoundException: Didn't find class "okhttp3.internal.Platform" on path: DexPathList[[zip file "/data/app/ddolcat.test-tBZhCODvIaNT-KBSGtWGBg==/base.apk"],nativeLibraryDirectories=[/data/app/ddolcat.test-tBZhCODvIaNT-KBSGtWGBg==/lib/arm64, /system/lib64, /system/product/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at okhttp3.logging.HttpLoggingInterceptor$Logger$1.log(HttpLoggingInterceptor.java:112)
at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:160)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:254)
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:200)
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:919)
클래스 파일을 찾지 못한다니 이해가 안가지만 혹시나 하는 마음에 라이브러리 버전 업데이트를 해보았다. 이런 경우는 경험상에 의존하면, 버전 업데이트가 답일때가 있다.
//현재 사용중인 버전
implementation 'com.squareup.retrofit2:retrofit:2.0.2'
implementation 'com.squareup.retrofit2:converter-gson:2.0.2'
implementation 'com.squareup.okhttp3:okhttp:3.3.1'
implementation 'com.squareup.okhttp3:logging-interceptor:3.3.1'
// 가장 최신 버전으로 업데이트처리
implementation 'com.squareup.retrofit2:retrofit:2.0.2'
implementation 'com.squareup.retrofit2:converter-gson:2.0.2'
implementation 'com.squareup.okhttp3:okhttp:3.14.1'
implementation "com.squareup.okhttp3:logging-interceptor:3.14.1"
가장 최신버전으로 업데이트를 하였더니 기존 오류는 사라지고 새로운 오류가 발생하였다.
Fatal Exception: java.lang.NoSuchMethodError: No static method metafactory(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite; in class Ljava/lang/invoke/LambdaMetafactory; or its super classes (declaration of 'java.lang.invoke.LambdaMetafactory' appears in /apex/com.android.runtime/javalib/core-oj.jar)
at okhttp3.internal.Util.<clinit>(Util.java:87)
at okhttp3.internal.Util.immutableList(Util.java:234)
at okhttp3.OkHttpClient.<clinit>(OkHttpClient.java:124)
at okhttp3.OkHttpClient$Builder.<init>(OkHttpClient.java:449)
at ddolcat.app.hi.lotto.HiLottoApplication.setupHttpClient(HiLottoApplication.java:182)
at ddolcat.app.hi.lotto.HiLottoApplication.makeHttpClient(HiLottoApplication.java:167)
at ddolcat.app.hi.lotto.HiLottoApplication.getDefaultHttpClient(HiLottoApplication.java:163)
at ddolcat.app.hi.lotto.network.NetworkManagement.getDefaultHttpClient(NetworkManagement.java:50)
at ddolcat.app.hi.lotto.network.NetworkManagement.getHttpClient(NetworkManagement.java:46)
at ddolcat.app.hi.lotto.IntroActivity.setHttpRetrofit(IntroActivity.java:184)
at ddolcat.app.hi.lotto.IntroActivity.CheckFCM(IntroActivity.java:281)
at ddolcat.app.hi.lotto.IntroActivity.onCreate(IntroActivity.java:175)
at android.app.Activity.performCreate(Activity.java:7812)
at android.app.Activity.performCreate(Activity.java:7801)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3298)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3462)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2063)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7615)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964)
이부분의 해결방법은 compileOption으로 자바 1.8 버전을 적용하면된다. 내가 원하는 것은 자바 버전 업데이트가 아니다. 그래서 한 참을 구글링 끝에 해결 책을 찾았다. 최신버전이 아닌, 3.4.1 버전을 적용하였더니 오류가 사라졌다.
//업데이트 후
implementation 'com.squareup.retrofit2:retrofit:2.0.2'
implementation 'com.squareup.retrofit2:converter-gson:2.0.2'
implementation 'com.squareup.okhttp3:okhttp:3.4.1'
implementation 'com.squareup.okhttp3:logging-interceptor:3.4.1'
[참고자료]
https://stackoverflow.com/questions/53613615/fatal-exception-okhttp-dispatcher/59467567#59467567
https://stackoverflow.com/questions/58630667/rejecting-re-init-on-previously-failed-class-in-okhttp
https://github.com/square/okhttp/issues/5760
https://stackoverflow.com/questions/59448845/no-static-method-metafactory
[관련자료]
Upgrading to OkHttp 4