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
相关产品推荐
相关产品推荐

