不生成BuildConfig-Gradle Kotlin DSL

问题描述 投票:0回答:1

要禁用使用Groovy DSL生成BuildConfig,可以执行以下操作:

afterEvaluate {
    generateReleaseBuildConfig.enabled = false
    generateDebugBuildConfig.enabled = false
}

我正在尝试使用Gradle的Kotlin DSL(build.gradle.kts)来寻找等效项。有人有运气吗?

android android-gradle gradle-kotlin-dsl android-buildconfig
1个回答
0
投票

您可以通过添加以下内容从所有变体中删除BuildConfig:

对于图书馆

android {
    ...

    // TODO replace with https://issuetracker.google.com/issues/72050365 once released.
    libraryVariants.all {
        generateBuildConfigProvider?.get()?.enabled = false
    }
}

用于申请

android {
    ...

    // TODO replace with https://issuetracker.google.com/issues/72050365 once released.
    applicationVariants.all {
        generateBuildConfigProvider?.get()?.enabled = false
    }
}

如果要指定构建类型,则:

libraryVariants
    .matching { it.buildType.name == "release"}
    .all {
        generateBuildConfigProvider?.get()?.enabled = false
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.