java.lang.NoClassDefFoundError: android.databinding.DataBinderMapperImpl when running Espresso tests

前端 未结 5 1299
刺人心
刺人心 2021-01-04 13:04

Data binding setup:

apply plugin: \'kotlin-kapt\'

android {
    dataBinding {
        enabled = true
    }
}

dependencies {
    kapt \"com.android.databind         


        
相关标签:
5条回答
  • 2021-01-04 13:18

    Add

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

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

    0 讨论(0)
  • 2021-01-04 13:20

    I have the same this issue, and fixed by adding

    kapt {
        generateStubs = true
    }
    

    in build.gradle app (all module if using dataBinding)

    apply plugin: 'kotlin-kapt'
    
    android {
    ...
        dataBinding {
            enabled = true
        }
    }
    
    kapt {
        generateStubs = true
    }
    
    dependencies {
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        ...
        implementation "androidx.core:core-ktx:+"
        implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
        kapt "com.android.databinding:compiler:$android_plugin_version"
    
    }
    

    In build.gradle project

    buildscript {
        ext.kotlin_version = '1.3.70'
        ext.android_plugin_version = '3.5.2'
        repositories {
            google()
            jcenter()
    
        }
        dependencies {
            classpath "com.android.tools.build:gradle:$android_plugin_version"
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        }
    }
    
    0 讨论(0)
  • 2021-01-04 13:27

    Try to add the android-apt plugin as per this stackoverflow answer:

    classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
    
    0 讨论(0)
  • 2021-01-04 13:35

    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.

    0 讨论(0)
  • 2021-01-04 13:36

    I run into this very error. I did 2 things: 1. Added kaptAndroidTest 'androidx.databinding:databinding-compiler:3.5.1' in gradle 2. Used the databinding, that is to say, I create a fake bool variable and injected it for real in a view. It would seem that you cannot just use databinding for retrieving the views instead of issuing the dreaded findViewById. You have to use it at least once in your module. Once you use it you are fine for all the other classes in your module.

    0 讨论(0)
提交回复
热议问题