B4J Question Firebase extending example.

tigrot

Well-Known Member
Licensed User
Longtime User
Hi everybody
I have modified and extended Erel's Firebase Messaging example:

B4X:
Non-UI application (console / server application)
#Region  Project Attributes
    #CommandLineArgs:
    #MergeLibraries: True
    #AdditionalJar: 'firebase-messaging.jar'
#End Region

Sub Process_Globals
    Private const API_KEY As String = "XXXXXXXXXXXXXXXXXXXXXXXXXX"
    Dim fm As FirebaseMessaging
End Sub
Sub fm_MessageArrived (Message As RemoteMessage)
   Log("Message arrived")
   Log($"Message data: ${Message.GetData}"$)
   Log(Message.GetData.Get("title"))
   Log( Message.GetData.Get("body"))
End Sub

Sub AppStart (Args() As String)
    fm.Initialize("fm")
    fm.SubscribeToTopic("general") 'you can subscribe to more topics
    SendMessage("general", "This is the title", "Hello!!!!")
    StartMessageLoop
End Sub

Private Sub SendMessage(Topic As String, Title As String, Body As String)
    Dim Job As HttpJob
    Job.Initialize("fcm", Me)
    Dim m As Map = CreateMap("to": $"/topics/${Topic}"$)
    Dim data As Map = CreateMap("title": Title, "body": Body)
    m.Put("data": data)
    Dim jg As JSONGenerator
    jg.Initialize(m)
    Job.PostString("https://fcm.googleapis.com/fcm/send", jg.ToString)
    Job.GetRequest.SetContentType("application/json")
    Job.GetRequest.SetHeader("Authorization", "key=" & API_KEY)
End Sub


Sub JobDone(job As HttpJob)
    Log(job)
    If job.Success Then
        Log(job.GetString)
    End If
    job.Release
    StopMessageLoop '<-- non ui app only
End Sub

The program, before adding the library provided with the example, connected and worked fine. I have added fm_arrived as well. The library included was extracted from Android AAR and renamed.
I get this error:
B4J version: 4.50
Parsing code. (0.00s)
Compiling code. (0.15s)
Compiling layouts code. (0.00s)
Compiling generated Java code. Error
Cannot find: C:\Program Files (x86)\Anywhere Software\B4J\libraries\com.google.firebase:firebase-messaging.jar

I'm not deep in Java so I'm wondering where is my fault...

Thank you in advance for help.

Mauro
 
Last edited:
Top