Skip to content
This repository has been archived by the owner on Aug 19, 2020. It is now read-only.

Defining properties per Android product flavors override themself #1254

Closed
Syex opened this issue Nov 22, 2018 · 1 comment
Closed

Defining properties per Android product flavors override themself #1254

Syex opened this issue Nov 22, 2018 · 1 comment

Comments

@Syex
Copy link

Syex commented Nov 22, 2018

Hey,

I'm currently converting our Android build file from Groovy to Kotlin DSL, so far everything worked very well 馃憤
However, I'm struggling with defining properties per product flavor for Fabric.

This is the old (shortened) Groovy code:

productFlavors {
        dev {
            ext.betaDistributionGroupAliasesFilePath = file('fabric/distrGroup_devs.txt').path
        }

        release {
            ext.betaDistributionGroupAliasesFilePath = file('fabric/distrGroup_external.txt').path
        }
}

where the property would change depending on the variant I'm currently building.

I changed it like this:

productFlavors {
        register("dev") {
            ext["betaDistributionGroupAliasesFilePath"] = file("fabric/distrGroup_devs.txt'").path
        }

        register("release") {
            ext["betaDistributionGroupAliasesFilePath"] = file("fabric/distrGroup_external.txt").path
        }
}

Now, always the last assigned value is used, so release is always overriding dev. I also tried:

productFlavors {
        register("dev") {
            crashlytics {
                betaDistributionGroupAliasesFilePath = file("fabric/distrGroup_devs.txt'").path
            }
        }

        register("release") {
            crashlytics {
                betaDistributionGroupAliasesFilePath = file("fabric/distrGroup_external.txt").path
            }
        }
}

or extra["betaDistributionGroupAliasesFilePath"] but I always get the same output, that the last assigned value is used.

It seems in Groovy ext was per flavor while with Kotlin DSL ext is set per project, so it overrides the value.

Am I misunderstanding something? Is it a bug?

Kotlin 1.3.10
Gradle 4.10

@eskatos
Copy link
Member

eskatos commented Apr 24, 2019

This is because the Android type for product flavor doesn't declare that it is ExtensionAware. The closer ExtensionAware type in that scope is the Project, hence the properties going to the project.

As a workaround you can do:

productFlavors {
        register("dev") {
            require(this is ExtensionAware)
            extra["betaDistributionGroupAliasesFilePath"] = file("fabric/distrGroup_devs.txt'").path
        }

        register("release") {
            require(this is ExtensionAware)
            extra["betaDistributionGroupAliasesFilePath"] = file("fabric/distrGroup_external.txt").path
        }
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants