Android App Crash On File Upload; FATAL EXCEPTION: OkHttp Dispatcher
HaidarZ opened this issue ยท 9 comments
Description:
I've been getting the error found below for a while. The exact scenario is that the app crashes whenever I try to upload any kind of file.
I've created a separate isolated app and started adding packages one by one to check which library is causing the below error. There's no context to know which library is firing this error.
Setup:
Android
"rn-fetch-blob": "~0.13.0-beta.2"
"react-native": "0.70.5"
Error
FATAL EXCEPTION: OkHttp Dispatcher
Process: com.awesomeproject, PID: 13130
java.lang.NoClassDefFoundError: Failed resolution of: Lokhttp3/internal/Util;
at com.facebook.react.modules.network.RequestBodyUtil$1.writeTo(RequestBodyUtil.java:149)
at okhttp3.MultipartBody.writeOrCountBytes(MultipartBody.kt:160)
at okhttp3.MultipartBody.writeTo(MultipartBody.kt:100)
at com.facebook.react.modules.network.ProgressRequestBody.writeTo(ProgressRequestBody.java:52)
at com.facebook.flipper.plugins.network.FlipperOkhttpInterceptor.cloneBodyAndInvalidateRequest(FlipperOkhttpInterceptor.java:118)
at com.facebook.flipper.plugins.network.FlipperOkhttpInterceptor.intercept(FlipperOkhttpInterceptor.java:90)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:34)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:95)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:84)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:65)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:205)
at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:533)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:776)
Caused by: java.lang.ClassNotFoundException: Didn't find class "okhttp3.internal.Util" on path: DexPathList[[zip file "/data/app/com.awesomeproject-1/base.apk"],nativeLibraryDirectories=[/data/app/com.awesomeproject-1/lib/arm64, /data/app/com.awesomeproject-1/base.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64, /system/vendor/lib64, /product/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
... 20 more
@HaidarZ
Try specifying 4.10.0
for okhttp version in project level build.gradle.
build script {
ext {
buildToolsVersion = "31.0.0"
minSdkVersion = 28
compileSdkVersion = 31
targetSdkVersion = 31
okhttp = "4.10.0" // <----- add this line
}
}
If no okhttp version is specified, currently 5.0.0-alpha.10
is used.
okhttp3.internal.Util
class seems to have been moved to package level constants/functions in 5.0.0-alpha.x
.
https://github.com/square/okhttp/blob/parent-5.0.0-alpha.10/okhttp/src/commonMain/kotlin/okhttp3/internal/-UtilCommon.kt
If you are in rn 0.70.5, you should better to set okhttp 4.9.2 that is same with rn
build script {
ext {
buildToolsVersion = "31.0.0"
minSdkVersion = 28
compileSdkVersion = 31
targetSdkVersion = 31
okhttp = "4.9.2" // <----- add this line
}
}
The case is why does this occurs out of nowhere.
The case is why does this occurs out of nowhere.
https://github.com/joltup/rn-fetch-blob/blob/master/android/build.gradle
because of the build.gradle of rn-fetch-blob:
dependencies {
implementation "com.facebook.react:react-native:${safeExtGet('reactNativeVersion', '+')}"
implementation "com.squareup.okhttp3:okhttp:${safeExtGet('okhttp', '+')}"
implementation "com.squareup.okhttp3:logging-interceptor:${safeExtGet('okhttp', '+')}"
implementation "com.squareup.okhttp3:okhttp-urlconnection:${safeExtGet('okhttp', '+')}"
// {RNFetchBlob_PRE_0.28_DEPDENDENCY}
}
Should it be referenced in the dependencies ? It's already part of the react-native package.
Maybe com.squareup.okhttp3:logging-interceptor & com.squareup.okhttp3:okhttp-urlconnection are not parts of react-native package. I'm not sure
@drfoxbox I've moved to the react-native-blob-util fork.
Android app is crashing
Fatal Exception: java.lang.ClassCastException: okhttp3.internal.http.RealResponseBody cannot be cast to com.RNFetchBlob.i.b
"rn-fetch-blob": 0.12.0
"react-native": 0.63.5
Its uploading zero bytes to the server.I couldn't find root cause for this problem.