我正在具有以下模块的多模块项目中运行Espresso测试: :app,:core。我在两个模块中都添加了以下代码段:-
dataBinding {
enabled = true
}
该应用运行正常。但是当我运行Espresso测试(在:core模块中)时,出现以下错误:
java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/databinding/DataBinderMapperImpl;
at androidx.databinding.DataBindingUtil.<clinit>(DataBindingUtil.java:32)
at androidx.databinding.DataBindingUtil.getDefaultComponent(DataBindingUtil.java:65)
at com.example.core.databinding.MyProductFragmentBinding.inflate(MyProductFragmentBinding.java:73)
at com.example.core.screens.collection.MyProductFragment.onCreateView(MyProductFragment.kt:29)
at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2544)
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:884)
at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManagerImpl.java:1235)
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:1301)
at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:710)
at androidx.fragment.app.FragmentManagerImpl.executeOps(FragmentManagerImpl.java:2071)
at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(FragmentManagerImpl.java:1861)
at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManagerImpl.java:1816)
at androidx.fragment.app.FragmentManagerImpl.execSingleAction(FragmentManagerImpl.java:1693)
at androidx.fragment.app.BackStackRecord.commitNow(BackStackRecord.java:554)
at androidx.fragment.app.testing.FragmentScenario$1.perform(FragmentScenario.java:307)
at androidx.fragment.app.testing.FragmentScenario$1.perform(FragmentScenario.java:286)
at androidx.test.core.app.ActivityScenario.lambda$onActivity$1$ActivityScenario(ActivityScenario.java:534)
at androidx.test.core.app.ActivityScenario$$Lambda$0.run(Unknown Source:4)
at android.app.Instrumentation$SyncRunnable.run(Instrumentation.java:2203)
at android.os.Handler.handleCallback(Handler.java:878)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:209)
at android.app.ActivityThread.main(ActivityThread.java:7046)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:486)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.databinding.DataBinderMapperImpl" on path: DexPathList[[zip file "/data/app/com.caastle.platform.core.test-QvTkSvEOT-JWp8dhTG8kIg==/base.apk"],nativeLibraryDirectories=[/data/app/com.caastle.platform.core.test-QvTkSvEOT-JWp8dhTG8kIg==/lib/x86, /system/lib, /system/product/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:195)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
... 26 more
Test running failed: Instrumentation run failed due to 'Process crashed.'