코틀린 설치





안드로이드 스튜디오 [ FILE ] - [ Settings ] 로 가셔서 kotlin 검색 후, 'Install' 을 합니다.

 


 

 


 


build.gradle (Application)


classpath 에 코틀린을 추가해 줍시다~

buildscript {

ext.kotlin_version = '1.1.3-2'

repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$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
}



build.gradle (App)


상단에 plugin 추가

apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'



dependencies 에 코틀린 라이브러리 추가

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])

compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
compile 'com.android.support:appcompat-v7:26.+'
compile 'com.android.support:design:26.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
}




Activity 작성

[File] - [New] - [Kolin Activity] 선택해서 액티비티를 생성하세요.


class MainKotlinActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main_kotlin)

var tv_kotlin = findViewById(R.id.tv_kotlin) as TextView
tv_kotlin.text = getMessage(1)
}

fun getMessage(msgType : Int) : String {
return if (msgType == 1) "아 너무 졸립다~" else "졸립지 않아요~"
}
}



Run 시키면, '아 너무 졸립다~' 가 회면에 나오게 됩니다.


감사합니다.




'안드로이드 > Kotlin (코틀린)' 카테고리의 다른 글

기본문법  (0) 2017.09.04
Kotlin -02 컴포넌트 바로 접근하기  (0) 2017.08.22
Posted by 자바리즘
,