Allan Wang
06/06/2019, 3:28 AMgildor
06/06/2019, 3:46 AMgildor
06/06/2019, 3:46 AMgildor
06/06/2019, 3:52 AMgildor
06/06/2019, 3:52 AMMatej Drobnič
06/10/2019, 7:51 AMMatej Drobnič
06/10/2019, 7:51 AM// Hack to allow android block below. See <https://github.com/gradle/kotlin-dsl/issues/1287>
@Suppress("UnstableApiUsage")
fun Project.android(
configure: com.android.build.gradle.BaseExtension.() -> Unit
): Unit =
(this as ExtensionAware).extensions.configure("android", configure)
Matej Drobnič
06/10/2019, 7:52 AMMatej Drobnič
06/10/2019, 7:53 AMcom.android.library
and com.android.application
in my appMatej Drobnič
06/10/2019, 7:53 AMandroid
extension. However both extensions extend from the com.android.build.gradle.BaseExtension
, so I can manually add extension like with code snippet abovegildor
06/10/2019, 7:56 AMProject.android
functiongildor
06/10/2019, 7:57 AMgildor
06/10/2019, 7:57 AMgildor
06/10/2019, 7:57 AMHack to allow android block belowIt’s not needed
gildor
06/10/2019, 7:57 AMgildor
06/10/2019, 7:57 AMgildor
06/10/2019, 7:58 AMMatej Drobnič
06/10/2019, 10:56 AMMatej Drobnič
06/10/2019, 10:56 AMMatej Drobnič
06/10/2019, 10:57 AMMatej Drobnič
06/10/2019, 10:57 AMMatej Drobnič
06/10/2019, 10:58 AMbuild.gradle.kts
I have a line like this:
subprojects {
android {
// Perform some configuration that is common to both android library and applicaton projects
}
}
Matej Drobnič
06/10/2019, 10:58 AMMatej Drobnič
06/10/2019, 11:00 AMplugins {
id("com.android.application")
}
to this common file, then it will break libraries
if I add
plugins {
id("com.android.library")
}
then it will break application modulesMatej Drobnič
06/10/2019, 11:01 AMandroid
extension, so I would get ClassCastExceptionsgildor
06/10/2019, 11:10 AMMatej Drobnič
06/10/2019, 11:12 AMgildor
06/10/2019, 11:13 AMMatej Drobnič
06/10/2019, 11:13 AMgildor
06/10/2019, 11:13 AMMatej Drobnič
06/10/2019, 11:14 AMjust a config in root build.grafle
gildor
06/10/2019, 11:14 AMgildor
06/10/2019, 11:15 AMMatej Drobnič
06/10/2019, 11:17 AMMatej Drobnič
06/10/2019, 11:17 AMgildor
06/10/2019, 11:18 AMgildor
06/10/2019, 11:19 AMgildor
06/10/2019, 11:20 AMandroid
extension static accessor of each pluginMatej Drobnič
06/10/2019, 11:21 AMMatej Drobnič
06/10/2019, 11:21 AMplugins {
id("com.android.application")
}
subprojects {
android {
performCommonConfiguration()
}
}
gildor
06/10/2019, 11:21 AMgildor
06/10/2019, 11:21 AMMatej Drobnič
06/10/2019, 11:21 AMgildor
06/10/2019, 11:22 AMgildor
06/10/2019, 11:22 AMgildor
06/10/2019, 11:24 AMgildor
06/10/2019, 11:24 AMgildor
06/10/2019, 11:25 AMgildor
06/10/2019, 11:27 AMMatej Drobnič
06/10/2019, 11:29 AMgildor
06/10/2019, 11:38 AM*-convention
plugins, I would apply them instead of com.android.*
, not togetherMatej Drobnič
06/10/2019, 11:52 AMMatej Drobnič
06/10/2019, 11:52 AMgildor
06/10/2019, 11:55 AM// Configure exten
subprojects { // or even allprojects, depends on your project structure
// Apply this config only when any of android plugins is applied
plugins.withType<com.android.build.gradle.BasePlugin<*>> {
// configure extension by common type for all android plugins
configure<com.android.build.gradle.BaseExtension> {
// this has type BaseExtension, so you can configure common properties
compileSdkVersion(28)
}
}
}
gildor
06/10/2019, 11:56 AM