java.lang.NoClassDefFoundError:运行Espresso测试时的android.databinding.DataBinderMapperImpl

问题描述 投票:7回答:2

数据绑定设置:

apply plugin: 'kotlin-kapt'

android {
    dataBinding {
        enabled = true
    }
}

dependencies {
    kapt "com.android.databinding:compiler:3.1.0"
}

使用数据绑定的fragment类:

class LandingFragment : Fragment(), Injectable {

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
                          savedInstanceState: Bundle?): View? {
        val dataBinding = LandingFragmentBinding.inflate(inflater, container, false)
        return dataBinding.root
    }
}

每次为此片段运行Espresso测试时,我都会遇到以下异常:

java.lang.NoClassDefFoundError: android.databinding.DataBinderMapperImpl
at android.databinding.DataBindingUtil.<clinit>(DataBindingUtil.java:32)
at com.sc.databinding.LandingFragmentBinding.inflate(LandingFragmentBinding.java:42)
at com.sc.ui.landing.LandingFragment.onCreateView(LandingFragment.kt:32)
...
android data-binding kotlin android-espresso
2个回答
© www.soinside.com 2019 - 2024. All rights reserved.