Android Question Android Studio & B4A

Marco Nissen

Active Member
Licensed User
Longtime User
Hi

I'm trying to use the following setting, because the emulator is now super fast ..
+ M1 Max Mac
+ Android Studio on Mac, with AVD = Pixel 6 + Android 33
+ B4A Bridge in emulator session
+ Parallels to run Win 11 ARM

Now the issue is that bridge.apk is behind a local router firewall of the android studio setting.
So, it can see the internet, but is separated from the host environment
B4A can't connect to any of the IP choices (i.e. not connecting to the host IP, or localhost, or the spooky 10xxx IP which is of course unreachable)

Is there anybody out there who managed to get use of this setting and has a good advice how to proceed?
The emulator years ago was super crappy and slow but since it's now to buttery smooth and fast, I hoped to be able to use it

Thanks
Marco
 

Attachments

  • Screenshot_1659208468.png
    Screenshot_1659208468.png
    77.7 KB · Views: 103

MicroDrie

Well-Known Member
Licensed User
I can't give you advise for the MAC, however for Windows you need to give access to the bridge into the firewall as an incoming firewall rule if you use the external pc firewall 10.x.y.z address. Confusing here is that the PC has an internal loopback address of 127.0.0.1 in addition to an externally assigned fixed or DHCP issued network address of, for example, 10.x.y.z. which can vary within the specified range in the router.
Usually the Windows firewall and the router allow all outgoing network traffic to the Internet and the incoming network traffic must be allowed with a firewall rule.
1659223430831.png

Note that from the virtual PC no firewall rule needs to be added for the internal PC loop-back address 127.0.0.1 when used from the same PC loop-back address (shown in green) . This in contrast when the external 10.x.y.z address of the PC is used from the PC! (red line) which is outgoing through the firewall and sent back by the router as incoming traffic through the firewall to the PC.
 
Upvote 0

Marco Nissen

Active Member
Licensed User
Longtime User
I ensured that no firewalls are running
the emulator address shown in b4a bridge is 10.0.2.16 but I can't use to talk to the app
the address comes from the issue that android studio creates a local network for the virtual machines
my computer has the address 192.168.178.140, and if I now use bridge the parallels vm gets 192.168.178.143
however, if I want to talk to xxx143 to reach the emulator, it does not get there.

the M1 thing is probably completely irrelevant, but that was just FYI
any other thoughts?
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
+ M1 Max Mac
+ Android Studio on Mac, with AVD = Pixel 6 + Android 33
+ B4A Bridge in emulator session šŸ¤” = windows = behind firewall must be opened with firewall rules!
+ Parallels to run Win 11 ARM šŸ¤” = is this a virtual machine which host the Windows environment?
The point is that according to your information different non-routable network addresses (loopback address 127.0.0.1, 192.168.x.x and 10.0.2.15) are used. Normally, those non-routable network addresses can't talk to an other (non-routable) network, other than with an addition to the routing table on every device that hosts an application (described nicely in the picture as 'virtual router'). In order for this to work, you need to know exactly where which application resides before or after a firewall on each required device.
 
Upvote 0

Marco Nissen

Active Member
Licensed User
Longtime User
The point is that according to your information different non-routable network addresses (loopback address 127.0.0.1, 192.168.x.x and 10.0.2.15) are used. Normally, those non-routable network addresses can't talk to an other (non-routable) network, other than with an addition to the routing table on every device that hosts an application (described nicely in the picture as 'virtual router'). In order for this to work, you need to know exactly where which application resides before or after a firewall on each required device.
yes . I tried some port forwarding, but I am not sure how B4A talks to B4A bridge.
port 5037 (adb) didn't really work out so well
 
Upvote 0

Marco Nissen

Active Member
Licensed User
Longtime User
You can study the B4A-Bridge source code for the used and alternative ports.
all right. it connects through port 6789

I added a port forwarding in the AVC console (telnet 5554) by entering "redir add tcp:6789:6789" which adds a route from the Mac host to the AVD emulator
now entering "telnet localhost 6789" will let B4A bridge to say that there is a connection (i.e. testing locally works fine)

only thing is, that the process only is listening for localhost (as LSOF would report: qemu-syst 7684 nissenm 76u IPv4 0xa1ca195628ab9e05 0t0 TCP 127.0.0.1:6789 (LISTEN))

>> so any idea how to change the 127.0.0.1:6789 to *:6789 ?
then I could connect from the virtual machine (Win11 / B4A) to the emulator on the local machine (macOS / AVD)

>> or, is It possible to let parallels share the network environment with the host computer, i.e. that connecting to 127.0.0.1 would actually connect to the Mac computer?
 
Upvote 0

Marco Nissen

Active Member
Licensed User
Longtime User
FY all -- SOLVED

AVD config using telnet 5554 on the Mac host :
AVD config:
redir add tcp:6789:6789

/etc/pf.conf - note here: the b4a lines are new
pf.conf:
scrub-anchor "com.apple/*"
nat-anchor "com.apple/*"
rdr-anchor "com.apple/*"
rdr-anchor "b4a"
dummynet-anchor "com.apple/*"
anchor "com.apple/*"
load anchor "com.apple" from "/etc/pf.anchors/com.apple"
load anchor "b4a" from "/etc/pf.anchors/com.b4a"

/etc/pf.anchors/com.b4a
com.b4a:
rdr pass on lo0 inet proto tcp from any to any port 6789 -> 127.0.0.1 port 6789
rdr pass on en0 inet proto tcp from any to any port 6789 -> 127.0.0.1 port 6789
rdr pass on en1 inet proto tcp from any to any port 6789 -> 127.0.0.1 port 6789

now, restart package filter
restart commands:
sudo pfctl -d
sudo pfctl -ef /etc/pf.conf

when doing that, I can now successfully run b4a in parallels using windows 11 arm, and connect it to the virtual device of android studio

only thing is, when you connect B4A, make sure to pull the correct IP address from macOS, and the network settings (e.g. 192.168xxx instead of 10.xxx)
 
Last edited:
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Good that it works. According the B4A-Bridge source you maybe hit the following points:
  1. If port 6789 fails a second try to port 6901 will be used
  2. As the phone SDK version is equal or greater 16 then a udp server is started
  3. The FTP server on port 6781 and port 6782 - 6788 for the data ports
 
Upvote 0

Marco Nissen

Active Member
Licensed User
Longtime User
It works "sort of"
B4A says it works, the designer app could be installed, my app takes pretty long for copying
drag & drop from the Mac side works much fast of course

You meant 6906, right ? ( 6789 + 117)

I can add more lines in the config to include this and the FTP ports, but since UDP is automatically assigned I can't add UDP lines.

Maybe that's the reason why debugging still doesn't work

and another issue is - whenever I restart the virtual device, I'll to re-add the port routings
 
Upvote 0
Top