4

我遵循了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)
    .....

合并的清单存在问题,但在androidTest目录中我没有清单,所以据我所知,我无法控制生成的清单中的内容。

我可以从目录中看到合并清单,main并且那里没有错误。我可以在构建文件夹中看到生成的清单,它确实显示了很多错误。

有什么技术可以用来尝试解决这个问题吗?

编辑:进一步调查显示问题为

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:exportedmain/AndroidManifest.xml按预期声明,并且它也存在于生成的合并清单中的每个组件中androidTest

4

1 回答 1

2

我在这里找到了解决方案。添加以下依赖项应该可以解决问题:

androidTestImplementation "androidx.test.ext:junit:1.1.3"

来自评论:

本质上,Android 12 引入了在定义了意图过滤器时在所有活动上指定 android:exported 值的要求。这正在引起问题,因为某些库尚未更新以正确处理此更改。

于 2021-12-07T20:08:50.727 回答