Android Tutorial B4A-Bridge source code

B4A-Bridge is made of two components. One component is running on the device and the other is embedded in the IDE.
The device side is the server side. It waits for connections and when a connection is established it handles the "action" messages.

The code itself is made of a simple activity:

arSsfzqjKtq2_v9Moofj4SgiWWet6WOFH-P1Z2NuxbMo4yB6yqsGaoioptbDdbMCZw4=h900



And a service that is doing most of the job.
All the network communication is handled by an AsyncStreams object. AsyncStreams are very useful for networking and other external communication.

In this case the AsyncStreams object is initialized in prefix mode. In this mode we always receive complete messages which makes things simpler.
See this tutorial for more information: AsyncStreams Tutorial

This code is a good example for networking and working with service.
You are welcomed to examine the code and ask any question about it.

Source code: https://github.com/AnywhereSoftware/B4A-Bridge
 
Last edited:

teddybear

Well-Known Member
Licensed User
I'm doing something wrong. Copying the .res folder doesn't seem to work. The contents of .res all get deleted/overwritten when I try to compile and I get the same error as above.
1.Extract the res.zip to the project folder
2. Add #AdditionalRes: ..\res to Main module
微信图片_20240904154611.png
 

agraham

Expert
Licensed User
Longtime User
Nope that doesn't work either. Get different errors now. You say extract res.zip, I don't have a res.zip so I'm copying it from the b4a_bridge.apk. That's probably the problem as in .res in the apk the xml files are not actually xml but some binary format. Where can I find res.zip?
B4A Version: 13.00
Parsing code. (0.11s)
Java Version: 19
Building folders structure. (0.02s)
Compiling code. (0.15s)
Compiling layouts code. (0.02s)
Organizing libraries. (0.08s)
(AndroidX SDK)
Compiling resources Error
..\res\anim-v11\btn_checkbox_to_checked_box_inner_merged_animation.xml:1: error: not well-formed (invalid token).
..\res\anim-v11\btn_checkbox_to_checked_box_inner_merged_animation.xml: error: file failed to compile.
..\res\anim-v11\btn_checkbox_to_checked_box_outer_merged_animation.xml:1: error: not well-formed (invalid token).
..\res\anim-v11\btn_checkbox_to_checked_box_outer_merged_animation.xml: error: file failed to compile.
..\res\anim-v11\btn_checkbox_to_checked_icon_null_animation.xml:1: error: not well-formed (invalid token).
..\res\anim-v11\btn_checkbox_to_checked_icon_null_animation.xml: error: file failed to compile.
..\res\anim-v11\btn_checkbox_to_unchecked_box_inner_merged_animation.xml:1: error: not well-formed (invalid token).
..\res\anim-v11\btn_checkbox_to_unchecked_box_inner_merged_animation.xml: error: file failed to compile.
..\res\anim-v11\btn_checkbox_to_unchecked_check_path_merged_animation.xml:1: error: not well-formed (invalid token).
..\res\anim-v11\btn_checkbox_to_unchecked_check_path_merged_animation.xml: error: file failed to compile.
..\res\anim-v11\btn_checkbox_to_unchecked_icon_null_animation.xml:1: error: not well-formed (invalid token).
..\res\anim-v11\btn_checkbox_to_unchecked_icon_null_animation.xml: error: file failed to compile.
..\res\anim-v11\btn_radio_to_off_mtrl_dot_group_animation.xml:1: error: not well-formed (invalid token).
..\res\anim-v11\btn_radio_to_off_mtrl_dot_group_animation.xml: error: file failed to compile.
..\res\anim-v11\btn_radio_to_off_mtrl_ring_outer_animation.xml:1: error: not well-formed (invalid token).
..\res\anim-v11\btn_radio_to_off_mtrl_ring_outer_animation.xml: error: file failed to compile.
..\res\anim-v11\btn_radio_to_off_mtrl_ring_outer_path_animation.xml:1: error: not well-formed (invalid token).
..\res\anim-v11\btn_radio_to_off_mtrl_ring_outer_path_animation.xml: error: file failed to compile.
..\res\anim-v11\btn_radio_to_on_mtrl_dot_group_animation.xml:1: error: not well-formed (invalid token).
..\res\anim-v11\btn_radio_to_on_mtrl_dot_group_animation.xml: error: file failed to compile.
 

teddybear

Well-Known Member
Licensed User
The zip was uploaded at post#60, delete the res folder first, then extract it
微信图片_20240904161249.png
 

agraham

Expert
Licensed User
Longtime User
I'm obviously being stupid but I'm still getting the 'not well formed' and other errors.
Finally got it to work. Many thanks for the help. The final problem was this
2. Add #AdditionalRes: ..\res to Main module
I cut and pasted this but there is an extra space after the colon that was messing the path up! Luckily I noticed it when carefully comparing your screenshot to my code in the IDE.
 

teddybear

Well-Known Member
Licensed User
The extra space after the colon is irrelevant. the error log of post # 64 was caused by the IDE opening the project and compiling it at the first time , recompiling will be ok
 

aeric

Expert
Licensed User
Longtime User
I have posted my modified version. Maybe it works for you.


or https://github.com/pyhoon/B4A-Bridge
 
Top