尝试运行 jetpack compose 仪器测试时如何克服此构建错误
Posted
技术标签:
【中文标题】尝试运行 jetpack compose 仪器测试时如何克服此构建错误【英文标题】:How to overcome this build error when trying to run jetpack compose instrumentation tests 【发布时间】:2021-12-11 06:54:45 【问题描述】:我关注了jetpack compose navigation codelab。在第 7 步测试 NavHost 之前,一切都很顺利。 尝试运行测试时,我收到以下错误和堆栈跟踪:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:processDebugandroidTestManifest'.
> Manifest merger failed with multiple errors, see logs
* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:processDebugAndroidTestManifest'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.lambda$executeIfValid$1(ExecuteActionsTaskExecuter.java:188)
at org.gradle.internal.Try$Failure.ifSuccessfulOrElse(Try.java:263)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeIfValid(ExecuteActionsTaskExecuter.java:186)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:174)
at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:109)
.....
Caused by: java.lang.RuntimeException: Manifest merger failed with multiple errors, see logs
at com.android.build.gradle.tasks.ProcessTestManifest.handleMergingResult(ProcessTestManifest.kt:331)
at com.android.build.gradle.tasks.ProcessTestManifest.mergeManifestsForTestVariant(ProcessTestManifest.kt:301)
at com.android.build.gradle.tasks.ProcessTestManifest.doFullTaskAction(ProcessTestManifest.kt:111)
.....
合并的 Manifest 存在问题,但在 androidTest
目录中我没有 Manifest,所以据我所知,我无法控制生成的 Manifest 中的内容。
我可以从main
目录中看到合并清单,并且其中没有错误。我可以在 build 文件夹中看到生成的清单,它确实显示了很多错误。
我可以使用一些技术来尝试解决这个问题吗?
编辑: 进一步调查显示问题为
android-compose-codelabs/NavigationCodelab/app/build/intermediates/tmp/manifest/androidTest/debug/tempFile1ProcessTestManifest6269584048200983460.xml Error:
android:exported needs to be explicitly specified for <activity>. Apps targeting Android 12 and higher are required to specify an explicit value for `android:exported` when the corresponding component has an intent filter defined. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details.
android:exported
已按预期在main/AndroidManifest.xml
中声明,并且它也存在于为androidTest
生成的合并清单中的每个组件中。
【问题讨论】:
【参考方案1】:我找到了解决方案here。添加以下依赖项应该可以解决问题:
androidTestImplementation "androidx.test.ext:junit:1.1.3"
来自评论:
基本上,Android 12 引入了在定义了意图过滤器时在所有活动上指定 android:exported 值的要求。这导致了现在的问题,因为一些库尚未更新以正确处理此更改。
【讨论】:
以上是关于尝试运行 jetpack compose 仪器测试时如何克服此构建错误的主要内容,如果未能解决你的问题,请参考以下文章