我正在尝试在 vs 代码上运行一个 react 本机 docker 容器。我能够运行我的代码。但是,容器无法检测到在我的主机上运行的 Android 模拟器。
< code >在本教程中,我一直在学习:
https://code.visualstudio.com/docs/remote/containers
在奔跑
npx react-local run-android但是,我收到一条错误消息,表明我的模拟器未运行。错误安装应用程序失败。确保您有一个Android模拟器正在运行或连接了设备。使用--verose标志运行CLI以了解更多详细信息。错误:命令失败:./gradlew app: install Debug-PreactNativeDevServerPort=8081
My 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"]
}
runArgs“host”应该转发所有端口。我想我需要一个反方向的类似论证?
检查android/gradlew
的权限。可以使用以下命令检查权限:
stat-c“%a%n”Android/gradlew
权限应该是755。如果没有,请将应用根文件夹中的权限更改为755。
chmod 755 android/gradlew
然后运行 react-native run-android