firebase / firebase-android-sdk

Firebase Android SDK
https://firebase.google.com
Apache License 2.0
2.25k stars 571 forks source link

FirebaseAppDistribution block does not respect variant-specific configuration #4241

Closed mformetal closed 1 year ago

mformetal commented 1 year ago

[REQUIRED] Step 2: Describe your environment

[REQUIRED] Step 3: Describe the problem

Steps to reproduce:

According to the distribution documentation, I should be able to set the artifactPath on a per-application-variant basis.

Relevant Code:

Root build.gradle.kts

buildscript {
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath("com.android.tools.build:gradle:7.2.2")
        classpath("com.google.gms:google-services:4.3.3")
        classpath("com.google.firebase:firebase-appdistribution-gradle:3.0.3")
    }
}

App build.gradle.kts

plugins {
    id("com.android.application")
    id("com.google.gms.google-services")
    id("com.google.firebase.appdistribution")
}

android {
    flavorDimensions += listOf("default")

    productFlavors {
        create("automation") {
            firebaseAppDistribution {
                artifactType="AAB"
                artifactPath="AUTOMATION PATH"
            }
        }

        create("dev") {
            firebaseAppDistribution {
                artifactType="AAB"
                artifactPath="DEV PATH"
            }
        }
    }
}

Running ./gradlew app:appDistributionUploadAutomationDebug should attempt (and fail) to upload using "AUTOMATION PATH". Running ./gradlew app:appDistributionUploadDevDebug should attempt (and fail) to upload using "DEV PATH".

However, both tasks end up using "DEV PATH". It seems like the last call to firebaseAppDistribution { .... } overwrites any previous ones, and this makes sense because AppDistributionExtension seems to be registered on a per-Project and not a per-Task basis.

This is currently blocking me from integrating with the Firebase Gradle Plugin, and I'd much rather not use the CLI for this.

google-oss-bot commented 1 year ago

I found a few problems with this issue:

mformetal commented 1 year ago

Configuring the AppDistributionExtension using the productFlavors/buildTypes API as below seems to be working for me now:

project.extensions.configure<ApplicationExtension> {

        productFlavors.configureEach {
            configure<AppDistributionExtension> {

            }
        }
    }

Closing.