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).
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 git@github.com: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 "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.
Enable gradle in your Qt Creator build options.
Edit lines in your project's gradle.build
to match your dependencies / modules. (Example)
Edit paths to match your setup in /path/to/QtFirebase/src/android/gradle.properties
. (Example)
Edit paths to match your setup in /path/to/QtFirebase/src/android/local.properties
.(Example)
Include google-services.json
downloaded from the Firebase console
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
or download Firebase.zip from https://firebase.google.com/download/ios and extract it to $$PWD/src/ios/
.
(Example)
Include GoogleService-Info.plist
downloaded from the Firebase console. (Example)
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
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...