Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
shokarta opened this issue Oct 10, 2024 · 44 comments
Open

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

shokarta opened this issue Oct 10, 2024 · 44 comments

Comments

@shokarta
Copy link

shokarta commented Oct 10, 2024

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
Copy link
Member

dantti commented Oct 10, 2024

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
Copy link
Author

how and where do I set this?

@dantti
Copy link
Member

dantti commented Oct 10, 2024

m_firebaseApp->setAppId(u"..."_s);
m_firebaseApp->setApiKey(u"..."_s);
m_firebaseApp->setProjectId(u"..."_s);
m_firebaseApp->initialize();

@shokarta
Copy link
Author

shokarta commented Oct 10, 2024

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.

  • so afterall i should realy place classpath 'com.google.gms:google-services:4.4.2' to dependencies {} in build.gradle?
  • after adding this to build.gradle, it does not fix the following: I FirebaseInitProvider: FirebaseApp initialization unsuccessful

I FirebaseInitProvider: FirebaseApp initialization unsuccessful

  • can I know the reason? its true it took me a while to figure out difference between app id, project id, project number etc... so i still might be entering wrong credentials... AppID, AppKey, ProjectId, can you point wihch fields its from google-services.json?

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

  • this says me that firebase was initiated, but probably not linked to my firebase project?

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

  • the only possible entry is only setAppId("..."), other convention does not work here

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

  • however after all these errors, it gives me some token ID

@dantti
Copy link
Member

dantti commented Oct 10, 2024

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
Copy link
Member

dantti commented Oct 10, 2024

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
Copy link
Author

shokarta commented Oct 10, 2024

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

@dantti
Copy link
Member

dantti commented Oct 10, 2024

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
Copy link
Author

shokarta commented Oct 10, 2024

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

  • so not even on real device... so i believe its missing something in build.gradle, something like implementation in dependencies {}, perhaps?

@dantti
Copy link
Member

dantti commented Oct 10, 2024

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
Copy link
Member

dantti commented Oct 10, 2024

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
Copy link
Author

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
Copy link
Author

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
Copy link
Member

dantti commented Oct 11, 2024

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
Copy link
Member

dantti commented Oct 11, 2024

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
Copy link
Author

shokarta commented Oct 11, 2024

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
Copy link
Member

dantti commented Oct 11, 2024

done

@shokarta
Copy link
Author

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

@dantti
Copy link
Member

dantti commented Oct 11, 2024

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

@dantti
Copy link
Member

dantti commented Oct 11, 2024

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

@shokarta
Copy link
Author

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
Copy link
Member

dantti commented Oct 11, 2024

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
Copy link
Author

shokarta commented Oct 13, 2024

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)

@dantti
Copy link
Member

dantti commented Oct 17, 2024

I think I need features from cmake 3.28, and no never tried to build for Windows, on iOS I pushed some changes that should almost be enough, but I get now link issues due usage of Swift, no idea how to fix that yet.
Maybe
https://github.com/apple/swift-cmake-examples/blob/main/3_bidirectional_cxx_interop/cmake/modules/AddSwift.cmake
and
https://github.com/apple/swift-cmake-examples/blob/main/3_bidirectional_cxx_interop/cmake/modules/InitializeSwift.cmake
can do some help...

@shokarta
Copy link
Author

where do you define FIREBASE_IOS_SDK_DIR, and which source it is actually?
also GoogleService-Info.plist is not considered anywhere?

@shokarta
Copy link
Author

