paparazzi icon indicating copy to clipboard operation
paparazzi copied to clipboard

java.lang.NoClassDefFoundError: androidx/databinding/DataBinderMapperImpl

Open mike-donald opened this issue 2 years ago • 4 comments

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

  1. Create a view with Recyclerview.
  2. Populate the data in Unit tests
  3. Take a snapshot
  4. 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 avatar Jun 16 '22 16:06 mike-donald

@mike-donald , I had the same issue and adding kaptTest "androidx.databinding:databinding-compiler:7.2.0" solved the problem for us

pazzinivinicius avatar Jun 20 '22 10:06 pazzinivinicius

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 avatar Jun 20 '22 18:06 mike-donald

@mike-donald yes, in the module's build.gradle

pazzinivinicius avatar Jun 21 '22 07:06 pazzinivinicius

@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!

fcduarte avatar Aug 08 '22 14:08 fcduarte

@pazzinivinicius 's response seems like the fix. Please reopen with a repro, if the issue still occurs.

jrodbx avatar Sep 05 '22 05:09 jrodbx

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)
    }

laurynas-bartkus-tg avatar Oct 05 '22 14:10 laurynas-bartkus-tg