I´m using OkHttpClient to post a file to a webserver (I have the latest OkHttpUtils2 V3.04).
In the ResponseSuccess event I call Response.Release
When I run in debug mode everything is ok however when I run in release mode I get an exception when calling Response.Release
Response.Release done
main_hc_responsesuccess (java line: 747)
android.os.NetworkOnMainThreadException
at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1667)
at java.net.SocketInputStream.read(SocketInputStream.java:172)
at java.net.SocketInputStream.read(SocketInputStream.java:143)
at okio.InputStreamSource.read(JvmOkio.kt:90)
at okio.AsyncTimeout$source$1.read(AsyncTimeout.kt:129)
at okio.RealBufferedSource.request(RealBufferedSource.kt:206)
at okio.RealBufferedSource.require(RealBufferedSource.kt:199)
at okio.RealBufferedSource.readHexadecimalUnsignedLong(RealBufferedSource.kt:381)
at okhttp3.internal.http1.Http1ExchangeCodec$ChunkedSource.readChunkSize(Http1ExchangeCodec.kt:429)
at okhttp3.internal.http1.Http1ExchangeCodec$ChunkedSource.read(Http1ExchangeCodec.kt:408)
at okhttp3.internal.Util.skipAll(Util.kt:337)
at okhttp3.internal.Util.discard(Util.kt:358)
at okhttp3.internal.http1.Http1ExchangeCodec$ChunkedSource.close(Http1ExchangeCodec.kt:450)
at okio.ForwardingSource.close(ForwardingSource.kt:34)
at okhttp3.internal.connection.Exchange$ResponseBodySource.close(Exchange.kt:309)
at okio.RealBufferedSource.close(RealBufferedSource.kt:477)
at okhttp3.internal.Util.closeQuietly(Util.kt:488)
at anywheresoftware.b4h.okhttp.OkHttpClientWrapper$OkHttpResponse.Release(OkHttpClientWrapper.java:637)
at b4a.example.main._hc_responsesuccess(main.java:747)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:221)
at anywheresoftware.b4a.BA$2.run(BA.java:395)
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:8061)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:703)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:911)
Any ideas why this is happening and how to fix it?
Thanks
In the ResponseSuccess event I call Response.Release
B4X:
Sub hc_ResponseSuccess (Response As OkHttpResponse, TaskId As Int)
Log("Response:" & Response.StatusCode)
If Response <> Null Then
Log("Response.Release done")
Response.Release
End If
End Sub
When I run in debug mode everything is ok however when I run in release mode I get an exception when calling Response.Release
Response.Release done
main_hc_responsesuccess (java line: 747)
android.os.NetworkOnMainThreadException
at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1667)
at java.net.SocketInputStream.read(SocketInputStream.java:172)
at java.net.SocketInputStream.read(SocketInputStream.java:143)
at okio.InputStreamSource.read(JvmOkio.kt:90)
at okio.AsyncTimeout$source$1.read(AsyncTimeout.kt:129)
at okio.RealBufferedSource.request(RealBufferedSource.kt:206)
at okio.RealBufferedSource.require(RealBufferedSource.kt:199)
at okio.RealBufferedSource.readHexadecimalUnsignedLong(RealBufferedSource.kt:381)
at okhttp3.internal.http1.Http1ExchangeCodec$ChunkedSource.readChunkSize(Http1ExchangeCodec.kt:429)
at okhttp3.internal.http1.Http1ExchangeCodec$ChunkedSource.read(Http1ExchangeCodec.kt:408)
at okhttp3.internal.Util.skipAll(Util.kt:337)
at okhttp3.internal.Util.discard(Util.kt:358)
at okhttp3.internal.http1.Http1ExchangeCodec$ChunkedSource.close(Http1ExchangeCodec.kt:450)
at okio.ForwardingSource.close(ForwardingSource.kt:34)
at okhttp3.internal.connection.Exchange$ResponseBodySource.close(Exchange.kt:309)
at okio.RealBufferedSource.close(RealBufferedSource.kt:477)
at okhttp3.internal.Util.closeQuietly(Util.kt:488)
at anywheresoftware.b4h.okhttp.OkHttpClientWrapper$OkHttpResponse.Release(OkHttpClientWrapper.java:637)
at b4a.example.main._hc_responsesuccess(main.java:747)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:221)
at anywheresoftware.b4a.BA$2.run(BA.java:395)
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:8061)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:703)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:911)
Any ideas why this is happening and how to fix it?
Thanks