仅向 Kotlin DSL 中的 "free" 产品风格添加实现依赖项

Adds an implementation dependency only to the "free" product flavor in 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"

}

下面是解决方法。

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

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

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