Log Exception information:

W/System.err: java.io.IOException: unexpected end of stream on http://xxx.xxx.cn/... W/System.err: at okhttp3.internal.http1.Http1ExchangeCodec.readResponseHeaders(Http1ExchangeCodec.kt:204) W/System.err: at okhttp3.internal.connection.Exchange.readResponseHeaders(Exchange.kt:110) W/System.err: at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.kt:93) W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) W/System.err: at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:34) W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) W/System.err: at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:95) W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) W/System.err: at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:83) W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) W/System.err: at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:76) W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) W/System.err: at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.kt:222) W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) W/System.err: at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:201) W/System.err: at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:517) W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) W/System.err: At java.lang.thread. run(thread.java :923) W/ system. err: Caused by: java.io.EOFException: \n Not found: Limit =0 Content =... W/System.err: at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.kt:332) W/System.err: at okhttp3.internal.http1.HeadersReader.readLine(HeadersReader.kt:29) W/System.err: at okhttp3.internal.http1.Http1ExchangeCodec.readResponseHeaders(Http1ExchangeCodec.kt:180) W/System.err: ... 18 moreCopy the code

Problem summary:

  1. java.io.IOException: unexpected end of stream on http://xxx.xxx.cn/...
  2. Caused by: java.io.EOFException: \n Not found: Limit =0 Content =...
  3. java.net.ProtocolException: unexpected end of stream

Causes:AndroidThe simulator is not usedWindowsthehostsFile configuration, causing the program to run to the phone can not access the Intranet address

🌴 Test environment: Android11 API 30

Solution: HereAndroidconfigurationWindowsthehostsfile

1. Specify a DNS server when starting the emulator
.\emulator.exe -avD emulator name -writable-system -no- snapshot-dnS-server 192.0.x.x,192.0.x.xCopy the code

If this method fails, you can modify hosts again, that is, method 2.

Use host files

Android emulators do not use Windows localhost files. You need to edit the hosts file on the Android emulator image itself.

  1. Start Android Virtual Appliance (AVD) :
  2. Open emulator.exe in C:\XXX\android-sdk\emulator

    .\emulator.exe -list-avds.\emulator.exe -avD emulator name -writable- system-no-snapshotCopy the code
    -no-snapshot-load Performs cold boot and saves the emulator status upon exit. -no-snapshot-save Performs a quick start, if possible, but does not save emulator status on exit. -no-snapshot disables the quick start feature completely - it does not load or save emulator state.

    Do not close the window after startup

  3. Remount the device image as writable:
  4. adb root
    adb disable-verity
    adb remount
    adb reboot
    
    adb shell
    mount -o rw,remount /system
    Copy the code

    Android Studio’s built-in emulator can easily get stuck in adb Reboot and fail… The Genymotion emulator is strongly recommended.

  5. Save a copy of the Android hosts file to a temporary location on your Windows host:
  6. adb pull /system/etc/hosts D:\TempFilesCopy the code

  7. Edit the Android hosts and add an entry pointing to the host:
  8. 127.0.0.1     localhost  
    10.0.2.2      mytesthost  
    Copy the code

  9. Save the edited hosts file back to the Android emulator:
  10. adb push D:\TempFiles\hosts /system/etc  
    Copy the code

  11. Test whether the Android emulator can access the host:
  12. adb shell
    adb ping mytesthost
    Copy the code

    Unexpected end of stream on http://xxx.xxx.cn/… EOFException: \n Not found: Limit =0 content=… The exception.

🍎 OkHttpOn the relevantissueThere are many:

Github.com/square/okht…

reference

From the command line to start the simulator developer.android.com/studio/run/…

Web.archive.org/web/2018061…

Stackoverflow.com/questions/3…

The Read – only file system blog.csdn.net/wlwh90/arti…