13

Running tests with createComposeRule and hitting a stack trace like (irrelevant parts omitted):

java.lang.RuntimeException: Could not launch activity
at androidx.test.runner.MonitoringInstrumentation.startActivitySync(MonitoringInstrumentation.java:495)
...
Caused by: java.lang.RuntimeException: Unable to resolve activity for: Intent { act=android.intent.action.MAIN flg=0x14000000 cmp=my.app.package.name.here/android.app.Activity }
...
0

3 Answers 3

35

The OP question is about the use of createComposeRule() which doesn't require a custom activity (it uses ComposeActivity under the hood).

In this case you need to include this below in your gradle file:

debugImplementation("androidx.compose.ui:ui-test-manifest:1.0.0-beta05")

If you take a look at the contents of that package, it's simply an AndroidManifest.xml with an <activity/> entry for androidx.activity.ComponentActivity.

3
  • 1
    I've added the debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version". to solve the problem Nov 25, 2021 at 15:25
  • I lost 3 days figuring this out. I thought adding the manifest to androidTestImplementation would have the same effect, but looks like you can't do that. So what this basically does it gives you a custom activity (androidx.activity.ComponentActivity) from which you can run your tests, but you have to include it via debugImplementation.
    – Tooroop
    Nov 28, 2021 at 14:56
  • FWIW, I had to add it as implementation() after moving some androidTest code into a module
    – kenyee
    Oct 30, 2022 at 20:21
3

You need to add

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

to your manifest.

1
  • I'm running an Android test using createComposeRule() and it works when "androidx.compose.ui:ui-test-manifest:$compose_version" is added, as above. I haven't added ComponentActivity to the manifest.
    – Ewan
    Nov 21, 2022 at 12:13
2

You need declare an Activity with name android.app.Activity in your AndroidManifest.xml for the Compose UI tests to use to host the content. Add the following within your <application> tag:

<activity android:name="android.app.Activity" android:theme="@style/your_app_theme_here"/>

substituting your_app_theme_here with a theme that exists in your app.

Not the answer you're looking for? Browse other questions tagged or ask your own question.