cutelyst / firebase-qt

Qt Wrapper for Firebase C++ API
MIT License
19 stars 5 forks source link

ASSERT failure in FirebaseQtApp: "App::Create" #6

Open shokarta opened 6 days ago

shokarta commented 6 days ago

Hello Daniel,

for the CMake, i managed (perhaps I even slighly simplified) to work it out. However if I use your approach in readme for build.gradle then build give me: E firebase: Failed to load default options when attempting to populate missing fields E firebase: App ID, API key, and Project ID must be specified in App options. F Filmtoro: ASSERT failure in FirebaseQtApp: "App::Create", file C:/Qt/Projects/extralibs/firebase-qt/src/firebaseqtapp.cpp, line 91 F libc : Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 18692 (qtMainLoopThrea), pid 18663 (mtoro.appMobile)

on the other hand, if I use your OLD approach and use build.gradle as per your video two years ago, all works fine

dantti commented 6 days ago

yes, you need to set App ID, API key, and Project ID before initialize, it can also load this from JSON but I didn't test that

shokarta commented 6 days ago

how and where do I set this?

dantti commented 6 days ago
m_firebaseApp->setAppId(u"..."_s);
m_firebaseApp->setApiKey(u"..."_s);
m_firebaseApp->setProjectId(u"..."_s);
m_firebaseApp->initialize();
shokarta commented 6 days ago

so I managed to build, however it brings couple issues/questions:

W FirebaseApp: Default FirebaseApp failed to initialize because no default options were found. This usually means that com.google.gms:google-services was not applied to your gradle project.

I FirebaseInitProvider: FirebaseApp initialization unsuccessful

I FA : App measurement initialized, version: 104007 I FA : To enable debug logging run: adb shell setprop log.tag.FA VERBOSE I FA : To enable faster debug mode event logging run: I FA : adb shell setprop debug.firebase.analytics.app com.xxx.appMobile E FA : Missing google_app_id. Firebase Analytics disabled. See https://goo.gl/NAOOOI E FA : Uploading is not possible. App measurement disabled

as you say m_firebaseApp->setAppId(u"..."_s);

I firebase: Firebase Cloud Messaging API Initialized W mtoro.appMobile: Attempt to remove non-JNI local reference D firebase.messaging: : OnTokenReceived 0x70ca7747e4f8 flbcGSAHW6k3n4C2c3Ndp1:APA91bEzUmNgKbUne-0WgRTViRGbbhUK6leF2FerjKcG_-ZWc3sPKI-KI6fUh-PmNq5kQRv2QfD1851bgXMzkLJhqSJNWiKPfd2VuIPsQUnbGGgP0jfPQfx7AzwR5sPa_Y4gpT70CC3X

dantti commented 6 days ago

hmm I don't have classpath 'com.google.gms:google-services:4.4.2' I also get unsuccessful initialization but I think this might be due Firebase auto initialization that expects to find the json file, maybe disabling the auto init or adding the file fixes it here.

dantti commented 6 days ago

ok I also have... W FirebaseApp: Default FirebaseApp failed to initialize because no default options were found. This usually means that com.google.gms:google-services was not applied to your gradle project.

shokarta commented 6 days ago

i fixed I FirebaseInitProvider: FirebaseApp initialization unsuccessful by adding apply plugin: 'com.google.gms.google-services' to build.gradle

dantti commented 6 days ago

yup, both are listed to be added by Firebase docs, but trying to be minimal I removed since I still got the token. I'm trying today making sure the app gets the notification, then next week will look into adding the frameworks to iOS

shokarta commented 6 days ago

yes, currently receiving notification while app is running results in: W mtoro.appMobile: Accessing hidden method Landroid/os/WorkSource;->add(I)Z (unsupported,test-api, reflection, allowed) W mtoro.appMobile: Accessing hidden method Landroid/os/WorkSource;->add(ILjava/lang/String;)Z (unsupported,test-api, reflection, allowed) W mtoro.appMobile: Accessing hidden method Landroid/os/WorkSource;->get(I)I (unsupported, reflection, allowed) W mtoro.appMobile: Accessing hidden method Landroid/os/WorkSource;->getName(I)Ljava/lang/String; (unsupported, reflection, allowed)

also when app is not running, nothing happens and notification is not received... at least on emulator (before with QMake it worked on emu just fine)... i will try real device shortly but I dont expect any difference

dantti commented 6 days ago
m_firebaseApp->setAppId(u"..."_s);
m_firebaseApp->setApiKey(u"..."_s);
m_firebaseApp->setProjectId(u"..."_s);
m_firebaseApp->initialize();

So these 3 lines are not needed if you have your google-services.json in /android dir QT_ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android" as your cmake target property.

Next the issue with notifications not arriving when the app is closed, is because of android unused app permission, if you disable that, then it will work, hopefuly on release more this is not an issue, but needs testing if androidmanifest.xml isn't missing something, now for the OnMessages I have not clue on what's wrong...

dantti commented 6 days ago

Found the issue! :)

Sadly it's more manual work but we now have Android working... if you look at the AndroidManifest.xml at firebase-sdk-cpp/messaging you will see what's needed, sadly our build system doesn't automate that...

        <service android:name="com.google.firebase.messaging.cpp.ListenerService"
                 android:exported="true" >
          <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
          </intent-filter>
        </service>

        <service android:name="com.google.firebase.messaging.cpp.RegistrationIntentService"
                 android:permission="android.permission.BIND_JOB_SERVICE"
                 android:exported="true" >
        </service>
    </application>

    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

    <permission
        android:name="${applicationId}.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />
    <uses-permission
        android:name="${applicationId}.permission.C2D_MESSAGE" />

