0

I'm using khttp to perform HTTP requests in my Android app, but every time I start adding breakpoints to my app in Android Studio 3.1, I'm getting this really annoying Illegal State Exception, at which point I them need to restart Android Studio. Here's an example of the exception thrown:

E/AndroidRuntime: FATAL EXCEPTION: Thread-4
Process: com.sbrl.peppermint, PID: 10777
java.lang.IllegalStateException: Cannot access request header fields after connection is set
  at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getRequestProperties(HttpURLConnectionImpl.java:232)
  at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getRequestProperties(DelegatingHttpsURLConnection.java:182)
  at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getRequestProperties(Unknown Source:0)
  at com.android.tools.profiler.support.network.httpurl.TrackedHttpURLConnection.getRequestProperties(TrackedHttpURLConnection.java:204)
  at com.android.tools.profiler.support.network.httpurl.TrackedHttpURLConnection.trackPreConnect(TrackedHttpURLConnection.java:63)
  at com.android.tools.profiler.support.network.httpurl.TrackedHttpURLConnection.connect(TrackedHttpURLConnection.java:126)
  at com.android.tools.profiler.support.network.httpurl.HttpsURLConnection$.connect(HttpsURLConnection$.java:366)
  at khttp.responses.GenericResponse.openRedirectingConnection$khttp(GenericResponse.kt:125)
  at khttp.responses.GenericResponse.getConnection(GenericResponse.kt:163)
  at khttp.responses.GenericResponse.getRaw(GenericResponse.kt:207)
  at khttp.responses.GenericResponse.getContent(GenericResponse.kt:216)
  at khttp.responses.GenericResponse.init$khttp(GenericResponse.kt:377)
  at khttp.KHttp.request(KHttp.kt:61)
  at khttp.KHttp.request$default(KHttp.kt:59)

I know that this question explains why this is happening, but my question is this:

How can I black-box the khttp library (similar to the way that Chrome allows you to black-box a JS source file), such that the Android debugger does not inspect it - throwing this exception?

starbeamrainbowlabs
  • 5,692
  • 8
  • 42
  • 73
  • Seems like the problem is khttp. I'd look at using another library, or getting them to fix their bugs. There's many far more developed networking libraries for android – Gabe Sechan Apr 02 '18 at 14:25
  • @GabeSechan Hrm, interesting. [Here's a link to the offending code](https://github.com/sbrl/Pepperminty-Wiki-Client-Android/blob/master/app/src/main/java/com/sbrl/peppermint/activities/AddWiki.kt#L56). While it _is_ on another thread, I'm not even accessing the request header fields in my code _at all_. – starbeamrainbowlabs Apr 02 '18 at 14:26
  • Ah, ok. I'll have to try with another library then. Time to do some research into alternatives, I guess. – starbeamrainbowlabs Apr 02 '18 at 14:27
  • The big ones for Android are Retrofit and Volley. With Retrofit being easier and Volley being more flexible. – Gabe Sechan Apr 02 '18 at 14:27
  • Thanks, @GabeSechan! I'll experiment and pick one. – starbeamrainbowlabs Apr 02 '18 at 14:30

0 Answers0