Envrionment
Java 8
Android Studio 2.3.1
gradle 2.3.1
kotlin 1.1.1
DataBinding 2.0
Installing the Kotlin plugin
https://blog.jetbrains.com/kotlin/2013/08/working-with-kotlin-in-android-studio/ After installation, restart Android Studio.Setting your project
Create src/main/kotlin folder for kotlin source code. Setup project/build.gradle, project/app/build.gradle project/build.gradlebuildscript { ext.kotlin_version = '1.1.1' repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:2.3.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { jcenter() } } task clean(type: Delete) { delete rootProject.buildDir }And you need some configurations in
apply plugin: 'com.android.application' apply plugin: 'kotlin-kapt' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' android { compileSdkVersion 25 buildToolsVersion "25.0.1" defaultConfig { applicationId "com.example.kotlin" minSdkVersion 15 targetSdkVersion 25 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } sourceSets { main.java.srcDirs += 'src/main/kotlin' } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } dataBinding { enabled = true version = "2.0.0" } kapt { generateStubs = true } } dependencies { kapt 'com.android.databinding:compiler:2.3.0' compile fileTree(dir: 'libs', include: ['*.jar']) androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) compile 'com.android.support:appcompat-v7:25.3.1' compile 'com.android.support:design:25.3.1' testCompile 'junit:junit:4.12' compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" } repositories { mavenCentral() }
Comments
Post a Comment