Robert Jeppesen
Robert Jeppesen

Reputation: 7877

Setting appDistributionProperties.apkPath from Kotlin dsl

I've tried converting our Android app to use the Kotlin DSL for gradle and I can't get AppDistribution to work in my CI build. This is the error I got:

App Distribution found more than 1 output file for this variant. Please contact [email protected] for help using APK splits with App Distribution.

This is what was working in groovy:

    applicationVariants.all { variant ->
        variant.outputs.each { output ->
                tasks.findAll {
                    it.name.startsWith(
                            "appDistributionUpload${variant.name.capitalize()}")
                }.each {
                    it.doFirst {
                        it.appDistributionProperties.apkPath = output.outputFile.absolutePath
                    }
                }
        }
    }

I can't find a way to set appDistributionProperties.apkPath in the kotlin dsl:

applicationVariants.forEach { variant ->
    variant.outputs.forEach { output ->
            tasks.filter {
                it.name.startsWith("appDistributionUpload${variant.name.capitalize()}")
            }.forEach {
                it.doFirst {
                    it.setProperty("apkPath", output.outputFile.absolutePath)
                }
            }
    }
}

I'm guessing I need a magic string instead of just "apkPath", because there doesn't seem to exist a strongly typed way of saying this.

Upvotes: 0

Views: 478

Answers (1)

Raghuram
Raghuram

Reputation: 115

Kotlin dsl way:

android.applicationVariants.all {
    this.outputs.all {
        val output = this
        tasks.matching {
            it.name.startsWith(
                "appDistributionUpload${this.name.capitalize()}"
            )
        }.forEach {
            it.doFirst {
                if (it is com.google.firebase.appdistribution.gradle.UploadDistributionTask) {
                    it.appDistributionProperties.get().apkPath = output.outputFile.absolutePath
                }
            }
        }
    }
}

Upvotes: 2

Related Questions