“RuntimeException:无法启动活动...无法解析 Intent 的活动";使用 createComposeRule 运行 Jetpack Compose UI 测试时 [英] "RuntimeException: Could not launch activity...Unable to resolve activity for Intent" when running Jetpack Compose UI tests with createComposeRule
问题描述
使用 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 }
...
推荐答案
OP 问题是关于 createComposeRule()
的使用,它不需要自定义活动(它使用 ComposeActivity
引擎盖下).
The OP question is about the use of createComposeRule()
which doesn't require a custom activity (it uses ComposeActivity
under the hood).
在这种情况下,您需要在您的 gradle 文件中包含以下内容:
In this case you need to include this below in your gradle file:
debugImplementation "androidx.compose.ui:ui-test-manifest:1.0.0-beta05"
如果您查看该包的内容,它只是一个 AndroidManifest.xml
,带有
条目,用于 androidx.activity.ComponentActivity
.
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
.
这篇关于“RuntimeException:无法启动活动...无法解析 Intent 的活动";使用 createComposeRule 运行 Jetpack Compose UI 测试时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!