Home > Net >  ComponentActivity ClassNotFoundException when trying to setup Instrumented tests, with Android Compo
ComponentActivity ClassNotFoundException when trying to setup Instrumented tests, with Android Compo

Time:02-10

I'm setting up my first instrumented unit-test and getting an obscure crash in logcat.

The emulator starts and immediately crashes when the app tries to open and the unit test doesn't even run because the application wasn't in the right state.

2022-02-09 19:30:37.116 25764-25764/com.anotherday.day17.test E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.anotherday.day17.test, PID: 25764
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.anotherday.day17.test/androidx.activity.ComponentActivity}: java.lang.ClassNotFoundException: Didn't find class "androidx.activity.ComponentActivity" on path: DexPathList[[zip file "/data/app/~~NodQZs7v97-vYTPte3T7UQ==/com.anotherday.day17.test-25XuwB3vTwyNbSX-nlETDQ==/base.apk"],

It seems to be looking for androidx.activity.ComponentActivity which is defined in the following gradle dependency:

implementation 'androidx.activity:activity-compose:1.3.1'

Not sure where else to look, here's my first test and my project in git: https://github.com/davida5/ComposeNotepad/blob/main/app/src/androidTest/java/com/anotherday/day17/navigation/NavigatorTest.kt

CodePudding user response:

Add the following to your AndroidManifest.xml:

<manifest>
  <application>
    ...
    <activity android:name="androidx.activity.ComponentActivity" />
    ...
  <application>
<manifest>

If you have a specific Manifest file for the debug variant, add this to that file instead, as this change isn't needed for the release variant.

  •  Tags:  
  • Related