에이치의 모바일 앱 개발
Databinding 본문
데이터 바인딩은 버터나이프의 업그레이드 된 버전입니다. 위 방법을 제공하는 출처는 다르지만, 제안한 사람이 같기에 버터나이프를 고집하시는 분도 데이터 바인딩을 찾아서 사용합니다. 데이터 바인딩은 말 그대로 뷰 자체에서 데이터를 바인딩하여 편리하고, 옵저빙하여 유용하게 사용하게 하는 기술입니다.
데이터 바인딩을 사용하려면 먼저 해당 라이브러리를 인폴트해줍니다.
android {
dataBinding {
enabled = true
}
}
작업 중인 class 파일이 java 가 아닌 kotlin으로 되어있다면 gradle에 아래와 같은 코드를 추가하셔야합니다.
// app gradle file...
apply plugin: 'kotlin-kapt'
..
dependencies {
// notice that the compiler version must be the same than our gradle version
kapt "com.android.databinding:compiler:$android_plugin_version"
}
// project gradle file...
buildscript {
ext.android_plugin_version = '3.2.1'
dependencies { classpath "com.android.tools.build:gradle:$android_plugin_version" }
}
gradle version 3.1.4 이 후 버전 부터는 kapt 을 등록할 필요가 없어보입니다.
이슈 변동이 생길 경우 내용 업데이트 하겠습니다.(19.05.15 기준)
----------------------------
(19.11.26 추가..)
코틀린 데이터 바인딩..
1. app :: gradle에 다음 내용을 추가합니다.
apply plugin: 'kotlin-android' // 코틀린 사용
apply plugin: 'kotlin-android-extensions' // 코틀린 확장(findByView 를 자동화 해줍니다.)
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
2. project :: gradle 에 다음 내용을 추가합니다.
buildscript {
ext.kotlin_version = '1.3.60'
ext.android_plugin_version = '3.5.2'
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:$android_plugin_version"
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
}
}
'Android > Android 개발 소스' 카테고리의 다른 글
Android Device Screen zoom 획득 (2) | 2019.03.07 |
---|---|
View-RecyclerView (0) | 2019.02.20 |
View-ImageView-Picasso-blur (0) | 2019.02.20 |
View-ImageView-Gradient (0) | 2019.02.20 |
Battery-Awake, Sleep (0) | 2019.02.20 |