Android Question Easy example for Cloud Firestore library

cas6678

Active Member
Licensed User
I used the FirestoreEx from @DonManfred but not work,

I put my json and name of packet of my project cloud in Firestore, is this ok?

B4X:
B4A Versión: 9.30
Java Versión: 11
Parseando código.    (0.03s)
Building folders structure.    (0.03s)
Compilando código.    (0.14s)
Compilado códigos de diseños.    (0.02s)
Organizando librerías.    (0.14s)
    (Android Support Library)
Generando el fichero R.    Error
c:\android\tools\..\extras\b4a_remote\androidx\core\core\1.1.0\unpacked-core-1.1.0\res\values\values.xml:121: error: Attribute "fontProviderFetchStrategy" already defined with incompatible format.
c:\android\tools\..\extras\b4a_remote\com\android\support\support-compat\28.0.0\unpacked-support-compat-28.0.0\res\values\values.xml:42: Original attribute defined here.
c:\android\tools\..\extras\b4a_remote\androidx\core\core\1.1.0\unpacked-core-1.1.0\res\values\values.xml:136: error: Attribute "fontProviderFetchTimeout" already defined with incompatible format.
c:\android\tools\..\extras\b4a_remote\com\android\support\support-compat\28.0.0\unpacked-support-compat-28.0.0\res\values\values.xml:54: Original attribute defined here.
c:\android\tools\..\extras\b4a_remote\androidx\core\core\1.1.0\unpacked-core-1.1.0\res\values\values.xml:146: error: Attribute "fontStyle" already defined with incompatible format.
c:\android\tools\..\extras\b4a_remote\com\android\support\support-compat\28.0.0\unpacked-support-compat-28.0.0\res\values\values.xml:62: Original attribute defined here.
I need a easy example for start connecting my database in cloud and do tests whit this library

Thanks
 

DonManfred

Expert
Licensed User
Firebase did changed the use of the old support Library and switched to use now AndroidX. The newest Artifacts are using AndroidX

I guess you need to use AndroidX to be able to use it. I can be wrong though (don´t know).

The error suggests a problem in the definition of fields set in AndroidX but you are using Android Support Library.

I don´t really know how to solve it as i am using AndroidX in my SDK.

Edit to add: Have you tried to run the Jetifiertool? Did it changes anything after you run it? Run jetifiertool, jetify all libraries, reload the librarys, clean project, try again.

For reference:
 
Last edited:

cas6678

