Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Building Android Projects with kts

Building Android Projects with kts

Presentation Build Android Projects with kts.
Devfest Latam 2020
Devfest Pacific Region DevFest 2020

Iñaki Villar

October 18, 2020
Tweet

More Decks by Iñaki Villar

Other Decks in Technology

Transcript

  1. apply plugin: 'com.android.application' apply plugin: 'kotlin-android' android { compileSdkVersion 30

    defaultConfig { applicationId “com.example.app" versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false } } }
  2. apply plugin: 'com.android.application' apply plugin: 'kotlin-android' android { compileSdkVersion 30

    defaultConfig { applicationId “com.example.app" versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false } } } apply(plugin = "com.android.application") apply(plugin = "kotlin-android") android { compileSdkVersion(30) defaultConfig { applicationId = "com.example.app" versionCode = 1 versionName = "1.0" } buildTypes { getByName("release") { isMinifyEnabled = false } } }
  3. apply plugin: 'com.android.application' apply plugin: 'kotlin-android' android { compileSdkVersion 30

    defaultConfig { applicationId “com.example.app" versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false } } } apply(plugin = "com.android.application") apply(plugin = "kotlin-android") android { compileSdkVersion(30) defaultConfig { applicationId = "com.example.app" versionCode = 1 versionName = "1.0" } buildTypes { getByName("release") { isMinifyEnabled = false } } }
  4. apply plugin: 'com.android.application' apply plugin: 'kotlin-android' android { compileSdkVersion 30

    defaultConfig { applicationId “com.example.app" versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false } } } apply(plugin = "com.android.application") apply(plugin = "kotlin-android") android { compileSdkVersion(30) defaultConfig { applicationId = "com.example.app" versionCode = 1 versionName = "1.0" } buildTypes { getByName("release") { isMinifyEnabled = false } } }
  5. apply plugin: 'com.android.application' apply plugin: 'kotlin-android' android { compileSdkVersion 30

    defaultConfig { applicationId “com.example.app" versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false } } } apply(plugin = "com.android.application") apply(plugin = "kotlin-android") android { compileSdkVersion(30) defaultConfig { applicationId = "com.example.app" versionCode = 1 versionName = "1.0" } buildTypes { getByName("release") { isMinifyEnabled = false } } }
  6. apply plugin: 'com.android.application' apply plugin: 'kotlin-android' android { compileSdkVersion 30

    defaultConfig { applicationId “com.example.app" versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false } } } apply(plugin = "com.android.application") apply(plugin = "kotlin-android") android { compileSdkVersion(30) defaultConfig { applicationId = "com.example.app" versionCode = 1 versionName = "1.0" } buildTypes { getByName("release") { isMinifyEnabled = false } } }
  7. KTS

  8. GRADLE JAVA API KTS Kotlin DSL API org.gradle.kotlin.dsl org.gradle.kotlin.dsl.plugins.dsl implementation("com.github.oshi:oshi-core:3.13.3")

    fun DependencyHandler.`implementation`(dependencyNotation: Any): Dependency? = add("implementation", dependencyNotation)
  9. dependencies { implementation("org.jetbrains.kotlin:kotlin-stdlib:1.3.60") implementation("org.influxdb:influxdb-java:2.19") } Module-a/build.gradle.kts object Dependencies { const

    val kotlin = "org.jetbrains.kotlin:kotlin-stdlib:1.3.60" const val influxDb = "org.influxdb:influxdb-java:2.19" } dependencies { implementation(Dependencies.kotlin) implementation(Dependencies.influxDb) }
  10. dependencies { implementation("org.jetbrains.kotlin:kotlin-stdlib:1.3.60") implementation("org.influxdb:influxdb-java:2.19") } Module-a/build.gradle.kts object Dependencies { const

    val kotlin = "org.jetbrains.kotlin:kotlin-stdlib:1.3.60" const val influxDb = "org.influxdb:influxdb-java:2.19" } dependencies { implementation(Dependencies.kotlin) implementation(Dependencies.influxDb) }
  11. Plugins build scripts blocks buildSrc build.gradle.kts build.gradle Gradle API dependencies

    { implementation("") implementation("") testImplementation("") } object Dependencies{ ... }
  12. Plugins build scripts blocks buildSrc build.gradle.kts build.gradle Gradle API plugins

    { `kotlin-dsl` } import org.gradle.kotlin.dsl.dependencies import org.gradle.kotlin.dsl.repositories class ExamplePlugin : Plugin<Project> { override fun apply(target: Project) { target.repositories { } target.dependencies { } } }
  13. Plugins build scripts blocks buildSrc build.gradle.kts build.gradle Gradle API buildscript

    { repositories { google() jcenter() } dependencies { classpath("com.android.tools.build:gradle:4.1.0") classpath(kotlin("gradle-plugin", version = "1.3.70")) } } plugins { id("com.android.application") kotlin("android") kotlin("android.extensions") }
  14. Java Platform Plugin dependencies { constraints { api("commons-httpclient:commons-httpclient:3.1") api("org.apache.commons:commons-lang3:3.8.1") }

    } dependencies { api(platform(project(":platform"))) api("commons-httpclient:commons-httpclient") }
  15. Java Platform Plugin dependencies { constraints { api("commons-httpclient:commons-httpclient:3.1") api("org.apache.commons:commons-lang3:3.8.1") }

    } dependencies { api(platform(project(":platform"))) api("commons-httpclient:commons-httpclient") } https://docs.gradle.org/current/userguide/java_platform_plugin.html
  16. AGP 4.1 Full Support Kotlin DSL API & DSL Kotlin

    https://developer.android.com/reference/tools/gradle-api/4.1/com/android/build/api/dsl/ApplicationBaseFlavor