2020-12-01 11:20:24.357 16113-16534/com.innerfit.app E/AndroidRuntime: FATAL EXCEPTION: OkHttp Dispatcher
Process: com.innerfit.app, PID: 16113
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(String.java:2064)
at okhttp3.JavaNetCookieJar.decodeHeaderAsJavaNetCookies(JavaNetCookieJar.kt:98)
at okhttp3.JavaNetCookieJar.loadForRequest(JavaNetCookieJar.kt:59)
at com.facebook.react.modules.network.ReactCookieJarContainer.loadForRequest(ReactCookieJarContainer.java:44)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:75)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:112)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:71)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:112)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:87)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.kt:184)
at okhttp3.RealCall$AsyncCall.run(RealCall.kt:136)
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:923)
Axios request works fine for a few requests but this crash happens and nothing works after that. Have to delete the application and reinstall it in order to make it work again.
Things I tried:
- Added { 'Connection': 'close' } in all requests according to this GitHub issue but doesn't fix it. https://github.com/facebook/react-native/issues/11016#issuecomment-336685459
- Added okhttp3 dependencies in Gradle file. https://github.com/facebook/react-native/issues/27250#issuecomment-573111088
dependencies {
compile "com.squareup.okhttp3:okhttp:4.2.1"
compile "com.squareup.okhttp3:logging-interceptor:4.2.1"
compile "com.squareup.okhttp3:okhttp-urlconnection:4.2.1"
}