Kotlin 합성에서 Jetpack 뷰 결합으로 이전
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
Kotlin Android 확장 프로그램이 지원 중단되었습니다. 즉, Kotlin을 사용하면
뷰 결합을 위한 합성은 더 이상 지원되지 않습니다. 앱에서 Kotlin을 사용하는 경우
합성을 사용하는 경우 이 가이드를 사용하여 Jetpack 뷰 결합으로 이전하세요.
앱에서 아직 뷰 결합에 Kotlin 합성을 사용하지 않는다면 뷰
바인딩을 참조하세요.
Gradle 파일 업데이트
Android 확장 프로그램과 마찬가지로 Jetpack 뷰 결합은 모듈별로 사용 설정됩니다.
기반으로 합니다 뷰 결합을 사용하는 각 모듈에 대해 viewBinding
빌드를 설정합니다.
모듈 수준 build.gradle
파일에서 true
옵션을 추가합니다.
Groovy
android {
...
buildFeatures {
viewBinding true
}
}
Kotlin
android {
...
buildFeatures {
viewBinding = true
}
}
앱에서 Parcelable
를 사용하지 않는 경우
기능을 사용하려면 Kotlin Android 확장 프로그램을 사용 설정하는 행을 삭제합니다.
Groovy
plugins {
id 'kotlin-android-extensions'
}
Kotlin
plugins {
kotlin("android.extensions")
}
모듈에서 뷰 결합을 사용 설정하는 방법에 관한 자세한 내용은 설정을 참조하세요.
안내를 따르세요.
활동 및 프래그먼트 클래스 업데이트
Jetpack 뷰 결합을 사용하면 각 XML 레이아웃 파일의 결합 클래스가 생성됩니다.
kube-APIserver입니다 이 결합 클래스의 이름은 XML의 이름입니다.
파일 맨 끝에 Binding이 추가된 파스칼 표기법으로 파일을 만듭니다. 예를 들어
레이아웃 파일의 이름은 result_profile.xml
이고 생성된
결합 클래스는 ResultProfileBinding
입니다.
합성 속성 대신 생성된 결합 클래스를 사용하여
뷰를 참조하고 활동과 프래그먼트 클래스를 변경하는 방법은 다음과 같습니다.
있습니다.
kotlinx.android.synthetic
에서 가져오기를 모두 삭제합니다.
활동에 대해 생성된 결합 클래스의 인스턴스를 확장합니다.
사용할 수 있습니다.
대신 결합 클래스 인스턴스를 사용하도록 모든 뷰 참조를 변경합니다.
합성 속성:
// Reference to "name" TextView using synthetic properties.
name.text = viewModel.nameString
// Reference to "name" TextView using the binding class instance.
binding.name.text = viewModel.nameString
자세한 내용은 아래의 사용량 섹션을 참고하세요.
뷰 결합 가이드를 참조하세요.
추천 서비스
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-07-27(UTC)
[null,null,["최종 업데이트: 2025-07-27(UTC)"],[],[],null,["# Migrate from Kotlin synthetics to Jetpack view binding\n\nKotlin Android Extensions is deprecated, which means that using Kotlin\nsynthetics for view binding is no longer supported. If your app uses Kotlin\nsynthetics for view binding, use this guide to migrate to Jetpack view binding.\n\nIf your app doesn't already use Kotlin synthetics for view binding, see [View\nbinding](/topic/libraries/view-binding) for basic usage information.\n\nUpdate the Gradle file\n----------------------\n\nLike Android Extensions, Jetpack view binding is enabled on a module-by-module\nbasis. For each module that uses view binding, set the `viewBinding` build\noption to `true` in the module-level `build.gradle` file: \n\n### Groovy\n\n```groovy\nandroid {\n ...\n buildFeatures {\n viewBinding true\n }\n}\n```\n\n### Kotlin\n\n```kotlin\nandroid {\n ...\n buildFeatures {\n viewBinding = true\n }\n}\n```\n\nIf your app doesn't use [`Parcelable`](/reference/android/os/Parcelable)\nfeatures, remove the line that enables Kotlin Android Extensions: \n\n### Groovy\n\n```groovy\nplugins {\n id 'kotlin-android-extensions'\n}\n```\n\n### Kotlin\n\n```kotlin\nplugins {\n kotlin(\"android.extensions\")\n}\n```\n| **Note:** If your app uses `Parcelable` features, switch to using the standalone `kotlin-parcelize` Gradle plugin described in [Parcelable implementation generator](/kotlin/parcelize).\n\nTo learn more about enabling view binding in a module, see [Setup\ninstructions](/topic/libraries/view-binding#setup).\n\nUpdate activity and fragment classes\n------------------------------------\n\nWith Jetpack view binding, a binding class is generated for each XML layout file\nthat the module contains. The name of this binding class is the name of the XML\nfile in Pascal case with the word *Binding* added at the end. For example, if\nthe name of the layout file is `result_profile.xml`, the name of the generated\nbinding class is `ResultProfileBinding`.\n\nTo use the generated binding classes instead of synthetic properties to\nreference views, change your activity and fragment classes by doing the\nfollowing:\n\n1. Remove all imports from `kotlinx.android.synthetic`.\n\n2. Inflate an instance of the generated binding class for the activity or\n fragment to use.\n\n - For activities, follow the instructions in [Use view binding in\n activities](/topic/libraries/view-binding#activities) to inflate an instance in your activity's [`onCreate()`](/reference/kotlin/android/app/Activity#oncreate) method.\n - For fragments, follow the instructions in [Use view binding in\n fragments](/topic/libraries/view-binding#fragments) to inflate an instance in your fragment's [`onCreateView()`](/reference/kotlin/androidx/fragment/app/Fragment#oncreateview) method.\n3. Change all view references to use the binding class instance instead of\n synthetic properties:\n\n // Reference to \"name\" TextView using synthetic properties.\n name.text = viewModel.nameString\n\n // Reference to \"name\" TextView using the binding class instance.\n binding.name.text = viewModel.nameString\n\nTo learn more, see the [Usage](/topic/libraries/view-binding#usage) section in\nthe view binding guide.\n\nRecommended for you\n-------------------\n\n- Note: link text is displayed when JavaScript is off\n- [View binding](/topic/libraries/view-binding)\n- [Paging library overview](/topic/libraries/architecture/paging/v3-overview)\n- [Test your Paging implementation](/topic/libraries/architecture/paging/test)"]]