I tried the project.
My B4A Logs show:
Logger connected to: HONOR VNE-LX2
--------- beginning of main
Copying updated assets files (16)
*** Service (starter) Create ***
Error opening auto discover port
(ErrnoException) android.system.ErrnoException: bind failed: EADDRINUSE (Address already in use)
** Service (starter) Start **
** Activity (main) Create (first time) **
** Activity (main) Resume **
17
** Activity (main) Pause, UserClosed = false **
Sleep not resumed (context is paused): anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub
*** Service (service1) Create ***
android.system.ErrnoException: bind failed: EADDRINUSE (Address already in use)
Error occurred on line: 92 (Service1)
java.lang.IllegalArgumentException: Invalid notification (no valid small icon): Notification(channel=*** shortcut=null contentView=null vibrate=null sound=null defaults=0xfffffffc flags=0x0 color=0x00000000 vis=PRIVATE)
at android.app.NotificationManager.fixNotification(NotificationManager.java:715)
at android.app.NotificationManager.notifyAsUser(NotificationManager.java:694)
at android.app.NotificationManager.notify(NotificationManager.java:643)
at android.app.NotificationManager.notify(NotificationManager.java:619)
at anywheresoftware.b4a.objects.NotificationWrapper.Notify(NotificationWrapper.java:284)
at com.puterise.b4abridge.service1._updatenotification(service1.java:1044)
at com.puterise.b4abridge.service1._service_create(service1.java:977)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
at com.puterise.b4abridge.service1.onCreate(service1.java:56)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:5541)
at android.app.ActivityThread.-$$Nest$mhandleCreateService(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2886)
at android.os.Handler.dispatchMessage(Handler.java:117)
at android.os.Looper.loopOnce(Looper.java:210)
at android.os.Looper.loop(Looper.java:302)
at android.app.ActivityThread.main(ActivityThread.java:9652)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:601)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1062)
** Service (service1) Start **
Error #1: (ErrnoException) android.system.ErrnoException: bind failed: EADDRINUSE (Address already in use)
Sub Service_Create
folder = rp.GetSafeDirDefaultExternal("")
If folder = File.DirInternal Then
ToastMessageShow("Secondary storage is not available. You will need to switch to USB debug mode.", True)
End If
Try
AutoDiscoverUdpSocket.Initialize("AutoDiscoverUdpSocket", 58912, 8192)
Catch
Log("Error opening auto discover port")
Log(LastException)
End Try
AcquireMulticastLock
End Sub
Error #2: android.system.ErrnoException: bind failed: EADDRINUSE (Address already in use)
Sub Service_Create
Try
If WifiServer.IsInitialized = False Then
WifiServer.Initialize(6789, "Server")
End If
Catch
Log(LastException.Message)
'switch to alternate port
WifiServer.Initialize(6789 + 117, "Server")
End Try
If Phone.SdkVersion >= 16 And UdpServer.IsInitialized = False Then
UdpServer.Initialize("Udp", 0, 8192)
End If
DisconnectTimer.Initialize("DisconnectTimer", 1000)
PE.Initialize("PE")
UpdateNotification
Service.StartForeground(1, Notification1)
Try
SetFTPServerState
Catch
Log(LastException)
End Try
End Sub
For error #1 and #2, I think because B4a-Bridge already running using a port number. I tried to change the port number.
Error #3:
java.lang.IllegalArgumentException: Invalid notification (no valid small icon): Notification(channel=*** shortcut=null contentView=null vibrate=null sound=null defaults=0xfffffffc flags=0x0 color=0x00000000 vis=PRIVATE)
Private Sub UpdateNotification
Dim icon As String
Dim content As String
If ConnectedStatus Then
icon = "a_connected"
content = "Connected"
Else
icon = "a_disconnected"
content = "Disconnected"
End If
Notification1.Initialize2(Notification1.IMPORTANCE_LOW)
Notification1.Sound = False
Notification1.Vibrate = False
Notification1.Icon = icon
Notification1.SetInfo("B4A-Bridge", content, Main)
Notification1.Notify(1)
End Sub
Solution #1 (error #3)
Let me fix this error first.
It seems the project is missing the following files:
a_connected.png
a_disconnected.png
Just put back these 2 files to B4A-Bridge267e\Objects\res\drawable
View attachment 168266
After fixing error #3, it is still showing error and I find the code actually handle the alternate port number.
Try
If WifiServer.IsInitialized = False Then
WifiServer.Initialize(6789, "Server")
End If
Catch
Log(LastException.Message)
'switch to alternate port
WifiServer.Initialize(6789 + 117, "Server")
End Try
Then I found the error #4.
Logger connected to: HONOR VNE-LX2
--------- beginning of main
*** Service (starter) Create ***
Error opening auto discover port
(ErrnoException) android.system.ErrnoException: bind failed: EADDRINUSE (Address already in use)
** Service (starter) Start **
** Activity (main) Create (first time) **
** Activity (main) Resume **
17
*** Service (service1) Create ***
Error occurred on line: 53 (Service1)
android.app.MissingForegroundServiceTypeException: Starting FGS without a type callerApp=ProcessRecord{6188154 27609:com.puterise.b4abridge/u0a393} targetSDK=35
at android.app.MissingForegroundServiceTypeException$1.createFromParcel(MissingForegroundServiceTypeException.java:53)
at android.app.MissingForegroundServiceTypeException$1.createFromParcel(MissingForegroundServiceTypeException.java:49)
at android.os.Parcel.readParcelableInternal(Parcel.java:4890)
at android.os.Parcel.readParcelable(Parcel.java:4872)
at android.os.Parcel.createExceptionOrNull(Parcel.java:3072)
at android.os.Parcel.createException(Parcel.java:3061)
at android.os.Parcel.readException(Parcel.java:3044)
at android.os.Parcel.readException(Parcel.java:2986)
at android.app.IActivityManager$Stub$Proxy.setServiceForeground(IActivityManager.java:6833)
at android.app.Service.startForeground(Service.java:781)
at anywheresoftware.b4a.objects.ServiceHelper.StartForeground(ServiceHelper.java:85)
at com.puterise.b4abridge.service1._service_create(service1.java:980)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
at com.puterise.b4abridge.service1.onCreate(service1.java:56)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:5541)
at android.app.ActivityThread.-$$Nest$mhandleCreateService(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2886)
at android.os.Handler.dispatchMessage(Handler.java:117)
at android.os.Looper.loopOnce(Looper.java:210)
at android.os.Looper.loop(Looper.java:302)
at android.app.ActivityThread.main(ActivityThread.java:9652)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:601)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1062)
** Service (service1) Start **
Solution #2 (error #1 and #2)
It seems the errors are related to
Foreground service types
B4A v13.0+ should be used with targetSdkVersion 34+. Android 14 continues the longtime trend of making services less flexible and more difficult to use (converging to iOS background tasks features from 2014). Many of the previous use cases for services are better covered by receivers...
www.b4x.com
It means we need to update the Manifest editor.
The easiest way is to check Erel's source code for B4A Bridge here:
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...
www.b4x.com
which is hosted on GitHub and by observing the xml file here:
https://github.com/AnywhereSoftware/B4A-Bridge/blob/main/Objects/AndroidManifest.xml
I guess I need to add the following to the Manifest Editor:
AddPermission(android.permission.FOREGROUND_SERVICE_CONNECTED_DEVICE)
SetServiceAttribute(service1, android:foregroundServiceType, "connectedDevice")
So the app is now compile and run on my phone.