首页 > 解决方案 > 仅向 Kotlin DSL 中的“免费”产品风格添加实现依赖项

问题描述

我正在将我们基于 Groovy 的脚本迁移到 Kotlin。除了不确定如何为特定风味添加依赖项外,我已经完成了大部分工作。到目前为止,这就是 Kotlin DSL 中的样子,但不确定为什么 freeImplementation("bar:2.2.8")

 productFlavors {
    create("free") {
         ...
         ...
    }
    create("paid") {
        ...
        ...
    }
}

dependencies {

    implementation("foo:1.2.0")

    // This is not working when migrated to Kotlin DSL
    freeImplementation("bar:2.2.8")

    //Below was the code in Groovy which was working fine earlier 
    //freeImplementation "bar:2.2.8"

}

标签: android-gradle-pluginbuild.gradlegradle-kotlin-dsl

解决方案


下面是它的解决方案。

 val freeImplementation by configurations
    dependencies {
        freeImplementation("bar:2.2.8")
    }

或者,可以使用字符串文字来表示动态配置:

dependencies {
    "freeImplementation"("bar:2.2.8")
}

推荐阅读