Android Tutorial B4A-Bridge a new way to connect to your device

Status
Not open for further replies.
There are several options to develop with B4A:
- Android emulator or a VM.
- Connect to a real device in USB debugging mode
- Connect to a real device with B4A-Bridge.

I recommend starting with B4A-Bridge, which is the simplest connection method.

USB Debug Mode

You will need to first configure your device to support USB debugging (Settings - Developer - USB debugging).

In order to reveal the developer settings you should follow these instructions:
- Choose Settings - About Phone
- Find the Build Number entry and click on it 7 times.
- On many devices you need to set the USB connection type to MTP or PTP.

Not all devices support USB debugging.

B4A-Bridge

B4A-Bridge is made of two components. One component runs on the device and allows the second component which is part of the IDE to connect and communicate with the device.
The connection is done over the local network or with a Bluetooth connection.

Once connected, B4A-Bridge supports all of the IDE features which include: installing applications, viewing the logs, debugging and the visual designer (taking screenshots is not supported).

Android doesn't allow applications to quietly install other applications, therefore when you run your application using B4A-Bridge you will see a dialog asking you to approve the installation.

Getting started with B4A-Bridge
1. First you need to install B4A-Bridge on your device.
B4A-Bridge can be downloaded from Google Play: https://play.google.com/store/apps/details?id=anywheresoftware.b4a.b4abridge

Note that you need to allow installation of applications from "Unknown sources". This is done by choosing Settings from the Home screen - Manage Applications.


2. Run B4A-Bridge on your device. It will display a screen similar to:

arSsfzqjKtq2_v9Moofj4SgiWWet6WOFH-P1Z2NuxbMo4yB6yqsGaoioptbDdbMCZw4=h900



3. Connect the IDE to the device

Go to Tools -> B4A-Bridge -> Connection -> New IP

You will be asked to enter the device IP address. The IP is displayed on the device.

The status bar at the bottom of the screen shows the current status:

SS-2016-09-29_09.31.05.png


SS-2016-09-29_09.31.46.png


That's it.

When B4A-Bridge gets connected it first checks if the designer application needs to be updated. In that case it will first install the designer application.

B4A-Bridge keeps running as a service until you press on the Stop button.
You can always reach it by opening the notifications screen.


As mentioned above, when you run an application you are required to approve the installation. You will usually see the following screens:

SS-2012-03-21_10.50.48.png


Note that the Internet permission is automatically added in debug mode.

SS-2012-03-21_10.52.17.png


In the above dialog you should choose Open to start the application.
If you try to install an existing application signed with a different key, the install will fail (without any meaningful message). You should first uninstall the existing application. Go to the home screen - Settings - Applications - Manage applications - choose the application - Uninstall.

Once you finished developing you should press on the Stop button in order to save battery.

Logs

With B4A-Bridge the logs will only appear in release mode if you add this line to the main module:
B4X:
#BridgeLogger: True
It is better to comment this line before submitting your app to Google Play.


B4A-Bridge source code is available here: http://www.b4x.com/forum/basic4andr...ls/8153-b4a-bridge-source-code.html#post45854

Tip

You can click on the B4A-Bridge status in the IDE to connect or disconnect the bridge.
 

Attachments

  • upload_2016-9-29_9-29-57.png
    upload_2016-9-29_9-29-57.png
    14.3 KB · Views: 6,239
Last edited:

moster67

Expert
Licensed User
Longtime User
I also have problems.

I can't find any outgoing calls using "NetStat -a" on my PC. I have disabled FIrewall. ADB with USB works nicely with my device. I tried to launch the log as suggested by you but it's only popolated by some "b". Nothing in log which indicates a problem.

Does B4A Bridge on the device open a specific port? Perhaps it's in use on my device?
 

susu

Well-Known Member
Licensed User
Longtime User
I tried with wifi at my home, device still say "My IP: 192.168.16.20" (the same IP I tried at work). Is it strange? I ping this IP and can't reach.

Ps: I run "basic4android -log" and got error from Windows

Basic4android has stopped working

Problem details:
Description:
Stopped working

