Gradle Kotlin DSL helps us to write build.gradle with Kotlin. I try to use it, and explain how to do it.
CVJMEHSBEMFΛ,PUMJOԽͯ͠Έͨೋ֊ಊว!4IJCVZBBQL
View Slide
ೋ֊ಊว ʹ͔͍Ͳ͏͋·Ͷ!BLBJEP"OESPJE͡Ίͨ࣌ظ.BSTINBMMPXϓϩϑΟʔϧ͖ͳݴ༿4IBSFE&MFNFOU
w CVJMEHSBEMFΛ,PUMJOͰॻ͚ΔΑ͏ʹw IUUQTHJUIVCDPNHSBEMFLPUMJOETM(SBEMF,PUMJO%4-
)PX
w "OESPJE4UVEJP TUBCMFw HSBEMFw "OESPJEQMVHJOGPS(SBEMFw ,PUMJOར༻ͨ͠ڥ
TFUUJOHTHSBEMFpluginManagement {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'
TFUUJOHTHSBEMFpluginManagement {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͔Βඞཁ
NWBQQCVJMEHSBEMF\ LUT^
CVJMEHSBEMFLUTमਖ਼apply plugin: 'com.android.application'apply plugin: 'kotlin-android'android {compileSdkVersion 26buildToolsVersion "26.0.2"defaultConfig {applicationId “jp.a2kaido.view"minSdkVersion 21targetSdkVersion 26versionCode 1versionName "1.0"testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"}buildTypes {release {minifyEnabled falseproguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'}}
plugins {id("com.android.application") version "3.0.0"kotlin("android") version "1.1.51"}android {compileSdkVersion 26buildToolsVersion "26.0.2"defaultConfig {applicationId “jp.a2kaido.view"minSdkVersion 21targetSdkVersion 26versionCode 1versionName "1.0"testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"}buildTypes {release {minifyEnabled falseproguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'CVJMEHSBEMFLUTमਖ਼
plugins {id("com.android.application") version "3.0.0"kotlin("android") version "1.1.51"}android {compileSdkVersion 26buildToolsVersion "26.0.2"defaultConfig {applicationId "jp.a2kaido.view"minSdkVersion 21targetSdkVersion 26versionCode 1versionName "1.0"testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"}buildTypes {release {minifyEnabled falseproguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'}}}dependencies {CVJMEHSBEMFLUTमਖ਼
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 = 1versionName = "1.0"testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner"}buildTypes {getByName("release") {isMinifyEnabled = falseproguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro")}}}dependencies {CVJMEHSBEMFLUTमਖ਼
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 = 1versionName = "1.0"testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner"}buildTypes {getByName("release") {isMinifyEnabled = falseproguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro")}}}dependencies {CVJMEHSBEMFLUTमਖ਼/** Sets the targetSdkVersion to the given value. */@NonNullpublic ProductFlavor setTargetSdkVersion(@Nullable ApiVersion targetSdkVersion) {mTargetSdkVersion = targetSdkVersion;return this;}
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मਖ਼
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मਖ਼
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)
Ҏ্ͰϏϧυͰ͖·͢
w HSPPWZͱಉ͡Α͏ʹॻ͚Δʂw ͻͱੲલHSPPWZͱࣅͨه๏ʹ͢ΔͨΊͷ ؔΛCVJMEHSBEMFLUTʹͰॻ͍ͯͨw ͜ͷΑ͏ͳه๏ʹ͢ΔͨΊʹͲͷΑ͏ͳ࣮Λ͍ͯ͠Δ͔ಡΉͷָ͕ͦ͠͏ͬͯΈͯ
͝੩ௌ͋Γ͕ͱ͏ ͍͟͝·ͨ͠