How to set up QtFirebase for inclusion and to utilize Firebase modules in your project.
For a working and up-to-date example that can be compiled in Qt Creator please follow the Quick start section found in the QtFirebaseExample README. (The example app links back here in some places - but not all). It's strongly adviced to see how the example app is setup in-order to avoid any missing entries.
Clone the QtFirebase project
Clone into the "extensions" or "vendor" folder or into another folder of your choice. Here we use the QtFirebaseExample structure.
cd /path/to/projects/QtFirebaseExample/extensions
git clone [email protected]:Larpon/QtFirebase.git
Download and extract the latest version of Google's Firebase C++ SDK.
cd /path/to/download
curl --location https://firebase.google.com/download/cpp --output "firebase_cpp_sdk.zip"
unzip firebase_cpp_sdk.zip -d /path/to/sdk
rm firebase_cpp_sdk.zip
If you have multiple projects using QtFirebase it's a space-saver to have the Firebase C++ SDK (~832 MB) in one place.
You can either symlink the Firebase C++ SDK to the default search path OR set the QTFIREBASE_SDK_PATH
variable to the absolute path of the SDK in your project's .pro
file for the app build.
ln -s /path/to/sdk/firebase_cpp_sdk /path/to/projects/QtFirebase/firebase_cpp_sdk
Open your project with Qt Creator.
Navigate to the .pro
(sub)project file in the Project pane.
QtFirebaseExample
|_...
|_App
|_App.pro
Locate the lines:
# NOTE QTFIREBASE_SDK_PATH can be symlinked to match $$PWD/firebase_cpp_sdk
...
Change it to match your path(s) - or leave it to use default $$PWD/firebase_cpp_sdk
QTFIREBASE_SDK_PATH = /path/to/sdk/firebase_cpp_sdk
(Example)
In your project's .pro
(sub)project file (before including qtfirebase.pri
) - choose the modules to include:
QTFIREBASE_CONFIG += analytics messaging admob remote_config
(Example)
Finally include qtfirebase.pri
in your project's .pro
file.
include(/path/to/QtFirebase/qtfirebase.pri)
(Example)
As Firebase C++ SDK does not support desktop apps - no further setup is needed.
QtFirebase provides stub implementations ("empty shells" or "placeholders") for desktop builds and no firebase libraries are linked to the application.
When building QtFirebase for Android targets you need the following extra steps to get everything running.
Make sure you have Google Services
apk installed and updated on the target device. Firebase won't work without it.
Furthermore the project needs gradle
and the Android NDK (r10d+) to build on Android.
Make sure you set your Android build SDK
to API level 23 in your Qt Creator project settings.
Firebase still work on devices from API level 14 according to this source - but it apparently need to be build with a higher target API.
Enable gradle in your Qt Creator build options.
For a fully working build.gradle
file please see this example
Depending on what modules you intend to use from Firebase you should edit the dependencies in your project's gradle.build
to match your preferences. (Example)
Edit paths to match your setup in /path/to/your/Qt Creator/project/android/gradle.properties
. (Example)
Edit paths to match your setup in /path/to/your/Qt Creator/project/android/local.properties
.(Example)
On some Qt Creator setups the above *.properties
files are auto-generated by the build tool and overriden on each build.
If you're using qmake
you can use ANDROID_PACKAGE_SOURCE_DIR to include your own overrides of these files.
Include google-services.json
downloaded from the Firebase console. (Example)
Note Using Messaging is only possible with Qt 5.9+ due to gradle dependencies that require recent versions of the Android SDK/NDK. Upgrading these will also "force" you to upgrade Qt (because of some bugs in Qt Creator) in order for it all to work
To use Messaging on Android there is some additional setup.
You'll need to have recent versions of the Android SDK/NDK toolchain.
Android SDK Build-Tools >= 25.0.0
Android NDK >= r11c
gradle >= 2.3.3
like here
Add Messaging specific services to your AndroidManifest.xml file. (Example).
Run the included script $$PWD/src/ios/download_firebase_ios.sh
to download the iOS SDK automatically
... or manually download Firebase.zip from https://firebase.google.com/download/ios and extract it to $$PWD/src/ios/
.
PRO TIP
If you are upgrading QtFirebase to a newer version - you'll probably want to download the Firebase iOS Frameworks again in order to get the latest matching versions
To use Messaging on iOS there is some additional setup.
- Go to https://developer.apple.com/account
- Click on the right side of the page on "Certificates, Identifiers & Profiles"
- Click on the right side of the page on "Keys, All"
- Click the "+" icon at the top right of the page
- Find Service Enable "APNs" and enter Key Description Name "Your keyname". At the bottom of the page click "Continue", then click "Confirm" and download the key.
- Go to https://console.firebase.google.com/
- Navigate to Overview (Gear icon) -> Project settings -> Cloud Messaging (Tab)
- Upload your APNs info
PRO TIP
The following changes can be made permanent with each build from Qt Creator by using various build tool (qmake) tricks. It's currently beyond the scope of this documentation to tell you how though.
In your app's Capabilities
tab.
Remember to enable Push Notifications
Remember to set Remote notifications
in Background Modes
For a fully working Info.plist
please see this example
Include GoogleService-Info.plist
downloaded from the Firebase console. (Example)
If you build for Android or iOS you should see output like the following in the "General Messages" tab of Qt Creator
Project MESSAGE: QtFirebase: configuring build for supported Firebase target platform...
Project MESSAGE: No QTFIREBASE_SDK_PATH path sat. Using default (firebase_cpp_sdk) /path/to/projects/QtFirebaseExample/extensions/QtFirebase/firebase_cpp_sdk
Project MESSAGE: QtFirebase Android base
Project MESSAGE: QtFirebase including Analytics
Project MESSAGE: QtFirebase including AdMob
...
Project MESSAGE: This project is using private headers and will therefore be tied to this specific Qt module build version.
Project MESSAGE: Running this project against other versions of the Qt modules may crash at any arbitrary point.
Project MESSAGE: This is not a bug, but a result of using Qt internals. You have been warned!
If you are building for Desktop target the output should be something like this:
Project MESSAGE: QtFirebase: configuring build for non-supported Firebase target platform...