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,264
Last edited:

Charlie

Member
Licensed User
Longtime User
Thanks for the suggestion. I looked: it is checked. I was not sure if it was checked during the last install, so I re-installed. No joy - the issue is still happening.
 

agraham

Expert
Licensed User
Longtime User
Running out of ideas here :( From what I can see B4A-Bridge is trying to open a file to write to in File.DirDefaultExternal which would be /mnt/sdcard/Android/data/anywheresoftware.b4a.babridge. The fact that it reports that it fails on temp2.apk is significant - it indicates that it attempted to open temp1.apk, caught the failure and tried again with temp2.apk which also failed but uncaught this time. The file it is failing to write could be the Designer apk as the IDE checks with B4A-Bridge which Designer version, if any, is installed and will download the latest version from the IDE if the device doesn't have it already.

DirDefaultExternal should be created automatically by Android the first time B4A-Bridge is run but it would seem that this is not happening. I'm afraid that I can't think of a reason why. Have you tried rebooting the tablet?
 

Charlie

Member
Licensed User
Longtime User
Yes, the tablet has been rebooted many times. I miss the older hardware where you could pull the battery to be certain of a complete reboot.

The directory /anywheresoftware.b4a.babridge has not even been created. Maybe I'll try creating one manually when I have more time to play.

I've eliminated everything but the tablet I think, as I can connect happily to my phone (running Android 2.3.3)

Thanks for trying, anyway! I can move forward by mounting the tablet as a drive and moving an APK, then dismounting and installing it. It's slow and clumsy, but will eventualy get the job done.
 

Charlie

Member
Licensed User
Longtime User
Can you post the logs when this crash happens?
I don't know how to do that. I can view the report and logs, but I don't have any idea how to save it or cut and paste it. The automated "send feedback for B4A Bridge" has been sent with the description "crash report from Charlie", if that helps...
 

Charlie

Member
Licensed User
Longtime User
Right click on the Logs pane.

Perhaps I did not make the original problem clear. The crash is on the tablet, not in the B4A editor. B4A reports nothing, there are no logs captured in the logs pane. The crash is on the tablet.

If I'm missing what you said, and you really want me to right click on the tablet... well... it has no mouse... so I'm still confused.
 

agraham

Expert
Licensed User
Longtime User
You said that "I can view the report and logs", I assumed that meant you could see it in the Logs pane of the IDE. If there is a crash on the tablet and the tablet is connected to the IDE, either by USB or B4A-Bridge then the reason for the crash and a stack trace should be visible in the Logs pane.
 

Charlie

Member
Licensed User
Longtime User
Sorry, as I said I'm pretty new to this. Here's as acurate a description as I can give:
B4A bridge on the tablet boots up happily. I push the button on the tablet that says "start wireless". I go to the PC, to the editor, choose tools > B4A bridge > Connect - wireless, and choose the tablet IP address. When I hit the O.K. button, there is no error message.
But on the tablet, it says "unfortunately B4A-bridge has stopped." I'm offered Report, or O.K. If I hit report, then hit preview, I can scroll down to system logs, event logs, etc. etc. These are the "logs" I was referring to. I have no idea how to get several pages of data from them, other than retyping for hours.
 

blong

Active Member
Licensed User
Longtime User
Cubieboard and B4A Bridge

I am currently developing on Android based Cubieboard which is NOT a telephone type device.

It has an RJ45 connector ... plus I can use a Wireless dongle.

B4A Bridge works well using Wifi BUT does not work over LAN.

Whilst I know Android phones don't have LAN how hard would it be to add LAN connectivity as well as wireless... happy to test :)

I think there will soon be many Android small computer boards as IMHO Android beats Linux anyday for development !
 

blong

Active Member
Licensed User
Longtime User
LAN and B4A Bridge

Erel

Indeed it did work ... I was using the "previous" wifi IP address...:sign0161:

Minor enhancement would be if Bridge is connected then the LAN IP address is displayed as well as the message about Status : Connected.

Actually when Bridge starts and LAN is active then show IP address so user knows what to enter.

Anyway thanks for the help.. as always greatly appreciated.

Am enjoying Android on a Cubieboard ... perhaps one of the only users here doing such development.

:)
 

blong

Active Member
Licensed User
Longtime User
Now it is giving an error

Erel

I connect the LAN cable and check Android settings and get IP address of 192.168.1.10 all seems OK.

Start B4A Bridge on Cubieboard and have following error

An error has occurred in sub:main_updateip (java line 477) java.lang.security exception:connectivity service: Neither user 10036 nor current process has android.permission.ACCESS_NETWORK_STATE. Continue ?

If I click YES I cannot connect with B4A.

Idea ?? (It did work for a while ??)
 

blong

Active Member
Licensed User
Longtime User
LAN again

Sorry .. did some more testing

If I click YES and continue then Click Start Wireless.. it says it is listening.

Then use Tools etc to connect and it connects OK..

i.e. Start Wireless seems to listen for LAN as well..

But after I click STOP button on IDE on bottomLHS then error pops up again ..
 

Charlie

Member
Licensed User
Longtime User
Erel, did you eventually get the files?

Also, I originally assumed that I had a common problem rather than something unusual. Would it make sense to move this to a new thread rather than pollute the B4A bridge tutorial?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
@blong, This is a bug in the Network library. It doesn't add this permission. In almost all cases it works properly as only the WIFI permission is needed. It will be fixed in the next update of the Network library. You can download the updated B4A-Bridge:
www.b4x.com/android/files/b4a_bridge.apk

@Charlie, I see the reports now. Thank you. It seems like a problem in your sd card. It all the time fails to create the required file. Make sure that it is writable.
 

blong

Active Member
Licensed User
Longtime User
Bug

Thanks Erel... will get updated B4A bridge program.

Regards
 

Charlie

Member
Licensed User
Longtime User
Thanks Erel. Even though I happily write to the card with other applications and can manually put an APK file on it and install from that APK, I tried swapping the card with another. Same issue. I tried a third card - still no joy.

Can you tell me the path it should create and then use?
 
Status
Not open for further replies.
Top