【问题标题】:Why my Emulator doesn't work with NativeScript?为什么我的模拟器不适用于 NativeScript?
【发布时间】:2019-11-10 22:15:41
【问题描述】:

我已经在https://github.com/rezaee/conFusion 上传了我的项目,但是当我尝试使用tns run android --device Pixel_2_API_29 运行它时,它会打开我的模拟器,但会在它的屏幕上显示此错误消息:

Error:0-Unknown Error Http failure response for https://10.0.2.2

我也尝试了以下几行,但都给出了相同的错误:

export const baseURL = "http://10.0.2.2:3000/";
export const baseURL = "http://192.168.1.5:3000/";
export const baseURL = "http://localhost:3000/";

为什么会发生这种情况,我该如何解决?

【问题讨论】:

  • localhost 肯定不会工作,因为模拟器在它自己的上下文中运行,更像是一个单独的设备。 http://10.0.2.2:3000 - 它是公共 IP,首先确保它可以在浏览器/rest 客户端中访问,从我的角度来看,它看起来不像。
  • @Manoj:它给了我This site can’t be reached 10.0.2.2 took too long to respond.
  • 我想知道你到底想在这里做什么,为什么你会点击那个IP?如果您尝试访问托管在本地机器或公共服务器上的任何 REST API,它应该是该机器的 IP。
  • @Manoj:我有一个 json 服务器,当我运行它时,它会在 localhost:3000/ 上监视。所以我喜欢让模拟器观察那个地址并显示那里的内容。

标签: android angular android-emulator nativescript json-server


【解决方案1】:

经过一个月的尝试,我在 NativeScript 的 github 上找到了如下答案:

在 API29 上测试,问题是您可能缺少 AndroidManifest.xml 文件中的 cleartext 权限。

在此处设置:your-application/app/App_Resources/Android/src/main/AndroidManifest.xml

在 AndroidManifest.xml 中设置android:usesCleartextTraffic

<application android:name="com.tns.NativeScriptApplication"
          android:allowBackup="true"
          android:icon="@drawable/opportuity"
          android:label="@string/app_name"
          android:theme="@style/AppTheme"
          android:usesCleartextTraffic="true">  

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-11-29
    • 2019-09-18
    • 2019-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-30
    相关资源
    最近更新 更多