I have two Firebase projects (one for development and one for production) and in my Assets folder I created two folders for each respectively where each contains its google-services.json file. I have already wrote directives to read specific values for the API authentication and info such as following and fill the strings accordingly:
#if DEVELOPMENT_BUILD || UNITY_EDITOR
public static string apiKey = "";
public static string authDomain = "";
public static string databaseURL = "";
public static string projectId = "";
public static string storageBucket = "";
public static string messagingSenderId = "";
#else
public static string apiKey = "";
.
. so on
#endif
But my storage reads the data directly from the instance which if I understood correctly takes the info from the JSON as it gave me an error that my bucket links do not match. I am now unsure how to make it read from specific folders in each case, I have seen solutions to change the build.gradle files by adding project flavours but the file says it is generated by Unity and will get overwritten in the next build. All other answers I have seen suggested using FirebaseApp class and call for the Create function to use my own FirebaseOptions but I am not sure when to call the method and if there is a better way.
Additional Firebase code:
private Firebase()
{
authenticationPath = new URI("https://www.googleapis.com");
databasePath = new URI(APIConfig.databaseURL);
}
storage initialization:
private FBStorage()
{
storage = Firebase.Storage.FirebaseStorage.DefaultInstance;
#if DEVELOPMENT_BUILD || UNITY_EDITOR
root_storage_ref = storage.GetReferenceFromUrl("gs://...");
#else
root_storage_ref = storage.GetReferenceFromUrl("gs://...");
#endif
}
And the Firebasestorage class is sealed.
CodePudding user response:
You're using the DefaultInstance of FirebaseStorage, which also means you're using the default instance of FirebaseApp and that reads from the configuration files.
Instead, you'll want to create your own FirebaseApp instance by calling FirebaseApp.Create(...) and pass in the correct options for the current build there.
Then you can get a FirebaseStorage instance for that configured FirebaseApp by calling FirebaseStorage.getInstance(app, "gs://yourBucketUrl").
