Power up your C++ games with our Firebase C++ SDKs which provide a C++ interface on top of Firebase SDKs.
Access Firebase entirely from your C++ code, without having to write any platform-native code. The Firebase SDK also translates many language-specific idioms used by Firebase into an interface more familiar to C++ developers.
Find out more information about powering up your games with Firebase at our Firebase games page.
Already added Firebase to your C++ project? Make sure that you're using the latest version of the Firebase C++ SDK.
Prerequisites
Install your preferred editor or IDE, such as Android Studio, IntelliJ, or VS Code.
Obtain the Android SDK.
Make sure that your project meets these requirements:
Targets API level 21 (Lollipop) or higher
Uses Gradle and is configured with CMake
Set up a physical device or use an emulator to run your app.
Sign into Firebase using your Google account.
Step 2: Create a Firebase project
Before you can add Firebase to your C++ project, you need to create a Firebase project to connect to your C++ project. Visit Understand Firebase Projects to learn more about Firebase projects.
Create a Firebase project
-
In the Firebase console, click Add project.
-
To add Firebase resources to an existing Google Cloud project, enter its project name or select it from the dropdown menu.
-
To create a new project, enter the desired project name. You can also optionally edit the project ID displayed below the project name.
-
-
If prompted, review and accept the Firebase terms.
-
Click Continue.
-
(Optional) Set up Google Analytics for your project, which enables you to have an optimal experience using any of the following Firebase products:
Either select an existing Google Analytics account or to create a new account.
If you create a new account, select your Analytics reporting location, then accept the data sharing settings and Google Analytics terms for your project.
-
Click Create project (or Add Firebase, if you're using an existing Google Cloud project).
Firebase automatically provisions resources for your Firebase project. When the process completes, you'll be taken to the overview page for your Firebase project in the Firebase console.
Step 3: Register your app with Firebase
To use Firebase in your Android app, you need to register your app with your Firebase project. Registering your app is often called "adding" your app to your project.
Go to the Firebase console.
In the center of the project overview page, click the Android icon (
) or Add app to launch the setup workflow.Enter your app's package name in the Android package name field.
What's a package name, and where do you find it?
A package name uniquely identifies your app on the device and in the Google Play Store.
A package name is often referred to as an application ID.
Find your app's package name in your module (app-level) Gradle file, usually
app/build.gradle
(example package name:com.yourcompany.yourproject
).Be aware that the package name value is case-sensitive, and it cannot be changed for this Firebase Android app after it's registered with your Firebase project.
(Optional) Enter other app information: App nickname and Debug signing certificate SHA-1.
How are the App nickname and the Debug signing certificate SHA-1 used within Firebase?
App nickname: An internal, convenience identifier that is only visible to you in the Firebase console
Debug signing certificate SHA-1: A SHA-1 hash is required by Firebase Authentication (when using Google Sign In or phone number sign in) and Firebase Dynamic Links.
Click Register app.
Step 4: Add the Firebase configuration file
Click Download google-services.json to obtain your Firebase Android config file.
What do you need to know about this config file?
The Firebase config file contains unique, but non-secret identifiers for your project. To learn more about this config file, visit Understand Firebase Projects.
You can download your Firebase config file again at any time.
Make sure the config file name is not appended with additional characters, like
(2)
.
Open your C++ project in an IDE, then add your config file to your project:
Gradle builds — Add your config file to the same directory as your top-level
build.gradle
file.Other build systems — See Custom build systems below to generate Android String Resources.
(Gradle builds only) To enable Firebase services in your C++ project, add the google-services plugin to your top-level
build.gradle
file.Add rules to include the Google Services Gradle plugin. Check that you have Google’s Maven repository, as well.
buildscript { repositories { // Check that you have the following line (if not, add it): google() // Google's Maven repository } dependencies { // ... // Add the following lines: classpath 'com.google.gms:google-services:4.4.2' // Google Services plugin implementation 'com.google.android.gms:18.5.0' } } allprojects { // ... repositories { // Check that you have the following line (if not, add it): google() // Google's Maven repository // ... } }
Apply the Google Services Gradle plugin:
apply plugin: 'com.android.application' // Add the following line: apply plugin: 'com.google.gms.google-services' // Google Services plugin android { // ... }
You're done with set up tasks in the Firebase console. Continue to Add Firebase C++ SDKs below.
Step 5: Add Firebase C++ SDKs
The steps in this section are an example of how to add supported Firebase products to your Firebase C++ project.
Download the Firebase C++ SDK, then unzip the SDK somewhere convenient.
The Firebase C++ SDK is not platform-specific, but it does contain platform-specific libraries.
In your project's
gradle.properties
file, specify the location of the unzipped SDK:systemProp.firebase_cpp_sdk.dir=
full-path-to-SDK To your project's
settings.gradle
file, add the following content:def firebase_cpp_sdk_dir = System.getProperty('firebase_cpp_sdk.dir') gradle.ext.firebase_cpp_sdk_dir = "$firebase_cpp_sdk_dir" includeBuild "$firebase_cpp_sdk_dir"
To your module (app-level) Gradle file (usually
app/build.gradle
), add the following content.
Include the library dependencies for the Firebase products that you want to use in your app.android.defaultConfig.externalNativeBuild.cmake { arguments "-DFIREBASE_CPP_SDK_DIR=$gradle.firebase_cpp_sdk_dir" } # Add the dependencies for the Firebase products you want to use in your app # For example, to use Analytics, Firebase Authentication, and Firebase Realtime Database apply from: "$gradle.firebase_cpp_sdk_dir/Android/firebase_dependencies.gradle" firebaseCpp.dependencies { analytics auth database }
android.defaultConfig.externalNativeBuild.cmake { arguments "-DFIREBASE_CPP_SDK_DIR=$gradle.firebase_cpp_sdk_dir" } # Add the dependencies for the Firebase products you want to use in your app # For example, to use Firebase Authentication and Firebase Realtime Database apply from: "$gradle.firebase_cpp_sdk_dir/Android/firebase_dependencies.gradle" firebaseCpp.dependencies { auth database }
To your project's
CMakeLists.txt
file, add the following content.
Include the libraries for the Firebase products that you want to use in your app.# Add Firebase libraries to the target using the function from the SDK. add_subdirectory(${FIREBASE_CPP_SDK_DIR} bin/ EXCLUDE_FROM_ALL) # The Firebase C++ library `firebase_app` is required, # and it must always be listed last. # Add the Firebase SDKs for the products you want to use in your app # For example, to use Analytics, Firebase Authentication, and Firebase Realtime Database set(firebase_libs firebase_analytics firebase_auth firebase_database firebase_app ) target_link_libraries(${target_name} "${firebase_libs}")
# Add Firebase libraries to the target using the function from the SDK. add_subdirectory(${FIREBASE_CPP_SDK_DIR} bin/ EXCLUDE_FROM_ALL) # The Firebase C++ library `firebase_app` is required, # and it must always be listed last. # Add the Firebase SDKs for the products you want to use in your app # For example, to use Firebase Authentication and Firebase Realtime Database set(firebase_libs firebase_auth firebase_database firebase_app ) target_link_libraries(${target_name} "${firebase_libs}")
Sync your app to ensure that all dependencies have the necessary versions.
If you added Analytics, run your app to send verification to Firebase that you've successfully integrated Firebase. Otherwise, you can skip the verification step.
Your device logs will display the Firebase verification that initialization is complete. If you ran your app on an emulator that has network access, the Firebase console notifies you that your app connection is complete.
You’re all set! Your C++ app is registered and configured to use Firebase services.
(optional alternative) Use ndk-build to add SDKs
- Make sure that you have the Android NDK v10d or later.
Download the Firebase C++ SDK, then unzip the SDK somewhere convenient.
The Firebase C++ SDK is not platform-specific, but it does contain platform-specific libraries.
-
Open your
local.properties
file, then:- Set the
firebase_cpp_sdk.dir
variable to the location of the unzipped Firebase C++ SDK. - Set the
ndk.dir
variable to the location of the Android NDK.
- Set the
-
To use Gradle's built-in ndkBuild support, create a
jni
directory within your top-level directory, then create the followingmake
files.-
Create a
jni/Application.mk
file with the following:APP_PLATFORM:=android-14 NDK_TOOLCHAIN_VERSION=clang APP_ABI:=armeabi-v7a arm64-v8a x86 x86_64 APP_STL:=c++_static APP_MODULES:=android_main APP_CPPFLAGS+=-std=c++11
-
Create a
jni/Android.mk
file with the following content.Include the libraries of the Firebase product that you want to use. For example, to use Analytics:
LOCAL_PATH:=$(call my-dir)/.. ifeq ($(FIREBASE_CPP_SDK_DIR),) $(error FIREBASE_CPP_SDK_DIR must specify the Firebase package location.) endif # With Firebase libraries for the selected build configuration (ABI + STL) STL:=$(firstword $(subst _, ,$(APP_STL))) FIREBASE_LIBRARY_PATH:=\ $(FIREBASE_CPP_SDK_DIR)/libs/android/$(TARGET_ARCH_ABI)/$(STL) # The Firebase C++ library `libfirebase_app.a` is required for all Firebase products. include $(CLEAR_VARS) LOCAL_MODULE:=firebase_app LOCAL_SRC_FILES:=$(FIREBASE_LIBRARY_PATH)/libfirebase_app.a LOCAL_EXPORT_C_INCLUDES:=$(FIREBASE_CPP_SDK_DIR)/include include $(PREBUILT_STATIC_LIBRARY) # Include the Firebase library for Google Analytics. # Note: Duplicate this block for each Firebase product that you want # to use in your app, and replace variable values as appropriate. include $(CLEAR_VARS) LOCAL_MODULE:=firebase_analytics LOCAL_SRC_FILES:=$(FIREBASE_LIBRARY_PATH)/libfirebase_analytics.a LOCAL_EXPORT_C_INCLUDES:=$(FIREBASE_CPP_SDK_DIR)/include include $(PREBUILT_STATIC_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE:=android_main # Reference your project's C++ source files LOCAL_SRC_FILES:=\ $(LOCAL_PATH)/src/common_main.cc \ $(LOCAL_PATH)/src/android/android_main.cc LOCAL_STATIC_LIBRARIES:=\ firebase_analytics \ firebase_app # this library reference must always be listed last LOCAL_WHOLE_STATIC_LIBRARIES:=\ android_native_app_glue LOCAL_C_INCLUDES:=\ $(NDK_ROOT)/sources/android/native_app_glue \ $(LOCAL_PATH)/src LOCAL_LDLIBS:=-llog -landroid -latomic LOCAL_ARM_MODE:=arm LOCAL_LDFLAGS:=-Wl,-z,defs -Wl,--no-undefined include $(BUILD_SHARED_LIBRARY) $(call import-add-path,$(NDK_ROOT)/sources/android) $(call import-module,android/native_app_glue)
-
-
Open your top-level
build.gradle
file, then complete the following steps:-
Add the dependencies for the Firebase products that you want to use. For example, to use Analytics:
dependencies { implementation 'com.google.firebase:firebase-analytics:21.0.0' }
-
Add the following lines so that your project uses Gradle's built-in ndk-build support to include the Firebase libraries specified in your
jni/Android.mk
file.android { // ... defaultConfig { // ... externalNativeBuild.ndkBuild { arguments "FIREBASE_CPP_SDK_DIR=${project.ext.firebase_cpp_sdk_dir}", "NDK_APPLICTION_MK=jni/Application.mk", sprintf("APP_PLATFORM=android-%d", android.defaultConfig.minSdkVersion.mApiLevel) } } }
-
Available libraries for Android (using ndk-build)
Each Firebase product has different dependencies. Be sure to add all the listed dependencies for the Firebase products that you want to use.
Add Firebase C++ libraries (like libfirebase_app.a
) by
including them in the top-level jni/Android.mk
file. For other
dependencies (like com.google.firebase:firebase-auth
), add them to your top-level
build.gradle
file.
Firebase product | Libraries and Dependencies |
---|---|
AdMob |
libfirebase_admob.a (required) libfirebase_analytics.a (required) libfirebase_app.a implementation 'com.google.firebase:firebase-ads:19.8.0' (required) implementation 'com.google.firebase:firebase-analytics:21.0.0'
|
Analytics |
libfirebase_analytics.a (required) libfirebase_app.a implementation 'com.google.firebase:firebase-analytics:21.0.0'
|
App Check |
libfirebase_app_check.a (required) libfirebase_app.a implementation 'com.google.firebase:firebase-appcheck:17.0.0'
|
Authentication |
libfirebase_auth.a (required) libfirebase_app.a implementation 'com.google.firebase:firebase-auth:21.0.5'
|
Cloud Firestore |
libfirebase_firestore.a (required) libfirebase_app.a implementation 'com.google.firebase:firebase-firestore:24.1.2'
|
Cloud Functions |
libfirebase_functions.a (required) libfirebase_app.a implementation 'com.google.firebase:firebase-functions:20.1.0'
|
Cloud Messaging |
libfirebase_messaging.a (recommended) libfirebase_analytics.a (required) libfirebase_app.a implementation 'com.google.firebase:firebase-messaging:23.0.5' (recommended) implementation 'com.google.firebase:firebase-analytics:21.0.0'
|
Cloud Storage |
libfirebase_storage.a (required) libfirebase_app.a implementation 'com.google.firebase:firebase-storage:20.0.1'
|
Dynamic Links |
ibfirebase_dynamic_links.a (recommended) libfirebase_analytics.a (required) libfirebase_app.a implementation 'com.google.firebase:firebase-dynamic-links:21.0.1' (recommended) implementation 'com.google.firebase:firebase-analytics:21.0.0'
|
Realtime Database |
libfirebase_database.a (required) libfirebase_app.a implementation 'com.google.firebase:firebase-database:20.0.5'
|
Remote Config |
libfirebase_remote_config.a (recommended) libfirebase_analytics.a (required) libfirebase_app.a implementation 'com.google.firebase:firebase-config:21.1.0' (recommended) implementation 'com.google.firebase:firebase-analytics:21.0.0'
|
Available libraries
Learn more about the C++ Firebase libraries in the reference documentation and in our open-source SDK release on GitHub.
Available libraries for Android (using CMake)
Note that C++ libraries for Apple platforms are listed on the Apple platforms (iOS+) version of this setup page.
Firebase product | Library references ( firebaseCpp.dependencies for build.gradle file) |
Library references ( firebase_libs for CMakeLists.txt file) |
---|---|---|
AdMob | admob |
firebase_admob (required) firebase_analytics (required) firebase_app
|
Analytics | analytics |
firebase_analytics (required) firebase_app
|
App Check | appCheck |
firebase_app_check (required) firebase_app
|
Authentication | auth |
firebase_auth (required) firebase_app
|
Cloud Firestore | firestore |
firebase_firestore (required) firebase_auth (required) firebase_app
|
Cloud Functions | functions |
firebase_functions (required) firebase_app
|
Cloud Messaging | messaging |
firebase_messaging (recommended) firebase_analytics (required) firebase_app
|
Cloud Storage | storage |
firebase_storage (required) firebase_app
|
Dynamic Links | dynamicLinks |
firebase_dynamic_links (recommended) firebase_analytics (required) firebase_app
|
Realtime Database | database |
firebase_database (required) firebase_app
|
Remote Config | remoteConfig |
firebase_remote_config (recommended) firebase_analytics (required) firebase_app
|
Additional information for mobile setup
Get NDK crash reports
Firebase Crashlytics supports crash reporting for apps using Android native libraries. To learn more, see Get Android NDK crash reports.
Custom build systems
Firebase provides the script generate_xml_from_google_services_json.py
to
convert google-services.json
to .xml
resources that you can include in
your project. This script applies the same transformation that the Google Play
services Gradle plugin performs when building Android applications.
If you don't build using Gradle (for example, you use ndk-build, makefiles, Visual Studio, etc.), you can use this script to automate the generation of Android String Resources.
ProGuard
Many Android build systems use ProGuard for builds in Release mode to shrink application sizes and protect Java source code.
If you use ProGuard, you'll need to add the files in libs/android/*.pro
corresponding to the Firebase C++ libraries that you're using in your ProGuard
configuration.
For example, with Gradle, if you're using Google Analytics,
your build.gradle
file would look like:
android { // ... buildTypes { release { minifyEnabled true proguardFile getDefaultProguardFile('your-project-proguard-config.txt') proguardFile file(project.ext.your_local_firebase_sdk_dir + "/libs/android/app.pro") proguardFile file(project.ext.your_local_firebase_sdk_dir + "/libs/android/analytics.pro") // ... and so on, for each Firebase C++ library that you're using } } }
Google Play services requirement
Most Firebase C++ libraries require
Google Play services
to be on the client's Android device. If a Firebase C++ library returns
kInitResultFailedMissingDependency
on initialization, it means Google Play services is not available on the
client device (meaning that it needs to be updated, reactivated, permissions
fixed, etc.). The Firebase library cannot be used until the situation on the
client device is corrected.
You can find out why Google Play services is unavailable on the client device
(and try to fix it) by using the functions in
google_play_services/availability.h
.
The following table lists whether Google Play services is required on a client device for each supported Firebase product.
Firebase C++ Library | Google Play services required on client device? |
---|---|
AdMob | Not required (usually) |
Analytics | Not required |
Authentication | Required |
Cloud Firestore | Required |
Cloud Functions | Required |
Cloud Messaging | Required |
Cloud Storage | Required |
Dynamic Links | Required |
Realtime Database | Required |
Remote Config | Required |
AdMob and Google Play services
Most versions of the Google Mobile Ads SDK for Android can work properly
without Google Play services on the client device. However, if you're using
the com.google.android.gms:play-services-ads-lite
dependency, instead of the
standard com.google.firebase:firebase-ads
dependency listed above, Google Play services is
required.
AdMob initialization will only return kInitResultFailedMissingDependency
when both the following are true:
- Google Play services is unavailable on the client device.
- You're using
com.google.android.gms:play-services-ads-lite
.
Set up a desktop workflow (beta)
When you're creating a game, it's often much easier to test your game on desktop platforms first, then deploy and test on mobile devices later in development. To support this workflow, we provide a subset of the Firebase C++ SDKs which can run on Windows, macOS, Linux, and from within the C++ editor.
For desktop workflows, you need to complete the following:
- Configure your C++ project for CMake.
- Create a Firebase project
- Register your app (iOS or Android) with Firebase
- Add a mobile-platform Firebase configuration file
Create a desktop version of the Firebase configuration file:
If you added the Android
google-services.json
file — When you run your app, Firebase locates this mobile file, then automatically generates a desktop Firebase config file (google-services-desktop.json
).If you added the iOS
GoogleService-Info.plist
file — Before you run your app, you need to convert this mobile file to a desktop Firebase config file. To convert the file, run the following command from the same directory as yourGoogleService-Info.plist
file:generate_xml_from_google_services_json.py --plist -i GoogleService-Info.plist
This desktop config file contains the C++ project ID that you entered in the Firebase console setup workflow. Visit Understand Firebase Projects to learn more about config files.
Add Firebase SDKs to your C++ project.
The steps below serve as an example of how to add any supported Firebase product to your C++ project. In this example, we walk through adding Firebase Authentication and Firebase Realtime Database.
Set your
FIREBASE_CPP_SDK_DIR
environment variable to the location of the unzipped Firebase C++ SDK.To your project's
CMakeLists.txt
file, add the following content, including the libraries for the Firebase products that you want to use. For example, to use Firebase Authentication and Firebase Realtime Database:# Add Firebase libraries to the target using the function from the SDK. add_subdirectory(${FIREBASE_CPP_SDK_DIR} bin/ EXCLUDE_FROM_ALL) # The Firebase C++ library `firebase_app` is required, # and it must always be listed last. # Add the Firebase SDKs for the products you want to use in your app # For example, to use Firebase Authentication and Firebase Realtime Database set(firebase_libs firebase_auth firebase_database firebase_app) target_link_libraries(${target_name} "${firebase_libs}")
Run your C++ app.
Available libraries (desktop)
The Firebase C++ SDK includes desktop workflow support for a subset of features, enabling certain parts of Firebase to be used in standalone desktop builds on Windows, macOS, and Linux.
Firebase product | Library references (using CMake) |
---|---|
App Check |
firebase_app_check (required) firebase_app
|
Authentication |
firebase_auth (required) firebase_app
|
Cloud Firestore |
firebase_firestore firebase_auth firebase_app
|
Cloud Functions |
firebase_functions (required) firebase_app
|
Cloud Storage |
firebase_storage (required) firebase_app
|
Realtime Database |
firebase_database (required) firebase_app
|
Remote Config |
firebase_remote_config (required) firebase_app
|
Firebase provides the remaining desktop libraries as stub (non-functional) implementations for convenience when building for Windows, macOS, and Linux. Therefore, you don't need to conditionally compile code to target the desktop.
Realtime Database desktop
The Realtime Database SDK for desktop uses REST to access your database, so you must
declare the indexes that
you use with Query::OrderByChild()
on desktop or your listeners will fail.
Additional information for desktop setup
Windows libraries
For Windows, library versions are provided based on the following:
- Build platform: 32-bit (x86) vs 64-bit (x64) mode
- Windows runtime environment: Multithreaded / MT vs Multithreaded DLL /MD
- Target: Release vs Debug
Note that the following libraries were tested using Visual Studio 2015 and 2017.
When building C++ desktop apps on Windows, link the following Windows SDK libraries to your project. Consult your compiler documentation for more information.
Firebase C++ Library | Windows SDK library dependencies |
---|---|
App Check | advapi32, ws2_32, crypt32 |
Authentication | advapi32, ws2_32, crypt32 |
Cloud Firestore | advapi32, ws2_32, crypt32, rpcrt4, ole32, shell32 |
Cloud Functions | advapi32, ws2_32, crypt32, rpcrt4, ole32 |
Cloud Storage | advapi32, ws2_32, crypt32 |
Realtime Database | advapi32, ws2_32, crypt32, iphlpapi, psapi, userenv |
Remote Config | advapi32, ws2_32, crypt32, rpcrt4, ole32 |
macOS libraries
For macOS (Darwin), library versions are provided for the 64-bit (x86_64) platform. Frameworks are also provided for your convenience.
Note that the macOS libraries have been tested using Xcode 13.3.1.
When building C++ desktop apps on macOS, link the following to your project:
pthread
system libraryCoreFoundation
macOS system frameworkFoundation
macOS system frameworkSecurity
macOS system frameworkGSS
macOS system frameworkKerberos
macOS system frameworkSystemConfiguration
macOS system framework
Consult your compiler documentation for more information.
Linux libraries
For Linux, library versions are provided for 32-bit (i386) and 64-bit (x86_64) platforms.
Note that the Linux libraries were tested using GCC 4.8.0, GCC 7.2.0, and Clang 5.0 on Ubuntu.
When building C++ desktop apps on Linux, link the pthread
system library to
your project. Consult your compiler documentation for more information. If
you're building with GCC 5 or later, define -D_GLIBCXX_USE_CXX11_ABI=0
.
Next steps
Explore sample Firebase apps.
Explore the open source SDK in GitHub.
Prepare to launch your app:
- Set up budget alerts for your project in the Google Cloud console.
- Monitor the Usage and billing dashboard in the Firebase console to get an overall picture of your project's usage across multiple Firebase services.
- Review the Firebase launch checklist.