Android Question Android Studio on Mac

marcick

Well-Known Member
Licensed User
Longtime User
Hi all,

now that I have a Mac M4 running the Build Server and the iOS Simulator, it would be great to also use the Android Studio emulator on the same Mac, so I could have both simulators running on the second screen.

However, it seems quite difficult to make B4A on Windows detect the Android emulator on the Mac through ADB. I’ve tried many attempts (even with help from ChatGPT) but with no success.

Has anyone actually managed to make this work?

Thanks!
 

marcick

Well-Known Member
Licensed User
Longtime User
What do you mean by Windows? Do you use Parallel Desktop or Virtual Machine?
No, no. I've installed Android Studio on the Mac and the emulator is running. In theory adb is listening on port 5555 (all firewalls disabled) but the Windows PC where B4A runs doesn't see the emulator on the Mac.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
No, no. I've installed Android Studio on the Mac and the emulator is running. In theory adb is listening on port 5555 (all firewalls disabled) but the Windows PC where B4A runs doesn't see the emulator on the Mac.
Do you mean you want to access the emulator on Mac from a Windows PC running B4A on the same network?
 
Upvote 0

aeric

Expert
Licensed User
Longtime User

To connect your B4A IDE on a Windows PC to an Android emulator running on a Mac within the same network, you must use Android Debug Bridge (adb) with port forwarding. The B4A-Bridge app itself is typically for physical devices or emulators running on the local Windows machine (e.g., Bluestacks on Windows), not for remote emulators on a different OS over the network.

On your Mac
  1. Start the Android Emulator: Launch your desired AVD (Android Virtual Device) from Android Studio's AVD Manager on the Mac.
  2. Open Terminal: Open the Terminal application on your Mac.
  3. Stop the adb server: Run the command adb kill-server. This ensures that the adb on the Mac doesn't interfere with the connection setup.
  4. Identify emulator ports: Run the following command to find the ports the emulator is using:
    Bash:
    lsof -iTCP -sTCP:LISTEN -P | grep 'emulator\|qemu'
    The output will show a pair of sequential ports (e.g., 5554 and 5555). The odd-numbered port (e.g., 5555) is used for adb connections.
  5. Set up port forwarding: The emulator's adb port (e.g., 5555) listens only on the loopback interface (127.0.0.1). You need to forward inbound TCP packets received externally on an available port to the loopback interface using nc (netcat). Open a new Terminal window and keep this command running:
    Bash:
    cd /tmp
    mkfifo backpipe
    nc -kl 5555 0<backpipe | nc 127.0.0.1 5555 > backpipe
    This forwards port 5555 traffic from the Mac's external network interface to the internal loopback interface.
  6. Get the Mac's IP address: Find your Mac's IP address on the local network (e.g., 192.168.0.2). You can use the ifconfig command in Terminal to find it.

On your Windows PC
  1. Open Command Prompt: Navigate to your Android SDK's platform-tools directory in Command Prompt (e.g., C:\B4A\sdk\platform-tools).
  2. Connect to the remote emulator: Use adb connect with the Mac's IP address and the adb port you identified (e.g., 5555).
    B4X:
    adb connect <Mac's IP address>:5555
    (e.g., adb connect 192.168.0.2:5555)
  3. Verify the connection: Run adb devices to confirm the emulator is listed as a connected device.
  4. Configure B4A IDE: In B4A, go to Tools > B4A-Bridge > Connection and enter the Mac's IP address and the port used for adb connection (e.g., 5555).
Your B4A IDE on Windows should now recognize and be able to deploy apps to the emulator running on the Mac. Keep the nc command running on the Mac Terminal for the connection to persist.
 
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
Perfect instructions! I spent a lot of time with ChatGPT doing similar steps, but the missing port-forwarding part prevented it from working.
Thanks :)
 
Upvote 0
Top