Configure multiple projects Stay organized with collections Save and categorize content based on your preferences.
This page describes how to use more than one Firebase project in your app.
Many apps need only a single Firebase project and the default set updescribed in theGet Started guides. Examples of when it can be usefulto use multiple Firebase projects include:
- Setting up your development environment to use different Firebase projectsbased on build type or target.
- Accessing the content from multiple Firebase projects in your app.
Support different environments
One common use case is to support separate Firebase projects for your developmentand production environments.
The Web and Admin SDKs are configured by directlypassing values to their initialization functions. For these SDK, you can use aruntime check to select development or production configuration variables.
Android and Apple platforms (and their Unity and C++ wrappers) normally loadconfiguration from a configuration file:GoogleService-Info.plist on Appleplatform andgoogle-services.json on Android. These files are read into anoptions object (FIROption orFirebaseOptions) that is referenced by theFirebase application object (FIRApp orFirebaseApp).
For these platforms, switching between environments is usually implemented as abuild time decision, through use of different configuration files for eachenvironment.
Support multiple environments in your Apple application
By default,FirebaseApp.configure() will load theGoogleService-Info.plist filebundled with the application. If your development and production environmentsare configured as separate targets in Xcode, you can:
- Download both
GoogleService-Info.plistfiles - Store the two files in different directories
- Add both to your Xcode project
- Associate the different files with the different targets using the TargetMembership panel:

