运行 Android 设备上的 React Apollo 网站 - react-native 的步骤不清楚

Running React Apollo website on Android device - the step with react-native is unclear

我正在使用 React Apollo boilerplate. Now I want to deploy that Website to my Android device. So I did it exactly like the Running On Device tutorial 说:

  1. 启用 USB 调试
    • 都很好
  2. 通过 USB 插入您的设备
    • adb devices
    • 我的列表如下所示:
       List of devices attached
       5141a720        device

所以这看起来不错。

  1. 运行 你的应用
    • 但是我有一个问题,因为我不知道 react-native 是什么意思
    • npx react-native run-android
    • 结果 react-native is not known

会不会是我的项目不是 react-native 项目,这就是为什么 react-native 不是适合我的情况的解决方案?

如何在我的 Android 设备上 运行 该网站而不将其转换为 APK 文件?

我不是 React Native 专家,但根据我对该工具的了解,您需要创建特殊组件才能在本机设备 (fc) 上呈现。

可能更适合您需求的工具是电容器:
安装:https://capacitor.ionicframework.com/docs/getting-started
工作流程:https://capacitor.ionicframework.com/docs/basics/workflow

工作流程的快速总结:

  1. 构建反应应用程序npm run build
  2. 创建 capacitor.config.json:
{
    "appId": "com.example.app",
    "appName": "Example",
    "bundledWebRuntime": false,
    "npmClient": "npm",
    "webDir": "build",
    "cordova": {},
    "linuxAndroidStudioPath": "/mnt/s/android-studio/bin/studio.sh"
}
  1. 打开android模拟器:npx cap open android

希望这对您有所帮助。

刚刚添加了这两行 npm/yarn install:

"react-native": "^0.62.2",
"react-native-cli": "^2.0.1",

又试了一次npx react-native run-android,现在似乎成功了。但是收到一条消息说:

error Android project not found. Are you sure this is a React Native project? If your Android files are located in a non-standard location (e.g. not inside 'android' folder), consider setting project.android.sourceDir option to point to a new location. Run CLI with --verbose flag for more details.

很明显 android 文件夹丢失了。在这里它帮助 运行 npx react-native init "test"。这创建了一个名为 test 的子文件夹。在这里,我只是将 android 文件夹移动到我的项目中。

现在 npx react-native run-android 有效。