Daniel, I think this is much closer then we think :)
To me (but i always rewrite your CMake to my needs) builds just fine, however FCM does not configure... log is:
FCM: Loading UIApplication FIRFCM category
QML debugging is enabled. Only use this in a safe environment.
11.3.0 - [FirebaseCore][I-COR000005] No app has been configured yet.
Setting up iOS 10 message delegate.
11.3.0 - [FirebaseCore][I-COR000005] No app has been configured yet.
11.3.0 - [FirebaseCore][I-COR000003] The default Firebase app has not yet been configured. Add FirebaseApp.configure() to your application initialization. This can be done in in the App Delegate's application(_:didFinishLaunchingWithOptions:) (or the @main struct's initializer in SwiftUI). Read more: https://firebase.google.com/docs/ios/setup#initialize_firebase_in_your_app`
11.3.0 - [FirebaseCore][I-COR000005] No app has been configured yet.
11.3.0 - [FirebaseMessaging][I-FCM001000] FIRMessaging Remote Notifications proxy enabled, will swizzle remote notification receiver handlers. If you'd prefer to manually integrate Firebase Messaging, add "FirebaseAppDelegateProxyEnabled" to your Info.plist, and set it to NO. Follow the instructions at: https://firebase.google.com/docs/cloud-messaging/ios/client#method_swizzling_in_firebase_messaging to ensure proper integration.
FCM: Initialize Firebase Messaging
FCM: Using FCM senderID 933253518766
FCM: Retrieve registration token
11.3.0 - [FirebaseMessaging][I-FCM002022] Declining request for FCM Token since no APNS Token specified
ERROR: Failed to register for remote notifications. // this might not be related to firebase, i think this is linked to my process of requesting authorizations so app can receive notifications
ERROR: Failed to register for remote notifications. // this might not be related to firebase, i think this is linked to my process of requesting authorizations so app can receive notifications
11.3.0 - [FirebaseMessaging][I-FCM012002] Error in application:didFailToRegisterForRemoteNotificationsWithError: chybí platný řetězec oprávnění (aps-environment) pro aplikaci // something like missing valid string of authorizations (aps-environment) for application

so I think that basicaly it only doesnt load GoogleService-Info.plist

@dantti
Copy link
Member

dantti commented Oct 17, 2024

well you know, the .plist file is the same as the json one, you can manually setKey..(), which XCode version are you using? I updated to the latests yesterday, I think I was on 14 and now on 16, but now instead of Swift link issues (which maybe will happen later) I get:
clang++: error: unknown argument: '-no_warn_duplicate_libraries'

About how I use it I have it as a submodule so to include firebase-qt I do:

if(ANDROID OR IOS)
    if (ANDROID)
        set(FIREBASE_CPP_SDK_DIR "/home/daniel/code/firebase_cpp-sdk-12/firebase_cpp_sdk_12.2.0/")
    else()
        set(FIREBASE_CPP_SDK_DIR "/Users/daniel/code/firebase_cpp_sdk-12.2.0/")
        set(FIREBASE_IOS_SDK_DIR "/Users/daniel/code/firebase/Firebase-11.2.0")
    endif()

    add_subdirectory(3rdparty/firebase-qt EXCLUDE_FROM_ALL)
    include_directories(3rdparty/firebase-qt/src)
    include_directories("${FIREBASE_CPP_SDK_DIR}/include")
endif()

@dantti
Copy link
Member

dantti commented Oct 17, 2024

Plus to link it's just this as I'm trying to have the CPP and iOS SDK linked at FirebaseQt stage

if(ANDROID OR IOS)
    target_compile_definitions(${app_target} PRIVATE FIREBASE=1)
    target_link_libraries(${app_target}
        PRIVATE
            FirebaseQt::App
            FirebaseQt::Messaging
    )
endif()

@shokarta
Copy link
Author

hello dantti, hows your progress?
as far as I set manualy (because it still does not see my GoogleServices-Info.plist even when checked in xcode project that file was copied) setAppId, setApiKey, setProjectId then I got to the error when firebase tells me t can not register as misisng APNs authentication key, so this I need to generate from apple developer console and upload to firebase console (project settings, cloud messaging) first - will do tomorrow as now have no access.
Also, from what I was able to gather info online (not proven), that we also need to put to the FirebaseAppDelegateProxyEnabled key (false) to Plist.info in order to receive notification when app is closed (or opened? docu for this is terrible, not exactly sure what this does).
and also is needed to put to the project xcode background modes (in order to receive notificaiton when app is running, only is in background): https://medium.com/@itsuki.enjoy/detail-guide-to-ios-push-notification-with-google-firebase-cloud-messaging-fcm-50944e0c2c45
but I guess this you can set from cmake so its automated?

@dantti
Copy link
Member

dantti commented Oct 22, 2024

Didn't have time to investigate further, and yes Firebase on iOS is just a wrapper for their APN think, which you import on Firebase console so you don't need to write different code for 2 OSes.
Which XCode version are you using?

@shokarta
Copy link
Author

shokarta commented Oct 22, 2024

