paparazzi
paparazzi copied to clipboard
java.lang.NoClassDefFoundError: androidx/databinding/DataBinderMapperImpl
Description When I test a view with Recylerview in it. As soon as I use listAdapter to add items, I get this error. I tried adding these dependencies in build.gradle in the module, but it didn't help. kaptTest 'androidx.databinding:databinding-compiler:7.4.0-alpha04' kaptAndroidTest "androidx.databinding:databinding-compiler:7.4.0-alpha04"
Steps to Reproduce
- Create a view with Recyclerview.
- Populate the data in Unit tests
- Take a snapshot
- java.lang.NoClassDefFoundError: androidx/databinding/DataBinderMapperImpl
Expected behavior Recyclerview should work in snapshot
Additional information:
- Paparazzi Version: 1.0.0
- OS: Android
- Compile SDK: 29
- Gradle Version: 7.4.1+
- Android Gradle Plugin Version: 7.0.4
@mike-donald , I had the same issue and adding kaptTest "androidx.databinding:databinding-compiler:7.2.0" solved the problem for us
Thank you @pazzinivinicius . I actually tried 7.2.0, 7.2.1, 7.4.0-alpha04. It is still returning the same error. Where are you putting the kaptTest, is it in the build.gradle in the module?
app.cash.paparazzi.internal.PaparazziLogger error
SEVERE: broken: View measure failed
java.lang.NoClassDefFoundError: androidx/databinding/DataBinderMapperImpl
@mike-donald yes, in the module's build.gradle
@mike-donald would you be able to add a unit test at the sample
module that demonstrates the issue? Since it's related to data binding it would be great to see if a simple implementation with Paparazzi's current code shows this issue, thanks!
@pazzinivinicius 's response seems like the fix. Please reopen with a repro, if the issue still occurs.
I want to leave solution for this error in case anyone encounters this again.. Long story short,
java.lang.NoClassDefFoundError: androidx/databinding/DataBinderMapperImpl
Means that your unit test class is not able generate/reach dataBinding classes, in order to make it work add this:
testOptions {
unitTests {
//allow unit tests to reach data binding generated classes
isIncludeAndroidResources = true
}
}
When you do that, you will most likely encounter other errors, something similar to:
error: cannot find symbol FeatureBindingImpl;
No worries, it means that you are missing kapt, so apply this to your library:
plugins {
id("com.android.library")
id("org.jetbrains.kotlin.android")
id("kotlin-kapt") //prevents error: cannot find symbol FeatureBindingImpl;
id("app.cash.paparazzi")
}
...
dependencies {
....
//allows unit tests to compile databinding
kapt("androidx.databinding:databinding-compiler:7.3.0")
kaptTest("androidx.databinding:databinding-compiler:7.3.0")
}
And for the most part, you should be good, in case you are not able to inflate material components, add this:
testImplementation("com.google.android.material:material:1.6.1")
and in case it says that you need to inherit app component theme, use this in your UI test.
@Test
fun testXFeature() {
val context = ContextThemeWrapper(paparazzi.context, R.style.AppTheme) //which parent is required theme
val view = DataBindingUtil.inflate<FeatureBinding>(
LayoutInflater.from(context),
R.layout.screen_feature,
null,
false
)
view.something = "something"
paparazzi.snapshot(view.root)
}