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

React Native仅Android端所有HTTP请求报错问题求助

Expo React Native Android端HTTP请求NETWORK ERROR问题排查方案
  • 检查Android网络权限配置
    Expo项目中,确认app.json已添加网络权限:

    {
      "expo": {
        "android": {
          "permissions": ["INTERNET"]
        }
      }
    }
    

    Expo SDK 48+默认包含该权限,若手动移除过需重新添加。

  • 确认API协议类型
    Android 9.0及以上默认禁止明文HTTP请求,若API使用HTTP协议,需在app.json中开启明文支持:

    {
      "expo": {
        "android": {
          "usesCleartextTraffic": true
        }
      }
    }
    

    优先建议将API切换为HTTPS协议,保障安全性。

  • 排查请求库与原生兼容性
    暂时替换Axios为原生fetch测试请求,判断问题是否出在Axios配置:

    fetch('你的API地址')
      .then(res => res.json())
      .then(data => console.log(data))
      .catch(err => console.error(err));
    

    若fetch同样报错,说明问题在网络或系统配置层面;若fetch正常,检查Axios的拦截器、超时设置等是否存在Android兼容问题。

  • 排查Remote Config配置
    若使用Firebase Remote Config,确保Android端配置文件google-services.json正确引入,Firebase初始化参数无误。可添加日志打印具体错误:

    import { initializeApp } from 'firebase/app';
    import { getRemoteConfig, fetchAndActivate } from 'firebase/remote-config';
    
    const firebaseConfig = {/* 你的Firebase配置 */};
    const app = initializeApp(firebaseConfig);
    const remoteConfig = getRemoteConfig(app);
    remoteConfig.settings.minimumFetchIntervalMillis = 3600000;
    
    fetchAndActivate(remoteConfig)
      .then(() => console.log('Remote Config加载成功'))
      .catch(err => console.error('Remote Config错误详情:', err));
    
  • 验证设备网络连通性
    在Android模拟器或真机上,用浏览器直接访问API地址,确认网络能正常获取数据。排查是否存在VPN、代理服务器导致的网络拦截。

  • 重置Expo开发环境
    重启Expo开发服务,若存在代理问题,可尝试指定代理启动:

    EXPO_HTTP_PROXY=http://你的代理地址 expo start
    

内容的提问来源于stack exchange,提问作者Willian Ferreira

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.31 03:15:23