使用 vs 代码反应原生 docker 容器以发布到主机操作系统上的 android 模拟器

amb*_*llo 7 android docker react-native

我正在尝试在 vs 代码上运行一个 react native docker 容器。我能够运行我的代码。但是,容器无法检测到在我的主机上运行的 android 模拟器。

I followed along in this tutorial course:

https://code.visualstudio.com/docs/remote/containers & https://github.com/microsoft/vscode-react-native

正在运行

npx react-native run-android 但是,我收到一条错误消息,指出我的模拟器没有运行。错误 无法安装应用程序。确保您有一个正在运行的 Android 模拟器或已连接的设备。使用 --verbose 标志运行 CLI 以获取更多详细信息。错误:命令失败:./gradlew app:installDebug -PreactNativeDevServerPort=8081

我的 devcontainer.json:-

{
    "name": "React Native Android Container",
  
    // Sets the run context to one level up instead of the .devcontainer folder.
    "context": "..",
  
    // Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename.
    "dockerFile": "Dockerfile",
  
    "runArgs": [
        "--privileged", // give all capabilities to a container, in other words, the container can then do almost everything that the host can do
        "--net",
        "host", // forwarding all host machine ports
        "-v",
        "/dev/bus/usb:/dev/bus/usb" // mount connected USB devices to a container
      ],
    
  
    "settings": {
      // This will ignore your local shell user setting for Linux since shells like zsh are typically
      // not in base container images. You can also update this to an specific shell to ensure VS Code
      // uses the right one for terminals and tasks. For example, /bin/bash (or /bin/ash for Alpine).
      "terminal.integrated.shell.linux": null
    },
  
    // Add the IDs of extensions you want to be installed when the container is created in the array below.
    "extensions": ["msjsdiag.vscode-react-native"]
  }
Run Code Online (Sandbox Code Playgroud)

runArgs“主机”应该转发所有端口。我想我需要在相反的方向进行类似的论证?

Ash*_*hok -1

检查 的权限android/gradlew。可以使用以下命令检查权限:

stat -c "%a %n" android/gradlew

权限应为 755。如果不是,请将应用程序根文件夹中的权限更改为 755。

chmod 755 android/gradlew

然后运行react-native run-android