androidandroid-gradle-plugingradle-kotlin-dsl

Android gradle plugin 8.1.0 change apk name


Old way of apk naming is no longer working, is there another api in AGP 8+?

Here's my kts build.config:

android {
    ...
    applicationVariants.all { variant ->
        variant.outputs
            // default type don't have outputFileName field
            .map { it as com.android.build.gradle.internal.api.ApkVariantOutputImpl } 
            .all { output ->
                output.outputFileName = "MyAwesomeName.apk"
                false
            }
    }
}

I use AGP 8.1.0 and gradle 8.2.1


Solution

  • Found the issue: there are more .all() methods, the right one comes from org.gradle.api.DomainObjectCollection and not from _Collections.kt

    Basically to get the right behavior we need to just remove the it lambda parameter.

    // wrong
    applicationVariants.all { variant -> }
    // right
    applicationVariants.all {  }
    

    Very tricky problem