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

使用ADB调试Expo Go中expo-file-system生成文件的权限问题

Expo Go下查看expo-file-system生成文件的方法

不需要构建应用后用adb push,有几种更便捷的方式:

1. 用Expo自带API直接查看/分享

利用expo-file-system和expo-sharing就能在开发阶段快速访问文件,不用碰adb:

  • 读取文件内容并打印到控制台:
    import * as FileSystem from 'expo-file-system';
    
    async function checkFileContent() {
      const targetPath = `${FileSystem.documentDirectory}your-file-name`;
      try {
        const content = await FileSystem.readAsStringAsync(targetPath);
        console.log('文件内容:', content);
      } catch (err) {
        console.error('读取失败:', err);
      }
    }
    
  • 把文件分享到手机上的其他应用(比如文件管理器、邮件):
    import * as FileSystem from 'expo-file-system';
    import * as Sharing from 'expo-sharing';
    
    async function shareFile() {
      const targetPath = `${FileSystem.documentDirectory}your-file-name`;
      const contentUri = await FileSystem.getContentUriAsync(targetPath);
      await Sharing.shareAsync(contentUri);
    }
    

2. 通过adb访问(无需正式构建)

如果一定要用adb,不用打包正式应用,直接用run-as命令切换到Expo Go的应用权限上下文:

adb shell run-as host.exp.exponent
cd files
# 此时就能查看目录下的文件,比如
ls
cat your-file-name

普通adb shell没有访问/data/user/0/host.exp.exponent的权限,run-as可以让你以Expo Go应用的身份访问其私有数据目录。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.20 15:27:06