</manifest>
shokarta commented 5 days ago
m_firebaseApp->setAppId(u"..."_s);
m_firebaseApp->setApiKey(u"..."_s);
m_firebaseApp->setProjectId(u"..."_s);
m_firebaseApp->initialize();

So these 3 lines are not needed if you have your google-services.json in /android dir QT_ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android" as your cmake target property.

Next the issue with notifications not arriving when the app is closed, is because of android unused app permission, if you disable that, then it will work, hopefuly on release more this is not an issue, but needs testing if androidmanifest.xml isn't missing something, now for the OnMessages I have not clue on what's wrong...

this I can not agree... with "old" (I reference old as your video two years ago) build.gradle these i didnt have to set, however with new I have to, and google-services.json is indedd in my project/android/ and cmake properly says: QT_ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android" and to be extra sure i have android/google-services.json inside RESOURCES in qt_add_qml_module()

EDIT: tedted again when removed those three lines and worked, so it got me wondering why it didnt worked before, and after futher testing i found out that commented out apply plugin: 'com.google.gms.google-services' in build.gradle causes this

shokarta commented 5 days ago

Found the issue! :)

Sadly it's more manual work but we now have Android working... if you look at the AndroidManifest.xml at firebase-sdk-cpp/messaging you will see what's needed, sadly our build system doesn't automate that...

        <service android:name="com.google.firebase.messaging.cpp.ListenerService"
                 android:exported="true" >
          <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
          </intent-filter>
        </service>

        <service android:name="com.google.firebase.messaging.cpp.RegistrationIntentService"
                 android:permission="android.permission.BIND_JOB_SERVICE"
                 android:exported="true" >
        </service>
    </application>

    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

    <permission
        android:name="${applicationId}.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />
    <uses-permission
        android:name="${applicationId}.permission.C2D_MESSAGE" />

</manifest>

yes, you are the best... so as of now it properly receives and displays notificaitons when app is NOT running, however while app is running, it gives me: W mtoro.appMobile: Accessing hidden method Landroid/os/WorkSource;->add(I)Z (unsupported,test-api, reflection, allowed) W mtoro.appMobile: Accessing hidden method Landroid/os/WorkSource;->add(ILjava/lang/String;)Z (unsupported,test-api, reflection, allowed) W mtoro.appMobile: Accessing hidden method Landroid/os/WorkSource;->get(I)I (unsupported, reflection, allowed) W mtoro.appMobile: Accessing hidden method Landroid/os/WorkSource;->getName(I)Ljava/lang/String; (unsupported, reflection, allowed) D firebase.messaging: : OnMessage "933253518766" "0:1728631339212511%d7f335bed7f335be" 0 D Filmtoro: Got a Push Notification when the app is running: QMap() so how do I properly access and read data out of received message?

dantti commented 5 days ago

Well all we get is on the firebase::messaging::Message, I think in the past it had less info, not sure, the data part is IMO what is most important since you can send any number of pairs like openPage=Foo.qml or showMsg="Your order is ready", still I'm thinking on changing this API to pass firebase::messaging::Message object instead of copying only it's data field. And yes, ignore the Warnings, they seem to be "normal"

dantti commented 5 days ago

and to be extra sure i have android/google-services.json inside RESOURCES in qt_add_qml_module()

I don't add them to RESOURCES and it just works

shokarta commented 5 days ago

Well all we get is on the firebase::messaging::Message, I think in the past it had less info, not sure, the data part is IMO what is most important since you can send any number of pairs like openPage=Foo.qml or showMsg="Your order is ready", still I'm thinking on changing this API to pass firebase::messaging::Message object instead of copying only it's data field. And yes, ignore the Warnings, they seem to be "normal"

great, got it, thank you :). Probably best would be to pass all the object and let the end user to work with it however he likes... if you ask me i would like also the other data (ie the notification title, text, name, img, ...), not only pairs

dantti commented 5 days ago

done

shokarta commented 5 days ago

how do I change: void messageReceived(const QMap<QString, QString> &data) ? as Im trying anything, it gives me bunch of errors :(

dantti commented 5 days ago

it's a new signal signature, it now gives you a copy of firebase::messaging::Message

dantti commented 5 days ago

you must ofc include the headers from firebase-cpp-sdk

shokarta commented 5 days ago

yes, thats what i figured... what I am asking is how to translate all message to either string so later I can serialize as JSON, or send it as JSON document right away

dantti commented 5 days ago

well you need to do it manually like what I was doing for dada

QHash<QString, QString> data;
    auto it = message.data.begin();
    while (it != message.data.end()) {
        qDebug() << "OnMessage data:" << it->first.c_str() << it->second.c_str();
        data.insert(QString::fromStdString(it->first), QString::fromStdString(it->second));
        ++it;
    }

the good thing is that the threading issue is covered by Qt delayed calls

shokarta commented 3 days ago

everything works perfectly! cant wait to iOS :) only one thing, little unrelated to mobile... when set set(MSVC_RUNTIME_MODE MD) then i have quite a lot linking issues when MSVC... however when set to MT then i have huuuge amount of linking issues... did you ever try to compile for Windows? EDIT: linking issues comes when #include <firebase/messaging.h>, and looks like: image EDIT2: this seems to have a direct influce by setting version of cmake_minimum_required, as lower I set, more errors it brings... however since 3.15 and above it gives always same errors (as per screenshot)