0

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 firebase-support@google.com 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.

Robert Jeppesen
  • 7,837
  • 3
  • 35
  • 50

1 Answers1

2

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
                }
            }
        }
    }
}
Raghuram
  • 115
  • 5
  • In my case I have changed the old line 'it.appDistributionProperties.apkPath = ' to the new line from your solution 'it.appDistributionProperties.get().apkPath ='. It helped. Thank you sir. – Andrew G Oct 20 '21 at 16:40