title: Android emulator (v28.0.23) unable to make HTTP requests
body: <p>I am running a NativeScript-Vue application (<code>TNS Android v5.1.0</code>) on <code>Mojave v10.14.3</code> with <code>Android Studio v3.3.1</code> and <code>Android emulator v28.0.23</code>.</p>
  
  <p>The Android emulator I am using (<code>Nexus 6, API 25, Android 7.1.1 (Google APIs), x86</code>) loses ability to make HTTP requests. The request hangs for a couple of minutes and eventually times out. I am using <code>axios</code> as the HTTP client to consume a remote C#.NET API (this is a client's API so I do not have access to it directly).</p>
  
  <p>I found this <a href="https://stackoverflow.com/questions/42736038/android-emulator-not-able-to-access-the-internet">SO post</a> and tried most of the solutions. Some of them seemed to work, but then after a few minutes, the problem reoccurs. </p>
  
  <hr>
  
  <p>Solutions I have tried:</p>
  
  <ul>
  <li>Wiped data from emulator via AVD manager</li>
  <li>Cold booted emulator via AVD manager</li>
  <li>Created a new emulator via AVD manager</li>
  <li>Set emulator proxy status to "No proxy" instead of using Android Studio's default proxy settings</li>
  <li>Ran <code>adb kill-server</code></li>
  <li>Added <code>8.8.8.8</code> and <code>8.8.4.4</code> as DNS servers for my Mac</li>
  <li>Started emulator with a specified DNS server, e.g. <code>$ANDROID_HOME/emulator/emulator -avd Nexus_6_API_25 -dns-server 8.8.8.8,8.8.4.4</code></li>
  <li>Attempted on Genymotion emulator (same issue)</li>
  <li>Set WiFi as first in the Network Service order</li>
  <li>Rebooting system; works for a few minutes then issue reoccurs</li>
  </ul>
  
  <hr>
  
  <p>Additional information: </p>
  
  <ul>
  <li>I am using WiFi and have not recently switched from LAN.</li>
  <li>Chrome doesn't have internet access either.</li>
  <li>The application works as expected on the iOS simulator and on physical android devices. </li>
  <li>I installed Mojave recently, however the issue existed previously, although not as frequently it seemed. </li>
  <li>JDK-8 and Android-SDK were installed via Homebrew following the NativeScript docs <a href="https://docs.nativescript.org/start/ns-setup-os-x" rel="nofollow noreferrer">here</a>.</li>
  </ul>
  
  <hr>
  
  <p>I am fairly new to mobile development, please let me know if any more information is needed. </p>
  
  <p>Does anyone know how I can fix this issue? I have limited access to a physical device so getting this fixed would be a tremendous help. Thanks!</p>
  
  <hr>
  
  <p>HTTP Request example:</p>
  
  <pre class="lang-js prettyprint-override"><code>// api/config.js
  import axios from "axios";
  
  export default axios.create({
      baseURL: "https://testapi.org",
  
      headers: {
          "Content-Type": "application/json",
      }
  });
  
  // store/modules/auth.js
  import api from "api/config.js";
  
  const actions = {
      login: async function(context, payload) {
          try {
              const response = await api.post("/api/account/login", payload);
              context.dispatch("setUser", response.data.user);
          } catch (error) {
              console.log(error);
          }
      }
  };
  
  export default {
      namespace: true,
      actions
  };
  </code></pre>
  
  <hr>
  
  <p>Logcat output:</p>
  
  <pre><code>02-28 14:12:40.742  1722  1816 D ConnectivityService: NetworkAgentInfo [MOBILE (LTE) - 100] validation failed
  02-28 14:12:48.271  2939  3095 E GoogleConversionReporter: Error sending ping
  02-28 14:12:48.271  2939  3095 E GoogleConversionReporter: java.net.SocketTimeoutException: SSL handshake timed out
  02-28 14:12:48.271  2939  3095 E GoogleConversionReporter:  at com.google.android.gms.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
  02-28 14:12:48.271  2939  3095 E GoogleConversionReporter:  at com.google.android.gms.org.conscrypt.NativeSsl.doHandshake(:com.google.android.gms@13280022@13.2.80 (040700-211705629):8)
  02-28 14:12:48.271  2939  3095 E GoogleConversionReporter:  at com.google.android.gms.org.conscrypt.ConscryptFileDescriptorSocket.startHandshake(:com.google.android.gms@13280022@13.2.80 (040700-211705629):15)
  02-28 14:12:48.271  2939  3095 E GoogleConversionReporter:  at com.android.okhttp.Connection.connectTls(Connection.java:235)
  02-28 14:12:48.271  2939  3095 E GoogleConversionReporter:  at com.android.okhttp.Connection.connectSocket(Connection.java:199)
  02-28 14:12:48.271  2939  3095 E GoogleConversionReporter:  at com.android.okhttp.Connection.connect(Connection.java:172)
  02-28 14:12:48.271  2939  3095 E GoogleConversionReporter:  at com.android.okhttp.Connection.connectAndSetOwner(Connection.java:367)
  02-28 14:12:48.271  2939  3095 E GoogleConversionReporter:  at com.android.okhttp.OkHttpClient$1.connectAndSetOwner(OkHttpClient.java:130)
  02-28 14:12:48.271  2939  3095 E GoogleConversionReporter:  at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:329)
  02-28 14:12:48.271  2939  3095 E GoogleConversionReporter:  at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:246)
  02-28 14:12:48.271  2939  3095 E GoogleConversionReporter:  at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:457)
  02-28 14:12:48.271  2939  3095 E GoogleConversionReporter:  at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:405)
  02-28 14:12:48.271  2939  3095 E GoogleConversionReporter:  at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:521)
  02-28 14:12:48.271  2939  3095 E GoogleConversionReporter:  at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getResponseCode(DelegatingHttpsURLConnection.java:105)
  02-28 14:12:48.271  2939  3095 E GoogleConversionReporter:  at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java)
  02-28 14:12:48.271  2939  3095 E GoogleConversionReporter:  at bsc.a(SourceFile:230)
  02-28 14:12:48.271  2939  3095 E GoogleConversionReporter:  at bsf.run(SourceFile:174)
  02-28 14:12:48.271  2939  3095 E GoogleConversionReporter:  at java.lang.Thread.run(Thread.java:761)
  02-28 14:12:49.375  2651  2932 W Conscrypt: Could not set socket write timeout: java.lang.reflect.InvocationTargetException
  02-28 14:12:49.376  2651  2932 W Conscrypt:     at java.lang.reflect.Method.invoke(Native Method)
  02-28 14:12:49.376  2651  2932 W Conscrypt:     at com.google.android.gms.org.conscrypt.Platform.setSocketWriteTimeout(:com.google.android.gms@13280022@13.2.80 (040700-211705629):13)
  02-28 14:12:49.376  2651  2932 W Conscrypt: Caused by: android.system.ErrnoException: setsockopt failed: EBADF (Bad file descriptor)
  02-28 14:12:49.376  2651  2932 W Conscrypt:     at libcore.io.Posix.setsockoptTimeval(Native Method)
  02-28 14:12:49.376  2651  2932 W Conscrypt:     at libcore.io.ForwardingOs.setsockoptTimeval(ForwardingOs.java:157)
  02-28 14:12:50.171  2651  2930 W Conscrypt: Could not set socket write timeout: java.lang.reflect.InvocationTargetException
  02-28 14:12:50.171  2651  2930 W Conscrypt:     at java.lang.reflect.Method.invoke(Native Method)
  02-28 14:12:50.171  2651  2930 W Conscrypt:     at com.google.android.gms.org.conscrypt.Platform.setSocketWriteTimeout(:com.google.android.gms@13280022@13.2.80 (040700-211705629):13)
  02-28 14:12:50.172  2651  2930 W Conscrypt: Caused by: android.system.ErrnoException: setsockopt failed: EBADF (Bad file descriptor)
  02-28 14:12:50.172  2651  2930 W Conscrypt:     at libcore.io.Posix.setsockoptTimeval(Native Method)
  02-28 14:12:50.172  2651  2930 W Conscrypt:     at libcore.io.ForwardingOs.setsockoptTimeval(ForwardingOs.java:157)
  02-28 14:12:50.283  2651  2929 W Conscrypt: Could not set socket write timeout: java.lang.reflect.InvocationTargetException
  02-28 14:12:50.284  2651  2929 W Conscrypt:     at java.lang.reflect.Method.invoke(Native Method)
  02-28 14:12:50.284  2651  2929 W Conscrypt:     at com.google.android.gms.org.conscrypt.Platform.setSocketWriteTimeout(:com.google.android.gms@13280022@13.2.80 (040700-211705629):13)
  02-28 14:12:50.284  2651  2929 W Conscrypt: Caused by: android.system.ErrnoException: setsockopt failed: EBADF (Bad file descriptor)
  02-28 14:12:50.284  2651  2929 W Conscrypt:     at libcore.io.Posix.setsockoptTimeval(Native Method)
  02-28 14:12:50.284  2651  2929 W Conscrypt:     at libcore.io.ForwardingOs.setsockoptTimeval(ForwardingOs.java:157)
  02-28 14:12:51.482  2651  3200 W Conscrypt: Could not set socket write timeout: java.lang.reflect.InvocationTargetException
  02-28 14:12:51.482  2651  3200 W Conscrypt:     at java.lang.reflect.Method.invoke(Native Method)
  02-28 14:12:51.482  2651  3200 W Conscrypt:     at com.google.android.gms.org.conscrypt.Platform.setSocketWriteTimeout(:com.google.android.gms@13280022@13.2.80 (040700-211705629):13)
  02-28 14:12:51.482  2651  3200 W Conscrypt: Caused by: android.system.ErrnoException: setsockopt failed: EBADF (Bad file descriptor)
  02-28 14:12:51.482  2651  3200 W Conscrypt:     at libcore.io.Posix.setsockoptTimeval(Native Method)
  02-28 14:12:51.482  2651  3200 W Conscrypt:     at libcore.io.ForwardingOs.setsockoptTimeval(ForwardingOs.java:157)
  02-28 14:13:05.945  5154  5156 I art     : Do partial code cache collection, code=30KB, data=30KB
  02-28 14:13:05.946  5154  5156 I art     : After code cache collection, code=30KB, data=30KB
  02-28 14:13:05.946  5154  5156 I art     : Increasing code cache capacity to 128KB
  02-28 14:13:14.458  2363  5301 E WakeLock: GCM_HB_ALARM release without a matched acquire!
  </code></pre>