How to get Firebase App Distribution to work for different flavors with Kotlin DSL?
Asked Answered
C

3

8

I have an issue with Firebase Distribution configuration. Here's a part of my build.gradle in Kotlin DSL

flavorDimensions("dim")
productFlavors {
    
    create("fl1") {
        applicationIdSuffix = ".fl1"
        setDimension("dim")
        firebaseAppDistribution {
            releaseNotes = "$name"
            groups = "group-fl1"
        }
    }

    create("fl2") {
        applicationIdSuffix = ".fl2"
        setDimension("dim")
        firebaseAppDistribution {
            releaseNotes = "$name"
            groups = "group-fl2"
        }
    }

}

Flavor 1 and flavor 2 are uploaded to 2 different Firebase projects - therefore I have two google-services.json files in: src/fl1 and src/fl2.

From observation Firebase App Distribution plugin uses always the config from second firebaseDistribution block. It looks like this is not set to flavor but globally. When I invoke for example assembleFl1Debug appDistributionUploadFl1Debug the correct .apk lands in correct Firebase project, but both release notes and groups are not correct. Anyone had a similar issue?

Congius answered 26/6, 2020 at 9:51 Comment(0)
C
7

I reported this to Firebase support and just received a confirmation that it is bug, but no workaround or fix date is scheduled yet :( This concerns only build.gradle files written in Kotlin DSL.

Congius answered 4/8, 2020 at 4:21 Comment(4)
do you have a link to that bug report?Flopeared
No, Firebase Support handled this by email. I can forward you their message. Right now we are forced to use the CLI to make this work with Kotlin DSLCongius
Do you have a link to a support ticket they may have created? I'm running into a similar issue now: I want to change the artifactPath on per-variant basis, but the extension is registered per-Project instead of per-Task.Sis
@Congius how do you fixed it via CLI?Dressmaker
S
5

It's a bug, but until it's fixed, instead of firebaseAppDistribution { ... }, you may use:

configure<AppDistributionExtension> {
  ...
}

That way you can make a dynamic configuration that doesn't get overriden.

Steersman answered 14/6, 2021 at 13:27 Comment(1)
This has the very same result. Apparently, distribution configuration falls to the last configuration on Gradle KTS :|Kabyle
T
0

I encountered an issue where the Firebase App Distribution plugin wasn’t selecting the correct serviceCredentialsFile for the build type. The plugin kept using the wrong credentials file, leading to failed APK uploads.

Solution:

Using configure instead of firebaseAppDistribution {} inside the buildTypes section resolved the issue. The correct service credentials file is now selected for each build type, and the APK uploads successfully.

android {
buildTypes {
    getByName("debug") {
        configure<AppDistributionExtension> {
            appId = "your_id"
            serviceCredentialsFile = "$rootDir/staging.json"
            groupsFile = "$rootDir/tester_groups.txt"
            releaseNotesFile = "$rootDir/releasenotes.txt"
        }
        versionNameSuffix = "-DEBUG"
        signingConfig = signingConfigs.getByName("debug")
    }
    getByName("release") {
        configure<AppDistributionExtension> {
            appId = "your_id"
            serviceCredentialsFile = "$rootDir/release.json"
            groupsFile = "$rootDir/tester_groups.txt"
            releaseNotesFile = "$rootDir/releasenotes.txt"
        }
        isMinifyEnabled = true
        signingConfig = signingConfigs.getByName("release")
    }
}
productFlavors {
    create("dev") {
        dimension = "environment"
        applicationIdSuffix = ".dev.staging"
    }
    create("production") {
        dimension = "environment"
    }
}

}

Tasset answered 24/9, 2024 at 10:55 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.