'"RuntimeException: Could not launch activity...Unable to resolve activity for Intent" when running Jetpack Compose UI tests with createComposeRule
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 }
...
Solution 1:[1]
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.
Solution 2:[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.
Solution 3:[3]
You need to add
<activity android:name="androidx.activity.ComponentActivity" />
to your manifest.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mahozad |
| Solution 2 | Ryan M |
| Solution 3 | André Ramon |
