You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native安卓模拟器无法连接Appium服务的原因排查

无法在React Native安卓模拟器中连接Appium服务的问题

背景

我需要在React Native安卓应用中检测运行的Appium服务(端到端测试服务器),以此让应用识别当前处于E2E测试环境。由于安卓模拟器的localhost指向自身网络接口,通常用10.0.2.2访问宿主机的localhost。

尝试的代码

// iOS/Android e2e test run on Emulator/Simulator with an Appium server
let isE2e: boolean | null = null

export async function getIsE2e() {
  if (env.ENV === 'production') {
    isE2e = false
  }
  if (isE2e === true || isE2e === false) {
    return isE2e
  }
  try {
    const response = await fetch('http://10.0.2.2/status', {
      mode: 'cors',
      headers: new Headers({
        accept: 'application/json',
      }),
    })
    isE2e = response.ok
  } catch (error) {
    isE2e = false
  }
  return isE2e
}

遇到的错误

TypeError: Network request failed

预期响应

{"value":{"build":{"version":"2.0.0-beta.46","git-sha":"258938ef66a2a49a4a400554a6dce890226ae34c","built":"2020-03-05 23:13:56 -0800"}}}

环境详情

  • 未使用任何代理
  • Appium服务器监听0.0.0.0:4723,监听状态:
    tcp        0      0 0.0.0.0:4723            0.0.0.0:*               LISTEN      26721/node          
    
  • 访问监听0.0.0.0:3000的webpack dev服务器完全正常,监听状态:
    tcp        0      0 0.0.0.0:3000            0.0.0.0:*               LISTEN      30217/node               
    

疑问

为何无法连接Appium服务?

内容的提问来源于stack exchange,提问作者Dimitri Kopriwa

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.02 22:55:56