通过Kotlin DSL的Android特定风味依赖

时间:2020-01-10 06:51:18

标签: android gradle-kotlin-dsl kotlin-dsl

build.gradle内部,我们可以

   productFlavors {
        free {
            dimension "tier"
        }
    }

然后

dependencies { freeDebugImplementation "com.someDependency:free-debug:1.0.0";}

但是当我在Kotlin DSL内使用build.gradle.kts时,我

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

然后在dependencies中,我不能

dependencies { freeImplementation(...)}

错误:^ Unresolved reference: freeImplementation 那么,如何通过Kotlin DSL implementation来选择特定口味?

3 个答案:

答案 0 :(得分:3)

您应该使用示例“ YOUR_FLAVOR_NAME实现”

[root@271386b095c6 /]# ps ax
  PID TTY      STAT   TIME COMMAND
    1 ?        Ssl  320:12 /usr/bin/contextBroker -fg -multiservice -ngsiv1Autocast -dbhost mongo -corsOrigin __ALL -logLevel DEBUG
 9248 pts/0    Ss     0:00 bash
 9293 pts/0    R+     0:00 ps ax

}

答案 1 :(得分:1)

Kotlin DSL 特定于口味的依赖性如下所示:

dependencies { 
    "freeImplementation"(...)
    "paidImplementation"(...)

}

答案 2 :(得分:0)

productFlavors {
    free {
            .....
         }
    paid {
            ....
         }
}

在依赖项中这样写

dependencies {

        freeImplementation "your dependency is here"
        paidImplementation "your dependency is here"
        // Other dependencies    
}