title: Is there a way to configure separate serviceCredentialsFile for each Android build variant with Firebase App Distribution?
body: <p>We have several Firebase projects which share the same code base via build types and flavors. We aim to use the app distribution via Gradle and authenticate using service account credentials.</p>
  <p>In the <a href="https://firebase.google.com/docs/app-distribution/android/distribute-gradle" rel="nofollow noreferrer">docs</a>, it is shown that <code>firebaseAppDistribution</code> block can be used to configure the parameters and the service credential file path is one of them. Since each variant is a Firebase project and each project has its own service credentials, as far as I can understand we need to point to separate service credential file paths in the Gradle configuration.</p>
  <p>I've tried to update the file path with a gradle task depending on the variant but couldn't make it work. The current build file looks like:</p>
  <pre><code>...
  
  apply plugin: 'com.google.firebase.appdistribution'
  
  class StringExtension {
    String value
  
    StringExtension(String value) {
      this.value = value
    }
  
    public void setValue(String value) {
      this.value = value
    }
  
    public String getValue() {
      return value
    }
  }
  
  android {
  
    ...
  
    productFlavors.whenObjectAdded {
      flavor -&gt; flavor.extensions.create(&quot;service_key_prefix&quot;, StringExtension, '')
    }
  
    productFlavors {
  
      flavor1 {
        ...
        service_key_prefix.value = &quot;flavor1&quot;
      }
  
      flavor2 {
        ...
        service_key_prefix.value = &quot;flavor2&quot;
      }
    }
  
    buildTypes {
  
      debug {
        firebaseAppDistribution {
          releaseNotesFile = file(&quot;internal_release_notes.txt&quot;).path
          groupsFile = file(&quot;group_aliases_debug_fb.txt&quot;).path
        }
      }
  
      release {
        firebaseAppDistribution {
          releaseNotesFile = file(&quot;release_notes.txt&quot;).path
          groupsFile = file(&quot;group_aliases_prod_fb.txt&quot;).path
        }
      }
    }
  }
  
  ...
  
  android.applicationVariants.all { variant -&gt;
  
    task(&quot;firebaseCredentials${variant.name.capitalize()}&quot;, overwrite: true) {
      variant.productFlavors.each { flavor -&gt;
  
        doLast {
          firebaseAppDistribution {
  
            def serviceKeyFile = file(
                &quot;../${flavor.service_key_prefix.value}-${variant.buildType.name}-service-key.json&quot;)
            if (serviceKeyFile != null) {
              serviceCredentialsFile = serviceKeyFile.path
            }
          }
        }
      }
    }
  }
  
  android.applicationVariants.all { variant -&gt;
    def distTask = tasks.named(&quot;appDistributionUpload${variant.name.capitalize()}&quot;)
    def configTask = tasks.named(&quot;firebaseCredentials${variant.name.capitalize()}&quot;)
    distTask.configure {
      dependsOn(configTask)
    }
  }
  
  apply plugin: 'com.google.gms.google-services'
  </code></pre>
  <p>The tasks seem to run correctly but I guess the file path is not updated because it still gives the following error when I run <code>appDistributionUpload</code> :</p>
  <blockquote>
  <p>Could not find credentials. To authenticate, you have a few options:</p>
  <ol>
  <li><p>Set the <code>serviceCredentialsFile</code> property in your gradle plugin</p>
  </li>
  <li><p>Set a refresh token with the FIREBASE_TOKEN environment variable</p>
  </li>
  <li><p>Log in with the Firebase CLI</p>
  </li>
  <li><p>Set service credentials with the GOOGLE_APPLICATION_CREDENTIALS environment variable</p>
  </li>
  </ol>
  </blockquote>
  <p>Any ideas on how to achieve such distribution configuration?</p>