ok, so this is how it goes.

  1. I have generated APN authkey in apple dev console and added to firebase console.
  2. used following to make sure GoogleService-Info.plist is copied and used:
    image
  3. added following to Info.plist to make sure Remote Notifications Background Modes in co for Notifications are lowed:
    image
  4. manualy added Push Notificaitons capability, dont know how to automate from CMake, this does not work
  5. on build had some linking issues:
    image
    fixed by point 2.2 from https://blog.cpming.top/p/react-native-0-62-undefined-symbol (2.1 i didnt need to because ios.swift comes from you, also 2.3 i already had yes, 2.4 i didnt need to even try)... for the first build it worked, however after clean and rebuild i had another issue:
    image
    which i fixed by replacing "$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)" by "$(SDKROOT)/usr/lib/swift" (however i have notifec if this "$(SDKROOT)/usr/lib/swift" is above "$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)" then it also works
    on first build i had xcode poping up window "codesign wants to access key in your keychain" and upon entering appleid password, it just re-popped up again... after googling people have problem that it realy asks 50times LOL... so I decided go to keychain manager and approve xcode to automaticaly use it without asking me...
    then all builds fine (the keychain thing did popup again, but only like 5times, then all next builds are without asking)... (if you know the way how to mautomatrd points 4 and 5 would be awesome!)

after build in the console I see:
image

  • which bring me to question i cant figure out, not even google up... how do I specify APNS token?

i guess this would take you also to same point, so able to build and compile without linking errors... if you want, I cant give you minimal example via email

XCode 16.0
MacOS 15.0.1
Firebase C++ SDK 12.2.0
Firebase iOS SDK 11.3.0
build via nevest QtCreator with 6.8.0

@dantti
Copy link
Member

dantti commented Oct 22, 2024

So, on iOS it used to work like this, you get a Firebase token like in Android, Google knows that this token is from iOS, so when your server calls Firebase to send this notification it will then relay the message to Apple servers, which is why you need to import your APN keys in Firebase web console.

@shokarta
Copy link
Author

yes, I also figured as it makes sence :)
I also use your FirebaseQt.h which you made in the initial video years ago... there you basicaly only use firebase->initialize();... shouldt whis (for iOS) be enhanced also for configure()?

@dantti
Copy link
Member

dantti commented Oct 22, 2024

I think so, since I didn't pass the compilation issues yet, you can make a PR if that's the only part left, I might try to automate what you said tho, but ofc might just fail and require these manual steps :(

@shokarta
Copy link
Author

it wont let me create PR :(
this could help: firebase/flutterfire#11946 somehow this issue is desribed...
dantti, what else I can do to help here?

@dantti
Copy link
Member

dantti commented Oct 22, 2024

dunno, does it work for you after setting the APN and getting a new token?

@shokarta
Copy link
Author

im stuck at the last screenshot i sent.. i dont know how to set the APN and THEN request new token :(

@dantti
Copy link
Member

dantti commented Oct 22, 2024

Project Overview -> Project Settings -> Cloud Messaging -> Apple app configuration -> there you have the upload button to upload the APN stuff

@dantti
Copy link
Member

dantti commented Oct 22, 2024

image

@shokarta
Copy link
Author

ok sorry for misunderstanding, this i of course did, and issue is the very same... so I assume in your FirebaseQt.h we must set somehow to configure() before initialize()? or even directly connect initialize() to call after APNs success?

@dantti
Copy link
Member

dantti commented Oct 22, 2024

I don't see this configure in their API

@dantti
Copy link
Member

dantti commented Oct 22, 2024

seems to do what I do https://github.com/firebase/quickstart-cpp/blob/main/messaging/testapp/src/common_main.cc
maybe the plist is not found?

@shokarta
Copy link
Author

shokarta commented Oct 22, 2024

EDIT: after setting -FIRDebugEnabled it produced extra info which might help to see whats happening:
image

@shokarta
Copy link
Author

dantti, done :D received token on iOS and received notification when app is off (will test during app is on and backgrounded later).
What i have found is that since firebase ios sdk 10.4 onwards they have changed this "debug" message to error when APNs token is not accessible... so I trtied 10.3 however could not build because of some exception issue of some lib. then i tried back to newest 11.4 which gave me again same exeption error, so 11.3 which i was working with since beginning works fine.
What i have found, that you need to put FirebaseAppDelegateProxyEnabled with TRUE value to you Info.plist (not to GoogleService-Info.plist as i was trying all yesterday :( ).
Documentation says, to put this variable with false if you want to provide ASPn token yourself (and not automaticaly by firebase) = nothing else it says !!! and all forums people says it this value is default TRUE, so I would of expect this variable you dont even need to set... however as soon as i put it to my Info.plist with TRUE, all worked fine :D.
I will send you short email describing everyhting i made in order to make it work, so you can put it here to docs and have this topic finished...
Thank you for all the support, you are the best!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants