Home > Software engineering >  NoClassDefFoundError: Failed resolution of: Landroidx/tracing/Trace
NoClassDefFoundError: Failed resolution of: Landroidx/tracing/Trace

Time:05-05

When I start a basic androidTest my app crashes:

@Test
fun myTest() {
    val scenario = ActivityScenario.launch(MainActivity::class.java)
    // ...
}

This is the stacktrace:

2022-04-27 08:43:38.438 28069-28069/myapp.test E/AndroidRuntime: FATAL EXCEPTION: main Process: myapp.debug.test, PID: 28069 java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/tracing/Trace; at androidx.startup.AppInitializer.discoverAndInitialize(AppInitializer.java:210) at androidx.startup.InitializationProvider.onCreate(InitializationProvider.java:45) at android.content.ContentProvider.attachInfo(ContentProvider.java:1919) at android.content.ContentProvider.attachInfo(ContentProvider.java:1894) at android.app.ActivityThread.installProvider(ActivityThread.java:6273) at android.app.ActivityThread.installContentProviders(ActivityThread.java:5839) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5747) at android.app.ActivityThread.-wrap1(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1669) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6528) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.tracing.Trace" on path: DexPathList[[zip file "/system/framework/android.test.mock.jar", zip file "/system/framework/android.test.runner.jar", zip file "/data/app/myapp.debug.test-4n8SpMC8qbT8ak5Kl9hJcQ==/base.apk"],nativeLibraryDirectories=[/data/app/myapp.debug.test-4n8SpMC8qbT8ak5Kl9hJcQ==/lib/arm64, /system/lib64, /vendor/lib64]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125) at java.lang.ClassLoader.loadClass(ClassLoader.java:379) at java.lang.ClassLoader.loadClass(ClassLoader.java:312) at androidx.startup.AppInitializer.discoverAndInitialize(AppInitializer.java:210)  at androidx.startup.InitializationProvider.onCreate(InitializationProvider.java:45)  at android.content.ContentProvider.attachInfo(ContentProvider.java:1919)  at android.content.ContentProvider.attachInfo(ContentProvider.java:1894)  at android.app.ActivityThread.installProvider(ActivityThread.java:6273)  at android.app.ActivityThread.installContentProviders(ActivityThread.java:5839)  at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5747)  at android.app.ActivityThread.-wrap1(Unknown Source:0)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1669)  at android.os.Handler.dispatchMessage(Handler.java:106)  at android.os.Looper.loop(Looper.java:164)  at android.app.ActivityThread.main(ActivityThread.java:6528)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

The following dependencies cause the problem:

androidTestImplementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
androidTestImplementation 'androidx.lifecycle:lifecycle-process:2.4.0'
androidTestImplementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'

CodePudding user response:

Use the dependencies which are listed in the example on this page:

https://developer.android.com/jetpack/androidx/releases/lifecycle#declaring_dependencies

  • Related