Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Error : "NoClassDefFoundError: Failed resolution of: Landroidx/databinding/DataBinderMapperImpl" when running Espresso Instrumentation Test [duplicate]

Data binding setup:

apply plugin: 'kotlin-kapt'

android {
    dataBinding {
        enabled = true
    }
}

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

The fragment class which uses data binding:

class LandingFragment : Fragment(), Injectable {

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

Every time the Espresso test is run for this fragment, I get the following exception:

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)
...
like image 495
makovkastar Avatar asked Apr 04 '18 14:04

makovkastar


2 Answers

A bit late, but I resolved this issue by adding DataBinding compiler with kapt as a test dependency:

kaptAndroidTest 'androidx.databinding:databinding-compiler:3.3.2'

Or the version not from AndroidX if your project is not using Jetpack yet.

like image 99
Rafael Toledo Avatar answered Oct 20 '22 00:10

Rafael Toledo


Add

kaptTest "androidx.databinding:databinding-compiler:+"

to dependencies on build.gradle files of all your modules.

like image 32
Osman Yalın Avatar answered Oct 20 '22 00:10

Osman Yalın