If the builds are part of a single target, the best option is to give bothconfiguration files unique names (e.g.GoogleService-Info-Free.plist andGoogleService-Info-Paid.plist). Then choose at runtime which plist to load.This is shown in the following example:
//Loadanamedfile.guardletfilePath=Bundle.main.path(forResource:"MyGoogleService",ofType:"plist"),letfileOptions=FirebaseOptions(contentsOfFile:filePath)else{fatalError("Couldn't load config file.")}FirebaseApp.configure(options:fileOptions)
Support multiple environments in your Android application
In Android, thegoogle-services.json file is processed into Android stringresources by the Google Services gradle plugin. You can seewhich resources are created in the Google Services Plugin documentation onProcessing the JSON file.
You can have multiplegoogle-services.json files for differentbuild variantsby placinggoogle-services.json files in dedicated directories named for eachvariant under the app module root. For example, if you have "development" and"release" build flavors, your configuration could be organized like this:
app/ google-services.json src/development/google-services.json src/release/google-services.json ...To learn more, see the Google Services Plugin documentation onAdding the JSON file.
These resources are then loaded by theFirebaseInitProvider,which runs before your application code and initializes Firebase APIs usingthose values.
Because this provider is just reading resources with known names, anotheroption is to add the string resources directly to your app instead of usingthe Google Services gradle plugin. You can do this by:
- Removing the
google-servicesplugin from your rootbuild.gradle - Deleting the
google-services.jsonfrom your project - Adding the string resources directly
- Deleting
apply plugin: 'com.google.gms.google-services'from your appbuild.gradle
Use multiple projects in your application
Sometimes you need to access different projects using the same APIs - forexample, accessing multiple database instances. In most cases there is a centralFirebase application object that manages the configuration for all the FirebaseAPIs. This object is initialized as part of your normal setup. However, when youwant to access multiple projects from a single application, you’ll need adistinct Firebase application object to reference each one individually. It’sup to you to initialize these other instances.
In both cases, you need to first create a Firebase options object to hold theconfiguration data for the Firebase application. Full documentationfor the options can be found in the API reference documentation for thefollowing classes:
- Swift:
FirebaseOptions(googleAppID:gcmSenderID:) - Android:
FirebaseOptions.Builder - Web:
initializeApp() - C++:
firebase::App::Create - Unity:
FirebaseApp.Create - Node.js:
initializeApp - Java:
FirebaseOptions.Builder
The use of these classes to support multiple projects in an application is shownin the following examples:
Swift
// Configure with manual options. Note that projectID and apiKey, though not// required by the initializer, are mandatory.letsecondaryOptions=FirebaseOptions(googleAppID:"1:27992087142:ios:2a4732a34787067a",gcmSenderID:"27992087142")secondaryOptions.apiKey="AIzaSyBicqfAZPvMgC7NZkjayUEsrepxuXzZDsk"secondaryOptions.projectID="projectid-12345"// The other options are not mandatory, but may be required// for specific Firebase products.secondaryOptions.bundleID="com.google.firebase.devrel.FiroptionConfiguration"secondaryOptions.clientID="27992087142-ola6qe637ulk8780vl8mo5vogegkm23n.apps.googleusercontent.com"secondaryOptions.databaseURL="https://myproject.firebaseio.com"secondaryOptions.storageBucket="myproject.appspot.com"secondaryOptions.deepLinkURLScheme="myapp://"secondaryOptions.storageBucket="projectid-12345.appspot.com"secondaryOptions.appGroupID=nil
Kotlin
// Manually configure Firebase Options. The following fields are REQUIRED:// - Project ID// - App ID// - API Keyvaloptions=FirebaseOptions.Builder().setProjectId("my-firebase-project").setApplicationId("1:27992087142:android:ce3b6448250083d1").setApiKey("AIzaSyADUe90ULnQDuGShD9W23RDP0xmeDc6Mvw")// .setDatabaseUrl(...)// .setStorageBucket(...).build()
Java
// Manually configure Firebase Options. The following fields are REQUIRED:// - Project ID// - App ID// - API KeyFirebaseOptionsoptions=newFirebaseOptions.Builder().setProjectId("my-firebase-project").setApplicationId("1:27992087142:android:ce3b6448250083d1").setApiKey("AIzaSyADUe90ULnQDuGShD9W23RDP0xmeDc6Mvw")// setDatabaseURL(...)// setStorageBucket(...).build();
Web
// The following fields are REQUIRED:// - Project ID// - App ID// - API KeyconstsecondaryAppConfig={projectId:"<PROJECT_ID>",appId:"<APP_ID>",apiKey:"<API_KEY>",// databaseURL: "...",// storageBucket: "...",};
C++
firebase::AppOptionssecondary_app_options;// API key, app ID, and project ID are always required.secondary_app_options.set_api_key("<API_KEY>");secondary_app_options.set_app_id("<GOOGLE_APP_ID>");secondary_app_options.set_project_id("<PROJECT_ID>");// The following options are specific to individual Firebase products// and may not always be required.secondary_app_options.set_database_url("<DATABASE_URL>");secondary_app_options.set_messaging_sender_id("<SENDER_ID>");secondary_app_options.set_storage_bucket("<STORAGE_BUCKET>");Unity
Firebase.AppOptionssecondaryAppOptions=newFirebase.AppOptions{ApiKey="<API_KEY>",AppId="<GOOGLE_APP_ID>",ProjectId="<PROJECT_ID>"};Node.js
constsecondaryServiceAccount=require('./path/to/serviceAccountKey.json');// All required options are specified by the service account,// add service-specific configuration like databaseURL as needed.constsecondaryAppConfig={credential:cert(secondaryServiceAccount),// databaseURL: 'https://<DATABASE_NAME>.firebaseio.com'};
Java
FileInputStreamserviceAccount=newFileInputStream("path/to/serviceAccountKey.json");FirebaseOptionssecondaryAppConfig=newFirebaseOptions.Builder().setCredential(FirebaseCredentials.fromCertificate(serviceAccount)).setDatabaseUrl("https://<DATABASE_NAME>.firebaseio.com/").build();After you have initialized this options object, you can use it to configure anadditional Firebase application instance. Note that in all the examples shownbelow we use the stringsecondary. This name is used to retrieve theapplication instance, and to distinguish it from other instances, including thedefault instance (named[DEFAULT]). You should pick a string appropriate tothe intended use of the other Firebase project.
The following snippets demonstrate connecting to an alternativeRealtime Database(the APIs for other Firebase features follow the same pattern).
Swift
// Configure an alternative FIRApp.FirebaseApp.configure(name:"secondary",options:secondaryOptions)// Retrieve a previous created named app.guardletsecondary=FirebaseApp.app(name:"secondary")else{fatalError("Could not retrieve secondary app")}// Retrieve a Real Time Database client configured against a specific app.letsecondaryDb=Database.database(app:secondary)
Kotlin
// Initialize secondary FirebaseApp.Firebase.initialize(context=this,options,"secondary")// Retrieve secondary FirebaseApp.valsecondary=Firebase.app("secondary")// Get the database for the other app.valsecondaryDatabase=Firebase.database(secondary)
Java
// Initialize with secondary appFirebaseApp.initializeApp(this/* Context */,options,"secondary");// Retrieve secondary FirebaseAppFirebaseAppsecondary=FirebaseApp.getInstance("secondary");
Web
// Initialize another app with a different configconstsecondaryApp=firebase.initializeApp(secondaryAppConfig,"secondary");// Access services, such as the Realtime Database// secondaryApp.database();
C++
firebase::App*secondary_app=firebase::App::Create(secondary_app_options,"Secondary");firebase::database::Database*secondary_database=firebase::database::Database::GetInstance(secondary_app);Unity
varsecondaryApp=Firebase.FirebaseApp.Create(secondaryAppOptions,"Secondary"));varsecondaryDatabase=Firebase.Database.FirebaseDatabase.getInstance(secondaryApp);Node.js
// Initialize another app with a different configconstsecondary=initializeApp(secondaryAppConfig,'secondary');// Access services, such as the Realtime Database// const secondaryDatabase = secondary.database();
Java
// Initialize another app with a different configFirebaseAppsecondaryApp=FirebaseApp.initializeApp(secondaryAppConfig,"secondary");// Retrieve the database.FirebaseDatabasesecondaryDatabase=FirebaseDatabase.getInstance(secondaryApp);Ensure reliable reporting forAnalytics
Google Analytics collects events very early in the app start up flow, insome occasions before the primary Firebase app instance has been configured. Inthese cases, Firebase refers to the Android resource orGoogleService-Info.plist on Apple platforms to look up the correct Google appID to store events. For this reason, we recommend using the defaultconfiguration methods wherever possible.
If runtime configuration is required, please note the following caveats:
- If you're usingAdMob and request ads at startup as recommended, you maymiss some Analytics data to related to mobile ads when not using the resourcebased configuration approach.
- Only ever supply a single Google app ID in each distributed variant of your app.For example, if you ship version 1 of your app with a certain
GOOGLE_APP_IDinthe configuration then upload version 2 with a different ID, it may causeanalytics data to be dropped. - On Apple platforms, do not add GoogleService-Info.plist to your project ifyou are supplying different configuration at run time, as this can result in anapparent change of
GOOGLE_APP_IDand result in lost Analytics.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2026-02-18 UTC.