9

I am trying to run a react native docker container on vs code. I am able to run my code. However, the container is not able to detect the android emulator running on my host machine.

I followed along in this tutorial course:

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

On running

npx react-native run-android however, I get an error message that my emulator is not running. error Failed to install the app. Make sure you have an Android emulator running or a device connected. Run CLI with --verbose flag for more details. Error: Command failed: ./gradlew app:installDebug -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"]
  }

the runArgs "host" is supposed to forward all ports. I think I need a similar argument in the reverse direction?

Ashok
  • 3,190
  • 15
  • 31
ambassallo
  • 924
  • 1
  • 12
  • 27
  • running this on Ubuntu 20.04 – ambassallo Oct 18 '20 at 10:09
  • do you use an `adb` connection? –  Oct 20 '20 at 23:03
  • I am trying to connect to the android emulator started from android studio – ambassallo Oct 21 '20 at 06:35
  • I am not sure what adb is.. researching that now – ambassallo Oct 21 '20 at 06:35
  • the `adb` is Android Device Bridge, when you install Android Studio, you already have it. for checking adb, go to terminal and run `adb --version`. if you got the version so you have it. if not you should install it and when you see your emulator by `adb devices` command, then with `yarn android` you can install your app on your emulator. –  Oct 21 '20 at 08:40
  • I do have the adb and I am able to run the emulator on my local host machine. I am trying to connect to the emulator from the vs code container – ambassallo Oct 21 '20 at 12:43
  • did you get it to work I was about to try the same on my box if yes can you please share instruction on how you did it – Chandan Oct 29 '20 at 03:16
  • not yet chandan.. if you get it to work post an answer here.. I will post as answer if I get it to work. Even a bounty could not get me an answer – ambassallo Oct 29 '20 at 09:34
  • https://stackoverflow.com/questions/17770902/forward-host-port-to-docker-container this post may have a clue – ambassallo Nov 07 '20 at 20:39
  • Did you get more information about this? – Lautaro Zarandon May 11 '22 at 02:39
  • @LautaroZarandon ... No , I gave up. – ambassallo May 13 '22 at 10:25
  • I am going to attempt to solve this mystery one more time. If somebody was already able to figure out how this can be done, please enlighten this page. – ambassallo Jul 12 '22 at 17:21
  • Could you add your Dockerfile @ambassallo? I remember that someone adds a node.js server to expose some ports and stuff like that – Jonathan Solorzano Jul 12 '22 at 21:37
  • Also, you're trying to create a local dev environment or a deploy configuration? – Jonathan Solorzano Jul 12 '22 at 21:38
  • @JonathanSolorzano a local dev environment. A deploy config will not be useful. I am not sure if android devices support running containers. I will answer with dockerfile once I succeed. – ambassallo Jul 13 '22 at 07:06

1 Answers1

-1

Check the permissions for android/gradlew. Can check the permissions using the below command:

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

The permissions should be 755. If not change the permissions to 755 inside your app root folder.

chmod 755 android/gradlew

then run react-native run-android

Ashok
  • 3,190
  • 15
  • 31