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

Use Kotlin for build.gradle.

Use Kotlin for build.gradle.

Gradle Kotlin DSL helps us to write build.gradle with Kotlin.
I try to use it, and explain how to do it.

Amane Nikaido

October 27, 2017
Tweet

More Decks by Amane Nikaido

Other Decks in Programming

Transcript

  1. CVJMEHSBEMFΛ
    ,PUMJOԽͯ͠Έͨ

    ೋ֊ಊว
    !4IJCVZBBQL

    View Slide

  2. ೋ֊ಊว ʹ͔͍Ͳ͏͋·Ͷ

    !BLBJEP
    "OESPJE͸͡Ίͨ࣌ظ.BSTINBMMPX
    ϓϩϑΟʔϧ
    ޷͖ͳݴ༿4IBSFE&MFNFOU

    View Slide

  3. w CVJMEHSBEMFΛ,PUMJOͰॻ͚ΔΑ͏ʹ
    w IUUQTHJUIVCDPNHSBEMFLPUMJOETM
    (SBEMF,PUMJO%4-

    View Slide

  4. )PX

    View Slide

  5. w "OESPJE4UVEJP TUBCMF

    w HSBEMF
    w "OESPJEQMVHJOGPS(SBEMF
    w ,PUMJO
    ར༻ͨ͠؀ڥ

    View Slide

  6. TFUUJOHTHSBEMF
    pluginManagement {
    repositories {
    gradlePluginPortal()
    maven { url "https://jcenter.bintray.com/" }
    maven { url "https://dl.google.com/dl/android/maven2/" }
    }
    resolutionStrategy {
    eachPlugin {
    if(requested.id.id == "com.android.application") {
    useModule("com.android.tools.build:gradle:$
    {requested.version}")
    }
    }
    }
    }
    include ‘:app'
    rootProject.buildFileName = 'build.gradle.kts'

    View Slide

  7. TFUUJOHTHSBEMF
    pluginManagement {
    repositories {
    gradlePluginPortal()
    maven { url "https://jcenter.bintray.com/" }
    maven { url "https://dl.google.com/dl/android/maven2/" }
    }
    resolutionStrategy {
    eachPlugin {
    if(requested.id.id == "com.android.application") {
    useModule("com.android.tools.build:gradle:$
    {requested.version}")
    }
    }
    }
    }
    include ':app'

    rootProject.buildFileName = 'build.gradle.kts'
    "OESPJEQMVHJO͔Βඞཁ

    View Slide

  8. NWBQQCVJMEHSBEMF\ LUT^

    View Slide

  9. CVJMEHSBEMFLUTमਖ਼
    apply plugin: 'com.android.application'
    apply plugin: 'kotlin-android'
    android {
    compileSdkVersion 26
    buildToolsVersion "26.0.2"
    defaultConfig {
    applicationId “jp.a2kaido.view"
    minSdkVersion 21
    targetSdkVersion 26
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
    release {
    minifyEnabled false
    proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-
    rules.pro'
    }
    }

    View Slide

  10. CVJMEHSBEMFLUTमਖ਼
    apply plugin: 'com.android.application'
    apply plugin: 'kotlin-android'
    android {
    compileSdkVersion 26
    buildToolsVersion "26.0.2"
    defaultConfig {
    applicationId “jp.a2kaido.view"
    minSdkVersion 21
    targetSdkVersion 26
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
    release {
    minifyEnabled false
    proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-
    rules.pro'
    }
    }

    View Slide

  11. plugins {
    id("com.android.application") version "3.0.0"
    kotlin("android") version "1.1.51"
    }
    android {
    compileSdkVersion 26
    buildToolsVersion "26.0.2"
    defaultConfig {
    applicationId “jp.a2kaido.view"
    minSdkVersion 21
    targetSdkVersion 26
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
    release {
    minifyEnabled false
    proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-
    rules.pro'
    CVJMEHSBEMFLUTमਖ਼

    View Slide

  12. plugins {
    id("com.android.application") version "3.0.0"
    kotlin("android") version "1.1.51"
    }
    android {
    compileSdkVersion 26
    buildToolsVersion "26.0.2"
    defaultConfig {
    applicationId "jp.a2kaido.view"
    minSdkVersion 21
    targetSdkVersion 26
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
    release {
    minifyEnabled false
    proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-
    rules.pro'
    }
    }
    }
    dependencies {
    CVJMEHSBEMFLUTमਖ਼

    View Slide

  13. plugins {
    id("com.android.application") version "3.0.0"
    kotlin("android") version "1.1.51"
    }
    android {
    compileSdkVersion(26)
    buildToolsVersion("26.0.2")
    defaultConfig {
    applicationId = "jp.a2kaido.view"
    minSdkVersion(21)
    targetSdkVersion(26)
    versionCode = 1
    versionName = "1.0"
    testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
    getByName("release") {
    isMinifyEnabled = false
    proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-
    rules.pro")
    }
    }
    }
    dependencies {
    CVJMEHSBEMFLUTमਖ਼

    View Slide

  14. plugins {
    id("com.android.application") version "3.0.0"
    kotlin("android") version "1.1.51"
    }
    android {
    compileSdkVersion(26)
    buildToolsVersion("26.0.2")
    defaultConfig {
    applicationId = "jp.a2kaido.view"
    minSdkVersion(21)
    targetSdkVersion(26)
    versionCode = 1
    versionName = "1.0"
    testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
    getByName("release") {
    isMinifyEnabled = false
    proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-
    rules.pro")
    }
    }
    }
    dependencies {
    CVJMEHSBEMFLUTमਖ਼
    /** Sets the targetSdkVersion to the given value. */
    @NonNull
    public ProductFlavor setTargetSdkVersion(@Nullable ApiVersion targetSdkVersion) {
    mTargetSdkVersion = targetSdkVersion;
    return this;
    }

    View Slide

  15. plugins {
    id("com.android.application") version "3.0.0"
    kotlin("android") version "1.1.51"
    }
    android {
    compileSdkVersion(26)
    buildToolsVersion("26.0.2")
    defaultConfig {
    applicationId = "jp.a2kaido.view"
    minSdkVersion(21)
    targetSdkVersion(26)
    versionCode = 1
    versionName = "1.0"
    testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
    getByName("release") {
    isMinifyEnabled = false
    proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-
    rules.pro")
    }
    }
    }
    dependencies {
    CVJMEHSBEMFLUTमਖ਼

    View Slide

  16. proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-
    rules.pro")
    }
    }
    }
    dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:
    3.0.1'
    }
    CVJMEHSBEMFLUTमਖ਼

    View Slide

  17. proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-
    rules.pro")
    }
    }
    }
    dependencies {
    implementation(fileTree(mapOf("dir" to "libs", "include" to arrayOf("*.jar"))))
    implementation("org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.51")
    implementation("com.android.support:appcompat-v7:26.1.0")
    "implementation"("com.android.support.constraint:constraint-layout:1.0.2")
    testImplementation("junit:junit:4.12")
    androidTestImplementation("com.android.support.test:runner:1.0.1")
    val test = "androidTestImplementation"
    test("com.android.support.test.espresso:espresso-core:3.0.1")
    }
    repositories {
    google()
    jcenter()
    }
    CVJMEHSBEMFLUTमਖ਼

    View Slide

  18. proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-
    rules.pro")
    }
    }
    }
    dependencies {
    implementation(fileTree(mapOf("dir" to "libs", "include" to arrayOf("*.jar"))))
    implementation("org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.51")
    implementation("com.android.support:appcompat-v7:26.1.0")
    "implementation"("com.android.support.constraint:constraint-layout:1.0.2")
    testImplementation("junit:junit:4.12")
    androidTestImplementation("com.android.support.test:runner:1.0.1")
    val test = "androidTestImplementation"
    test("com.android.support.test.espresso:espresso-core:3.0.1")
    }
    repositories {
    google()
    jcenter()
    }
    CVJMEHSBEMFLUTमਖ਼
    operator fun String.invoke(dependencyNotation: Any): Dependency =
    dependencies.add(this, dependencyNotation)

    View Slide

  19. proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-
    rules.pro")
    }
    }
    }
    dependencies {
    implementation(fileTree(mapOf("dir" to "libs", "include" to arrayOf("*.jar"))))
    implementation("org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.51")
    implementation("com.android.support:appcompat-v7:26.1.0")
    "implementation"("com.android.support.constraint:constraint-layout:1.0.2")
    testImplementation("junit:junit:4.12")
    androidTestImplementation("com.android.support.test:runner:1.0.1")
    val test = "androidTestImplementation"
    test("com.android.support.test.espresso:espresso-core:3.0.1")
    }
    repositories {
    google()
    jcenter()
    }
    CVJMEHSBEMFLUTमਖ਼

    View Slide

  20. Ҏ্ͰϏϧυͰ͖·͢

    View Slide

  21. w HSPPWZͱಉ͡Α͏ʹॻ͚Δʂ
    w ͻͱੲલ͸HSPPWZͱࣅͨه๏ʹ͢ΔͨΊͷ

    ؔ਺ΛCVJMEHSBEMFLUTʹ௚Ͱॻ͍ͯͨ
    w ͜ͷΑ͏ͳه๏ʹ͢ΔͨΊʹͲͷΑ͏ͳ࣮૷Λ͠
    ͍ͯΔ͔ಡΉͷָ͕ͦ͠͏
    ΍ͬͯΈͯ

    View Slide

  22. ͝੩ௌ͋Γ͕ͱ͏

    ͍͟͝·ͨ͠

    View Slide