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

如何在Expo React Native项目中添加usesClearTextTraffic=true?

解决Expo React Native项目配置usesClearTextTraffic=true的方法

因为Expo托管项目不会暴露原生的AndroidManifest.xml文件,你需要通过Expo的配置文件实现该设置,具体步骤如下:

  • 在项目根目录找到app.json或app.config.js(使用JS配置时)
  • 在配置文件的expo.android字段下添加useClearTextTraffic属性并设为true,示例如下:

如果是app.json:

{
  "expo": {
    "name": "YourAppName",
    "slug": "your-app-slug",
    // 其他配置项...
    "android": {
      "useClearTextTraffic": true,
      // 其他Android相关配置...
    }
  }
}

如果是app.config.js:

export default {
  expo: {
    name: "YourAppName",
    slug: "your-app-slug",
    // 其他配置项...
    "android": {
      "useClearTextTraffic": true,
      // 其他Android相关配置...
    }
  }
};
  • 保存配置文件后,执行expo start --clear清除缓存并重新运行项目,Expo会自动将该配置注入到生成的AndroidManifest.xml中。

注意:若你的项目是裸工作流(已执行expo eject或npx expo prebuild),此时会生成原生Android目录,可直接在android/app/src/main/AndroidManifest.xml的<application>标签内添加android:usesClearTextTraffic="true",无需通过Expo配置文件设置。

内容的提问来源于stack exchange,提问作者Prageeth Milan

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.19 00:22:00