android - 使用 vs 代码对本机 docker 容器做出反应以发布到主机操作系统上的 android 模拟器
问题描述
我正在尝试在 vs 代码上运行一个反应原生 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"]
}
runArgs“主机”应该转发所有端口。我想我需要一个相反的类似论点?
解决方案
检查android/gradlew
. 可以使用以下命令检查权限:
stat -c "%a %n" android/gradlew
权限应为 755。如果不是,请在您的应用根文件夹中将权限更改为 755。
chmod 755 android/gradlew
然后运行react-native run-android