android:exported needs to be explicitly specified for <activity>. Apps targeting Android 12 and higher are required to specify
I had this issue and one of the libraries I used wasn't setting it correctly.
You can find it by doing the steps:
- Set target SDK for 30
- Go to the merged manifest:
- Go to the individual manifest file of all the libraries (You can skip this step if the merged manifest is created and you can just look into the merged manifest)
- Find if there's any activity, service, receiver, or provider that does not have an
exported
and set it to corresponding needs. We can override the specification written in the manifest of a library by adding it to our application's manifest. More information : Documentation, Similar issue in a SDK. - Set target SDK for 31
- Override all the entries you found like this:
<receiver android:name="<name_of_the_entry>"
android:exported="false or true"
tools:node="merge" />
Fixing such issue can be a bit cumbersome, cause the IDE doesn't provide details on the error, it just tells you that there is an Activity, Receiver or Service without the exported parameter, but does not tell you which one it is. As Jakos recommend, you can manually check the merged manifest, or use this script in case the generated manifest is too large.
After that you can modify the affected entries by adding the exported attribute if it is part of your project, or override it if it's part of a library with:
<activity android:name="name_of_the_activity_inside_library>"
android:exported="false|true"
tools:node="merge" />
UPDATE: The manifest merge task seems to fail without generating the manifest when targeting android S and this problems are detected, so my advise is to compile the app using a targetSdk lower than 31, and then inspect the generated manifest either manually or using the script I linked. (you can find the merged manifest on the build folder or by inspecting the generated apk)
Check your build.gradle
file for:
debugImplementation "androidx.fragment:fragment-testing:<version>"
and if present change it to:
androidTestImplementation "androidx.fragment:fragment-testing:<version>"
It should always have been androidTestImplementation
but there was some dependency issue before and it was necessary to use debugImplementation
as a workaround. The IDE actually prompted you to do this. But evidently it is fixed for SDK 31, and if you leave it as debugImplementation you get the android:exported
-missing manifest error which comes from a manifest.xml
in a dependent package.
For instrumented test, if you are using compose test, make sure you add androidx.test.ext:junit
in addition to compose.ui dependencies
androidTestImplementation "androidx.test.ext:junit:1.1.3"
androidTestImplementation "androidx.compose.ui:ui-test-junit4:1.0.4"
After the build has failed go to AndroidManifest.xml and in the bottom click merged manifest see which activities which have intent-filter
but don't have exported=true
attribute.
Or you can just get the activities which are giving error.
Add these activities to your App manifest with android:exported="true"
and app tools:node="merge"
this will add exported attribute to the activities giving error.
Example:
<activity
android:name="<activity which is giving error>"
android:exported="true"
tools:node="merge" />
You will have to do this once, you can remove this once the library developers update their libs.