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.
Find location
First of all, we need to find the exact location and/or cause for the error,
which can be done with different approaches (see below).
Find by inspecting merged-manifest (approach #1)
You can find it by doing the steps:
Set target SDK to 30 (to silence 31+ errors).
Open application's manifest (
AndroidManifest.xml
) and click on "Merged Manifest
" tab on bottom of your edit pane:Which if you configure
build.gradle
like:allprojects {
buildDir = "${rootProject.rootDir}/build/${project.name}"
}Something similar should be in a sub-path like:
build/my-app/intermediates/merged_manifest/debug/AndroidManifest.xml
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)
Search if there's any entry of type activity, service, receiver, or provider which does not have an
exported
attribute, and for each entry follow below "Fix found entries" section (or see once for how to setexported
attribute).Set target SDK back to 31 (or whatever it was before changing to 30).
Find by console logs (approach #2)
In Git-bash run something like:
./gradlew assembleDebug --stacktrace --info | tee my-logs.txt
Open
my-logs.txt
file (which previous step created, in your preferred text-editor).Now, the exact location is hidden in the logs,
hence search in the createdmy-logs.txt
file,
for these keywords:activity#
service#
receiver#
provider#
Which should find something like:
activity#androidx.test.core.app.InstrumentationActivityInvoker$BootstrapActivity
ADDED from [androidx.test:core:1.2.0] C:\Users\Admin\.gradle\caches\transforms-3\709730c74fe4dc9f8fd991eb4d1c2adc\transformed\jetified-core-1.2.0\AndroidManifest.xml:27:9-33:20
- Open
AndroidManifest.xml
file that previous steps did find, search if there's any entry of typeactivity
,service
,receiver
, orprovider
which does not have anexported
attribute, and see below "Fix found entries" section (for how to set each entriesexported
attribute).
Note that (at time of writting) passing
--stacktrace
alone did not include location info ;-)
Fix found entries
If the real (not build-generated) source of found entry is in root-project's manifest (or somewhere you can alter),
set exported
attribute to corresponding need (which is normally false
) therein directly, like:
<receiver
android:name="<name_of_the_entry>"
android:exported="false or true"
tools:node="merge" />
Note that both
android:exported="..."
andtools:node="merge"
are set above.
But if found entry's specification is written in the manifest of a third-party library (which's real-source you can't alter),
override the specification of said library by adding it to our root-project's manifest, for example like:
<provider
android:name="com.squareup.picasso.PicassoProvider"
android:exported="false"
tools:node="merge"
tools:overrideLibrary="com.squareup.picasso.picasso" />
Note that this time
tools:overrideLibrary="..."
is set as well.For more information see Documentation,
and/or Similar issue in a SDK.
android:exported needs to be explicitly specified for receiver. Apps targeting Android 12 and higher In Flutter
Please make
android:exported="false"
in all activities, services, receivers except MainActivity
`android:exported needs to be explicitly specified for activity` even though I have specified it
In addition to android:exported="true"
The post android:exported needs to be explicitly specified for . Apps targeting Android 12 and higher are required to specify also mention needing tools:node="merge"
or possibly tools:node="replace"
See Android Documentation regarding Inspect the merged manifest and find conflicts
I also believe you need xmlns:tools="http://schemas.android.com/tools"
property in your manifest
XML tag as stated in merge rule markers
android:exported added but still getting error Apps targeting Android 12 and higher are required to specify an explicit value for android:exported
To solve this error in target sdk 31-
1.First of all set target sdk to 30
2.Then go to the merged manifest
3.Find if there’s any activity, service, receiver or provider that does not have android:exported
set.Override all those entries and set their android:exported
to true or false.
4.set target sdk back to 31 and run project
Android:exported needs to be explicitly specified for service.Apps targeting Android 12 and higher
The reason is because some of the dependency libraries that you're using have elements which do not have "android:exported" attribute.
You need to do this:
Lower the version in your gradle to 30 and sync and build.
Go to your AndroidManifest.xml file and click on "Merged Manifest".
Find items such as Activity, Receiver, Service, etc that don't have "android:exported" attribute.
Then add them to your AndroidManifest.xml file in this way.
<activity
android:name="SomeActivity"
android:exported="false"
tools:node="merge"
tools:replace="android:exported" />
Now you can increase your version to 31.
I fixed it that way ! Hope it helps you !
Android Studio error: Manifest merger failed: Apps targeting Android 12
You need to specify android:exported="false"
or android:exported="true"
Manifest:
<activity
android:name=".MainActivity"
android:exported="true"
android:theme="@style/Theme.MyApplication.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
as mentioned in the document:
If your app targets Android 12 and contains activities, services, or
broadcast receivers that use intent filters, you must explicitly
declare the android: exported attribute for these app components.
Warning: If an activity, service, or broadcast receiver uses intent
filters and doesn't have an explicitly-declared value for
android:exported, your app can't be installed on a device that runs
Android 12.
Also check when to use true/false for the 'android:exported' value.
Related Topics
How to Get Eclipse to Use a Different Compiler Version for Java
Getextractedtext on Inactive Inputconnection Warning on Android
Code Will Only Return 0.0, 0.0 Gps Coordinate While Throwing Nullpointerexception
Android: Countdowntimer Skips Last Ontick()!
Android Overlay a View Ontop of Everything
How to Implement Enum with Generics
Listening for Input Without Focus in Java
How to Use Jndi Datasource Provided by Tomcat in Spring
How to Populate a Drop Down with a List Using Thymeleaf and Spring
How to Get String Array from Arrays.Xml File
Opengl Extensions Available on Different Android Devices
Sort Data to Recyclerview Based on Latest Date from Firebase