1

am trying to run an android emulator on a windows pc and then am trying to run the code on another windows PC.

Like, i have a window pc with 8gb ram so it can't carry an emulator and still run the code together, so since i have 2 windows pc (not hign end), am trying to make use of both in order to make my work more faster as it always get super slow when i run my code and an emulator on one PC.

Am a flutter dev and that is what am using for coding in android, so if anyone knows of a way please do suggest it here, i will mean a lot to me and to some other people who are running into such problems.

Thanks in advance.

I have tried researching about this but it seems that it is quite easy to do if i had learnt react native instead as i can use expo for this and it will work find, but since am using flutter and since flutter don't have expo like software then am finding it hard to do this.

2 Answers2

2

There is another Question similar to this with many answers. Combining the answers helped me reach a solution for Windows 10 on both systems, SDK Emulator and Android Studio. I'm sharing it here since this post comes first when you search for this problem.

Android Studio uses ADB (Android Debug Bridge) for detection and communication of android device. When it starts it will look for local emulated devices on port 555*. Usually its 5554.

It is possible to use ADB's command line to connect to another IP for the emulated device. But sadly the emulator that comes with Android SDK won't bind to 0.0.0.0 and there is no way to change its listening host-name/IP. Meaning that it will only accept local requests.

A port forwarding SSH tunnel will trick Emulator and Android Studio into thinking they're both on the same machine. If you have SSH working between IDE and Emulator PC skip to "Tunnel is working". If not here is what i found practical:

SSH Client on IDE PC

To avoid typing SSH password every time we are going to use public key authentication.

Open a command prompt type ssh to see if its already installed.

if not, install it by Settings > Apps > Optional features > Add a features > "OpenSSH Client".

Open Services and set OpenSSH Authentication Agent to Automatic and start it.

Enter ssh-keygen on command prompt. keep pressing enter for default rsa key pair and to avoid setting password on the keys.

Open C:\Users\IDE_UserName\.ssh. Generated public and private keys are placed in 2 separate files. Open PowerShell in the same directory (Shift + Right Click).

Enter ssh-add you should see "Identity added". This will add the generated key into Authentication Agent used by the SSH client.

Copy id_rsa.pub file which contains your public key to your emulator PC. Take note of its location we need it later.

SSH Server on Emulator PC

Install it by Settings > Apps > Optional features > Add a features > "OpenSSH Server".

Or you can get the latest stable version: Here

Using your favorite text editor with admin privileges open C:\ProgramData\ssh\sshd_config

UnComment StrictModes yes and change it to no

UnComment PubkeyAuthentication yes

UnComment PasswordAuthentication yes and change it to no

Comment AuthorizedKeysFile __PROGRAMDATA__/ssh/administrators_authorized_keys

Save and close the config file.

Rename id_rsa.pub of IDE_PC to authorized_keys and place it at C:\Users\EMU_UserName\.ssh.

Open Services and set OpenSSH SSH Server to Automatic make sure to restart / start it for changes to take effect.

Make sure port 22 is open on emulator PC's firewall.

Back on IDE PC

Our setup is done. We should be able to ssh into Emulator PC without entering a password.

Test it by ssh IdeUser@EmuHostname|ip like ssh mike@192.168.1.4

In case of any trouble follow a guide like: This

Tunnel is working

Now that SSH is working we can use it to forward ports 5554 and 5555 using the command:

ssh -NL 5554:localhost:5554 -L 5555:localhost:5555 IdeUser@EmuHostname

Credits and Thanks Christopher Orr

Don't close the prompt window as we should keep the port forwarding ssh tunnel open while working. Also note that it's better to open the tunnel before running Android Studio. Otherwise we should restart ADB on IDE_PC.

Finally disable ADB on EMU_PC

By changing ADB location settings in Extented Controls or if its already set you can do this by renaming or moving ADB.exe file located at EMU_PC\AndroidSDK\platform-tools

For smoother workflow we can place the tunnel command into a vbs (Visual Basic Script) file to avoid a command prompt forever open in our taskbar like so:

Set oShell = CreateObject ("Wscript.Shell") 
Dim strArgs
strArgs = "cmd /c ssh -NL 5554:localhost:5554 -L 5555:localhost:5555 IdeUser@EmuHostname"
oShell.Run strArgs, 0, false

When you are done with the tunnel you can close it by killing ssh.exe process.

1

If you want to run an emulator on one computer and run code on another computer, you need to have both computers connected to the same network. Here's how you can do this:

  1. Install an emulator on the first computer. For example, if you want to use Android emulator, you can install Android Studio.
  2. Start the emulator on the first computer. This will create a virtual device that runs on the first computer.
  3. Connect the second computer to the same network as the first computer.
  4. On the second computer, use an Integrated Development Environment (IDE) like Android Studio to develop your code.
  5. In the IDE, select the virtual device created on the first computer as the target for running your code.
  6. Run your code on the second computer, and it will be executed on the virtual device running on the first computer.

Note: The steps may vary depending on the specific emulator and IDE you're using.

  • Hmmm, do you mean it's this simple, if so then how can the second computer dictate the first computer emulator even if they are connected to the same network, some complicated answer I saw earlier was talking about using a port forwarding tool for this. Can you please explain your approach? – Michael Stephen Feb 11 '23 at 18:23
  • Would you please provide more detail on step 5? I’m condiering doing this, but I’m uncertain how to select the virtual device on the remote computer. Thanks. – Bink May 17 '23 at 21:04