Search code examples
androidfirebasebuildproduction-environmentfirebase-storage

Firebase storage for dev and prod


How can I separate my firebase prod and dev storage with buildtypes or flavors in android ?

I already know how to separate the database but this doesn't apply to storage.
The problem is that the code to instantiate the storage doesn't rely on google-services.json but on a fixed url :
FirebaseStorage.getInstance().getReferenceFromUrl("gs://dev-app.appspot.com");


Solution

    1. Set in build.gradle (module level)
     buildTypes {
            debug {
                buildConfigField "String", "BASE_URL", '"gs://dev-app.appspot.com"'
            }
            release {
                buildConfigField "String", "BASE_URL", '"gs://prod-app.appspot.com"'
            }
    
    1. In your code use

      FirebaseStorage.getInstance().getReferenceFromUrl(BuildConfig.BASE_URL);