android:exported needs to be explicitly specified for . Apps targeting Android 12 and higher are required to specify

We Are Going To Discuss About android:exported needs to be explicitly specified for . Apps targeting Android 12 and higher are required to specify. So lets Start this Java Article.

android:exported needs to be explicitly specified for . Apps targeting Android 12 and higher are required to specify

  1. android:exported needs to be explicitly specified for . Apps targeting Android 12 and higher are required to specify

    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)

  2. exported needs to be explicitly specified for . Apps targeting Android 12 and higher are required to specify

    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)

Solution 1

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: Merged Manifest in Android Studio
  • 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" />

Original Author Of This Content

Solution 2

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)

Original Author Of This Content

Solution 3

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.

Original Author Of This Content

Solution 4

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"

Original Author Of This Content

Conclusion

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

Siddharth

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment