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.
In the docs, it is shown that firebaseAppDistribution
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.
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:
...
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 -> flavor.extensions.create("service_key_prefix", StringExtension, '')
}
productFlavors {
flavor1 {
...
service_key_prefix.value = "flavor1"
}
flavor2 {
...
service_key_prefix.value = "flavor2"
}
}
buildTypes {
debug {
firebaseAppDistribution {
releaseNotesFile = file("internal_release_notes.txt").path
groupsFile = file("group_aliases_debug_fb.txt").path
}
}
release {
firebaseAppDistribution {
releaseNotesFile = file("release_notes.txt").path
groupsFile = file("group_aliases_prod_fb.txt").path
}
}
}
}
...
android.applicationVariants.all { variant ->
task("firebaseCredentials${variant.name.capitalize()}", overwrite: true) {
variant.productFlavors.each { flavor ->
doLast {
firebaseAppDistribution {
def serviceKeyFile = file(
"../${flavor.service_key_prefix.value}-${variant.buildType.name}-service-key.json")
if (serviceKeyFile != null) {
serviceCredentialsFile = serviceKeyFile.path
}
}
}
}
}
}
android.applicationVariants.all { variant ->
def distTask = tasks.named("appDistributionUpload${variant.name.capitalize()}")
def configTask = tasks.named("firebaseCredentials${variant.name.capitalize()}")
distTask.configure {
dependsOn(configTask)
}
}
apply plugin: 'com.google.gms.google-services'
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 appDistributionUpload
:
Could not find credentials. To authenticate, you have a few options:
Set the
serviceCredentialsFile
property in your gradle pluginSet a refresh token with the FIREBASE_TOKEN environment variable
Log in with the Firebase CLI
Set service credentials with the GOOGLE_APPLICATION_CREDENTIALS environment variable
Any ideas on how to achieve such distribution configuration?
com.google.firebase.appdistribution.buildtools.reloc.com.google.api.client.googleapis.auth.oauth2.DefaultCredentialProvider
I'm usingcom.google.firebase:firebase-appdistribution-gradle:1.4.1
Hmm this package does not contain the buildtools package. I wonder where they are... – Attack