Problem signature:
Problem Event Name: CLR20r3
Problem Signature 01: basic4android.exe
Problem Signature 02: 1.3.0.0
Problem Signature 03: 4d6a7b32
Problem Signature 04: mscorlib
Problem Signature 05: 2.0.0.0
Problem Signature 06: 4bebd50b
Problem Signature 07: 344b
Problem Signature 08: 119
Problem Signature 09: System.IO.DirectoryNotFound
OS Version: 6.1.7600.2.0.0.256.1
Locale ID: 1033

Read our privacy statement online:
Windows 7 Privacy Statement - Microsoft Windows

If the online privacy statement is not available, please read our privacy statement offline:
C:\Windows\system32\en-US\erofflps.txt
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
I tried with wifi at my home, device still say "My IP: 192.168.16.20" (the same IP I tried at work). Is it strange? I ping this IP and can't reach.
Maybe the real IP is different for some reason?
Check the IP reported in your device network settings.

It seems like some network problem. Your device should respond to the ping request.

About the logs. Create a folder named C:\Temp and it should work. Though I don't think that there will be anything useful there in this case.
 

susu

Well-Known Member
Licensed User
Longtime User
You're right, the "real IP" of my device is 192.168.0.110 and it works. I just don't know why B4A Bridge keep saying that my IP is 192.168.16.20? Maybe it's a bug?
 

susu

Well-Known Member
Licensed User
Longtime User
No, my laptop and mobile connected to the same wifi network. I also disconnect my mobile from 3G/EDGE.
 

susu

Well-Known Member
Licensed User
Longtime User
Yes, I'm satisfied with B4A Bridge. Hope you will add more functions soon. Thank you :D
 

moster67

Expert
Licensed User
Longtime User
Erel,

Problem resolved. Got error due to a custom ROM. Flashed another one and now it works.

Great tool!
 

wes58

Active Member
Licensed User
Longtime User
B4A-Bridge works fine with Basic4Android but when I try to connect adb from the Command prompt, using: "adb connect 192.168.0.10:6789" I get the status on the PC that adb connected to the device, but then, on the device I get a message that "B4A-Bridge has stopped unexpectedly".
Any solution for that?
 

tremara1

Active Member
Licensed User
Longtime User
awwwesommmme!!

I cant believe the pain banging my head against the emulator was and now what a joy it is to develop......thank you.........
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4A-Bridge works fine with Basic4Android but when I try to connect adb from the Command prompt, using: "adb connect 192.168.0.10:6789" I get the status on the PC that adb connected to the device, but then, on the device I get a message that "B4A-Bridge has stopped unexpectedly".
Any solution for that?
B4A-Bridge is not supposed to work with ADB.
 

bobsimoneau

Member
Licensed User
Longtime User
I liked it better in version 1.2 where you could start the emulator automatically. I do not see the use for the bridge for me. I dislike having to remember to start the AVD manager first. Perhaps there should be a setting to choose bridge or AVD.
 

anuj0sharma

Member
Licensed User
Longtime User
hello

Hello Admin and all expert members :sign0085:
I am a new bee :sign0104: to the android development and not familier with any java coding..I want to connect my development platform to my pc via b4a-bridge.

1. where to find the "b4a-bridge.apk"? the link in foram has all source file in the zip. can anyone share the file?

2. how can I compile those source to .apk ? [if doing so is easy, I do not have eclipse]

3. can I use wired LAN between device and my pc to connect via b4a-bridge?
[no wireless capability in the device]

4. does b4a-bridge supports android 1.6? [as the device for devlopment runs the same]
 

anuj0sharma

Member
Licensed User
Longtime User
thanks for the prompt reply Erel :icon_clap:
I am trying my hands on b4a trial version only.
please compile the code and try to post the apk file to install it on the develpment device side.
thanks for the help, Erel.
 

anuj0sharma

Member
Licensed User
Longtime User
:signOops:

I tryed that link. in my pc its always gets downloaded as a zip file with souce files inside. Is there a problem at my end?

anyways, sent u a requiest for standard version purchase..please do consider.
thanks again.
 
Status
Not open for further replies.
Top