Active Member
Licensed User
ok, I`ll try whit android x follow this https://www.b4x.com/android/forum/threads/androidx-sdk.107236/

Now:

1. Open Tools - B4A Sdk manager.
OK
2. Install all recommended items. This will make the switch to AndroidX. You can always go back to the previous SDK. All is
OK
3. Open Tools - Jetifier.
OK
4. Click on Jetify. It is possible that the jetifier will fail to jetify a few libraries. In most cases you can ignore it as those libraries don't need to be jetified.
OK. Just one no. jython.standalone-2.5.3.jar
5. Clean the project (Ctrl + P)
OK
6. Run your project. The compilation dialog will tell you which SDK was used:
BUT, (Android Support Library). I expected (AndroidX SDK)



🥴
 

cas6678

Active Member
Licensed User
I have followed your instructions but I must confess that I do not know what we have done....but work

B4A Versión: 9.30
Java Versión: 11
Parseando código. (0.03s)
Building folders structure. (0.04s)
Compilando código. (0.04s)
Compilado códigos de diseños. (0.00s)
Organizando librerías. (0.00s)
(AndroidX SDK)
Generando el fichero R. (0.00s)
Compilando el código Java generado. (0.18s)
Convirtiendo byte code a dex optimizado. (27.36s)
Empaquetando ficheros. (3.17s)
Copiando los recursos de librerias (0.13s)
Found 36 resource files.
Firmando ficheros de paquete (clave privada) (2.09s)
ZipAlign file. (0.07s)
Instalando archivo al dispositivo. (0.07s)
Instalando con B4A-Bridge.
Completado con éxito
and now the app close because:

Registo conectado a: samsung SM-A520F
--------- beginning of main
*** Service (starter) Create ***
Using FileProvider? true
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Setting query to get driver
** Activity (main) Resume **
*** Service (firebasemessaging) Create ***
** Service (firebasemessaging) Start **
onAuthStateChanged: com.google.firebase.auth.internal.zzl@c1a03f8
firebasemessaging_subscribetotopics (java line: 465)
java.lang.RuntimeException: Object should first be initialized (FirebaseMessaging).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
at anywheresoftware.b4a.objects.FirebaseNotificationsService$FirebaseMessageWrapper.SubscribeToTopic(FirebaseNotificationsService.java:130)
at b4a.CasTrack.firebasemessaging._subscribetotopics(firebasemessaging.java:465)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
at anywheresoftware.b4a.keywords.Common$11.run(Common.java:1179)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6944)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
*** Service (starter) Create ***
Using FileProvider? true
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Setting query to get driver
** Activity (main) Resume **
*** Service (firebasemessaging) Create ***
** Service (firebasemessaging) Start **
onAuthStateChanged: com.google.firebase.auth.internal.zzl@a887c4a
firebasemessaging_subscribetotopics (java line: 465)
java.lang.RuntimeException: Object should first be initialized (FirebaseMessaging).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
at anywheresoftware.b4a.objects.FirebaseNotificationsService$FirebaseMessageWrapper.SubscribeToTopic(FirebaseNotificationsService.java:130)
at b4a.CasTrack.firebasemessaging._subscribetotopics(firebasemessaging.java:465)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
at anywheresoftware.b4a.keywords.Common$11.run(Common.java:1179)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6944)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
*** Service (starter) Create ***
Using FileProvider? true
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Setting query to get driver
** Activity (main) Resume **
*** Service (firebasemessaging) Create ***
** Service (firebasemessaging) Start **
onAuthStateChanged: com.google.firebase.auth.internal.zzl@e1970d1
firebasemessaging_subscribetotopics (java line: 465)
java.lang.RuntimeException: Object should first be initialized (FirebaseMessaging).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
at anywheresoftware.b4a.objects.FirebaseNotificationsService$FirebaseMessageWrapper.SubscribeToTopic(FirebaseNotificationsService.java:130)
at b4a.CasTrack.firebasemessaging._subscribetotopics(firebasemessaging.java:465)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
at anywheresoftware.b4a.keywords.Common$11.run(Common.java:1179)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6944)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
*** Service (starter) Create ***
Using FileProvider? true
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Setting query to get driver
** Activity (main) Resume **
*** Service (firebasemessaging) Create ***
** Service (firebasemessaging) Start **
onAuthStateChanged: com.google.firebase.auth.internal.zzl@e1970d1
firebasemessaging_subscribetotopics (java line: 465)
java.lang.RuntimeException: Object should first be initialized (FirebaseMessaging).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
at anywheresoftware.b4a.objects.FirebaseNotificationsService$FirebaseMessageWrapper.SubscribeToTopic(FirebaseNotificationsService.java:130)
at b4a.CasTrack.firebasemessaging._subscribetotopics(firebasemessaging.java:465)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
at anywheresoftware.b4a.keywords.Common$11.run(Common.java:1179)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6944)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
*** Service (starter) Create ***
Using FileProvider? true
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Setting query to get driver
** Activity (main) Resume **
*** Service (firebasemessaging) Create ***
** Service (firebasemessaging) Start **
onAuthStateChanged: com.google.firebase.auth.internal.zzl@c507e9d
firebasemessaging_subscribetotopics (java line: 465)
java.lang.RuntimeException: Object should first be initialized (FirebaseMessaging).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
at anywheresoftware.b4a.objects.FirebaseNotificationsService$FirebaseMessageWrapper.SubscribeToTopic(FirebaseNotificationsService.java:130)
at b4a.CasTrack.firebasemessaging._subscribetotopics(firebasemessaging.java:465)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
at anywheresoftware.b4a.keywords.Common$11.run(Common.java:1179)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6944)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
I'm happy to advance, thanks.
 

DonManfred

Expert
Licensed User
and now the app close because:
Please always create a new thread for any new issue. Only this time i´ll answer here again.

Post the Versions of this libs:
1. FirebaseAuth
2. FirebaseNotification
3. FirebaseFirestore

Please post your manifestcode

For reference: this is my manifest from my Firestoretestproject

B4X:
AddManifestText(
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="26"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
'End of default text.
SetApplicationAttribute(android:theme, "@style/Theme.AppCompat")
'************ Google Play Services Base ************
CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase)
'************ Google Play Services Base (end) ************
'************ Firebase Base ************
CreateResourceFromFile(Macro, FirebaseAnalytics.Firebase)
'************ Firebase Base (end) ************
'************ Firebase Auth ************
CreateResourceFromFile(Macro, FirebaseAuth.FirebaseAuth)
'************ Firebase Auth (end) ************
CreateResourceFromFile(Macro, FirebaseNotifications.FirebaseNotifications)
v1.06 of FirebaseAuth you can find here
 
Last edited:

cas6678

Active Member
Licensed User
Please always create a new thread for any new issue. Only this time i´ll answer here again.
sorry but I think was the same topic, I´ll open new thread next time.

1. FirebaseAuth 1.06
2. FirebaseNotification 1.24
3. FirebaseFirestore 0.67

B4X:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="26"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
'End of default text.
SetApplicationAttribute(android:theme, "@style/Theme.AppCompat")
'************ Google Play Services Base ************
CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase)
'************ Google Play Services Base (end) ************

'************ Firebase Base ************
'CreateResourceFromFile(Macro, FirebaseAnalytics.Firebase)
CreateResourceFromFile(Macro, FirebaseFirestore.Firebase)
'************ Firebase Base (end) ************

'************ Firebase Auth ************
CreateResourceFromFile(Macro, FirebaseAuth.FirebaseAuth)
'************ Firebase Auth (end) ************
CreateResourceFromFile(Macro, FirebaseNotifications.FirebaseNotifications)
The manifest is from your example, no modifications

compared to your post #7 reference, saw one diference...

B4X:
'CreateResourceFromFile(Macro, FirebaseAnalytics.Firebase)
CreateResourceFromFile(Macro, FirebaseFirestore.Firebase)
I've tried both and the result is the same, don't work
 

Erel

Administrator
Staff member
Licensed User
Can you upload the generated Objects\AndroidManifest.xml file?
 

cas6678

Active Member
Licensed User
I don't understand "Your manifest does not have a Firestore-Registrar" I am using your example, the one that came to me next to the libraries: FirestoreEx

I have version 1.1 of FirebaseAnalytics, but it is not called in your example.

Maybe the example I'm using is too complicated (at least for me)

Ist there a simpler example so I can connect to my database in the cloud? to then see the power of the @DonManfred library?
 

DonManfred

Expert
Licensed User
I have version 1.1 of FirebaseAnalytics, but it is not called in your example
It is used here:
CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase)
FirebaseAnalytics 1.12 i do have.

I hope it is ok for @Erel to post it here

also used here and this is the important one
CreateResourceFromFile(Macro, FirebaseAnalytics.Firebase)
For you manifest and the missing Firestoreregistrar:

It is this part which is missing in your manifest

<meta-data
android:name="com.google.firebase.components:com.google.firebase.firestore.FirestoreRegistrar"
android:value="com.google.firebase.components.ComponentRegistrar"/>
Try again with firebaseanalytic 1.12 please.

Sorry, i named the zip wrong. It contains 1.12
 

Attachments

Last edited:

DonManfred

Expert
Licensed User
Ist there a simpler example so I can connect to my database in the cloud? to then see the power of the @DonManfred library?
the problematic part is the first setup. Once it is setup correctly we can go further.
But the setup must be done successfully first.

In fact we came further by every answer step by step.

I´m positive that FirebaseAnalytics 1.12 will bring you further now ;-)

Please be patient; i´m there to help you till it runs! :cool:
 

DonManfred

Expert
Licensed User
You do not need to add Firebaseanalytics lib to your project.
The new version must be present in your internal libraryfolder when compiling. That´s all...
 

cas6678

Active Member
Licensed User
ok, now I understand. I didn't know why you wanted something I didn't use

now FirebaseAnalytics 1.12

and now the manifest have the mssing part. Attached.

but not work,

B4X:
Registo conectado a:  samsung SM-A520F
--------- beginning of main
*** Service (starter) Create ***
Using FileProvider? true
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Setting query to get driver
** Activity (main) Resume **
*** Service (firebasemessaging) Create ***
** Service (firebasemessaging) Start **
onAuthStateChanged: com.google.firebase.auth.internal.zzl@43b6799
firebasemessaging_subscribetotopics (java line: 465)
java.lang.RuntimeException: Object should first be initialized (FirebaseMessaging).
    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
    at anywheresoftware.b4a.objects.FirebaseNotificationsService$FirebaseMessageWrapper.SubscribeToTopic(FirebaseNotificationsService.java:130)
    at b4a.CasTrack.firebasemessaging._subscribetotopics(firebasemessaging.java:465)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
    at anywheresoftware.b4a.keywords.Common$11.run(Common.java:1179)
    at android.os.Handler.handleCallback(Handler.java:789)
    at android.os.Handler.dispatchMessage(Handler.java:98)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6944)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
 

Attachments

Erel

Administrator
Staff member
Licensed User
Many things are missing from the manifest file.

Looks like you are missing this line:
B4X:
CreateResourceFromFile(Macro, FirebaseAnalytics.Firebase)
I recommend you to create a small project and upload it.
 

cas6678

Active Member
Licensed User
I recommend you to create a small project and upload it.
Yes, I prefer, but I need to have an elementary base code to start. Unless it allows me to connect to my database and write and / or read something

I only found https://www.b4x.com/android/forum/threads/chargeable-firebase-cloud-firestore.105067/ and it is with that example that I started working.

Looks like you are missing this line:
B4X:
CreateResourceFromFile(Macro, FirebaseAnalytics.Firebase)
You're right, but I did it following the instructions of the thread:

Setup Firebase Firestore:
- Replace this line from the firebaseintegrationtutorial
B4X:
CreateResourceFromFile(Macro, FirebaseAnalytics.Firebase)
with this one
B4X:
CreateResourceFromFile(Macro, FirebaseFirestore.Firebase)
now I reversed the action (manifest) and work. I have seen that the app has made changes to my database. However, if you can tell me a simple project as a basic example, I think it would be easier. Because I think it will be difficult for me to understand each of the lines of this code.

But it work :D

Thanks.
 

DonManfred

Expert
Licensed User
You're right, but I did it following the instructions of the thread
Above i posted my ACTUAL Manifest which does NOT contain this old code from the example from 2017!

I told you that this part is the interesting one. You answered with a new manifest.xml and i was expecting you DID used the code i posted.
Seems you did not :-(
But it work
This is how we could start now. . But surely in a new thread!

BTW There is NO WAY to give any congrete Example as it all depends on the Databasestructure used.

The example already shows
- how to read values
- how to create Values in a Collection.

There is not much to say more.

If you have any specific question then please start a new thread for any question you have. i´ll try to give you an answer there.

At least you now have it working ;-)
 

cas6678

Active Member
Licensed User
I told you that this part is the interesting one. You answered with a new manifest.xml and i was expecting you DID used the code i posted.
Seems you did not :-(
I did it both ways, but none worked because I had more problems, the library I didn't have.

You're right, it works. I will try to understand the code and ask in another thread.

I already have to entertain a few days



Thanks @DonManfred and @Erel
 
Top