[英]Share logic between application module and library module
I have module.gradle.kts
:我有
module.gradle.kts
:
plugins {
id("com.android.library")
id("org.jetbrains.kotlin.android")
}
android {
defaultConfig {
...
}
}
And app.gradle.kts
:和
app.gradle.kts
:
plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
}
android {
defaultConfig {
...
}
}
I would like to define a common configuration of android.defaultConfig
for both app.gradle.kts
and module.gradle.kts
in a dedicated gradle file, such as root.gradle.kts
:我想在专用的 gradle 文件中为
app.gradle.kts
和module.gradle.kts
定义android.defaultConfig
的通用配置,例如root.gradle.kts
:
plugins {
// What plugin to use here since this is neither an application module nor a library module ?
id("org.jetbrains.kotlin.android")
}
android {
defaultConfig {
// Common configuration to be used by app.gradle.kts and module.gradle.kts
}
}
Is there a common ancestor to "com.android.application" and "com.android.library" that can be used in that case?在这种情况下是否可以使用“com.android.application”和“com.android.library”的共同祖先?
I've defined my own extension function in buildSrc/src/main/Extensions.kt
:我在
buildSrc/src/main/Extensions.kt
中定义了我自己的扩展 function :
import com.android.build.api.dsl.CommonExtension
fun CommonExtension<*, *, *, *>.applyRootConfiguration() {
defaultConfig {
// ...
}
}
Then I can apply it in an application or a library by doing:然后我可以通过执行以下操作将它应用到应用程序或库中:
android {
applyRootConfiguration()
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.