Android gradle插件8.1.0更改apk名称

Lin*_*182 7 android android-gradle-plugin gradle-kotlin-dsl

旧的 apk 命名方式不再有效,AGP 8+ 中是否还有其他 api?

这是我的 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
            }
    }
}
Run Code Online (Sandbox Code Playgroud)

我使用 AGP 8.1.0 和 gradle 8.2.1

Lin*_*182 2

发现问题:方法多了.all(),正确的来自org.gradle.api.DomainObjectCollection而不是来自_Collections.kt

基本上,为了获得正确的行为,我们只需删除itlambda 参数即可。

// wrong
applicationVariants.all { variant -> }
// right
applicationVariants.all {  }
Run Code Online (Sandbox Code Playgroud)

非常棘手的问题

  • @Link182,对我没有帮助。使用 Android Gradle 插件 8.0.1 和 Gradle 8.0。我只是没有看到 outputFileName 属性。你能复制粘贴整个块吗?文件顶部有任何导入吗? (2认同)
  • @Karolis此代码应该可以工作/sf/answers/4062518421/ (2认同)