Android Studio Dolphin中BindingAdapter类未生成编译报错求助
解决Android Studio Dolphin中@BindingAdapter编译错误的排查方案
基础配置核查
- 确认Module级
build.gradle中启用数据绑定:android { buildFeatures { dataBinding true } } - 确保
kotlin-kapt插件正确配置:
项目级build.gradle中声明插件版本:
Module级plugins { id 'com.android.application' version '7.3.0' apply false id 'org.jetbrains.kotlin.android' version '1.7.20' apply false id 'kotlin-kapt' version '1.7.20' apply false }build.gradle中应用插件:plugins { id 'com.android.application' id 'org.jetbrains.kotlin.android' id 'kotlin-kapt' }
@BindingAdapter代码规范检查
- 必须使用
androidx.databinding.BindingAdapter注解,避免使用旧版android.databinding.BindingAdapter - Kotlin中绑定方法需标记
@JvmStatic(伴生对象或顶层函数均可):object BindingAdapters { @JvmStatic @BindingAdapter("app:customText") fun setCustomText(view: TextView, text: String?) { view.text = text ?: "" } } - XML中属性名需与注解内的名称完全匹配,同时确认根节点已声明
app命名空间:<layout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" app:customText="@{viewModel.text}" /> </layout>
编译缓存清理
- 执行
Build > Clean Project,再执行Build > Rebuild Project - 清除IDE缓存:
File > Invalidate Caches... > Invalidate and Restart
版本兼容性检查
- 确保Android Gradle Plugin(AGP)版本与Kotlin版本匹配:Dolphin对应AGP 7.3.x,建议搭配Kotlin 1.7.x
- 无需手动添加databinding依赖,AGP会自动引入对应兼容版本的库
内容的提问来源于stack exchange,提问作者Fazal
相关产品推荐
相关产品推荐

