4

I've followed the jetpack compose navigation codelab. Everything was going well until it came to testing the NavHost in step 7. When trying to run the tests, I get the following error and stack trace :

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)
    .....

There is a problem with the merged Manifest, but within the androidTest directory I have no Manifest, so as far as i can see, I have no control over what's in the generated one.

I can see the Merged Manifest from the main directory and there are no errors present in there. I can see the generated manifest in the build folder and it does display a load of errors.

Is there some technique I could use to attempt to resolve this?

EDIT: Further investigation shows the problem as

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 has been declared in the main/AndroidManifest.xml as expected, and it is also present in each component in the generated merged manifest for androidTest.

Chris
  • 4,662
  • 2
  • 19
  • 27

1 Answers1

3

I found a solution here. Adding the following dependency should solve the problem:

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

From the comment:

Essentially, Android 12 introduced the requirement to specify the android:exported value on all activities when you have an intent-filter defined. This is causing issues right now because some libraries haven't updated to handle this change properly.

Mahmudul Hasan Shohag
  • 2,203
  • 1
  • 22
  • 30