Android模拟器(v28.0.23)无法发出HTTP请求

时间:2019-02-28 22:03:19

标签: android macos android-emulator nativescript nativescript-vue

我正在TNS Android v5.1.0上通过Mojave v10.14.3Android Studio v3.3.1运行NativeScript-Vue应用程序(Android emulator v28.0.23)。

我正在使用的Android仿真器(Nexus 6, API 25, Android 7.1.1 (Google APIs), x86)无法发出HTTP请求。该请求挂起了几分钟,最终超时。我使用axios作为HTTP客户端来使用远程C#.NET API(这是客户端的API,因此我无法直接访问它)。

我找到了SO post,并尝试了大多数解决方案。他们中的一些人似乎可以正常工作,但是几分钟后,问题再次出现。


我尝试过的解决方案:

  • 通过AVD管理器从模拟器清除数据
  • 通过AVD管理器冷启动的模拟器
  • 通过AVD管理器创建了新的模拟器
  • 将模拟器代理状态设置为“无代理”,而不使用Android Studio的默认代理设置
  • adb kill-server
  • 为我的Mac添加了8.8.8.88.8.4.4作为DNS服务器
  • 使用指定的DNS服务器启动模拟器,例如$ANDROID_HOME/emulator/emulator -avd Nexus_6_API_25 -dns-server 8.8.8.8,8.8.4.4
  • 尝试了Genymotion模拟器(相同的问题)
  • 将WiFi设置为“网络服务”顺序中的第一位
  • 重新启动系统;工作几分钟,然后再次出现问题

其他信息:

  • 我正在使用WiFi,最近没有从LAN切换。
  • Chrome也无法访问互联网。
  • 该应用程序可以在iOS模拟器和物理android设备上正常运行。
  • 我最近安装了Mojave,但是这个问题以前就存在过,尽管看起来并不那么频繁。
  • 遵循NativeScript文档here,通过Homebrew安装了JDK-8和Android-SDK。

我对移动开发还很陌生,请让我知道是否需要更多信息。

有人知道我如何解决此问题?我对物理设备的访问受到限制,因此修复此问题将提供巨大帮助。谢谢!


HTTP请求示例:

// 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
};

Logcat输出:

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!

0 个答案:

没有答案