45

I have added android:exported="true" to my only activity in manifest but still getting below error after updating compile sdk and target sdk version to 31.I also tried rebuilding the project , invalidating cache and restart but that didn't helped

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

AndroidManifest File

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.xyz.abc">

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

    <application
        android:name=".framework.presentation.BaseApplication"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name="com.xyz.presentation.MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Merged manifest error

Other Manifest Files (Included in merge, but did not contribute any elements) firebase-installations:17.0.0 manifest, versionedparcelable:1.1.1 manifest, runtime:1.0.1 manifest, test:core:1.2.0 manifest, loader:1.0.0 manifest, facebook-share:11.1.0 manifest, leakcanary:leaksentry:2.0-alpha-3 manifest, material-dialogs:input:3.2.1 manifest, material-icons-extended:1.0.0 manifest, play-services-stats:17.0.0 manifest, interpolator:1.0.0 manifest, activity-compose:1.3.1 manifest, material-ripple:1.0.0 manifest, foundation:1.0.0 manifest, asynclayoutinflater:1.0.0 manifest, savedstate-ktx:1.1.0 manifest, navigation-dynamic-features-fragment:2.3.5 manifest, firebase-ui-auth:7.2.0 manifest, animation:1.0.1 manifest, animation-core:1.0.1 manifest, installreferrer:1.0 manifest, firebase-crashlytics:18.0.0 manifest, ui:1.0.1 manifest, lifecycle-viewmodel-savedstate:2.3.1 manifest, play-services-auth-base:17.0.0 manifest, hilt-android:2.35.1 manifest, material-dialogs:core:3.2.1 manifest, AndroidManifest.xml navigation file, savedstate:1.1.0 manifest, cursoradapter:1.0.0 manifest, sqlite-framework:2.0.1 manifest, room-ktx:2.1.0 manifest, leakcanary-android-core:2.0-alpha-3 manifest, AndroidManifest.xml navigation file, media:1.0.0 manifest, coordinatorlayout:1.1.0 manifest, legacy-support-core-utils:1.0.0 manifest, lifecycle-runtime:2.3.1 manifest, coil-kt:coil:1.3.1 manifest, ui-tooling-preview:1.0.0 manifest, facebook-core:11.1.0 manifest, core:1.6.0 manifest, material:1.0.0 manifest, firebase-common:20.0.0 manifest, documentfile:1.0.0 manifest, lifecycle-viewmodel-compose:2.4.0-beta01 manifest, play-services-base:17.1.0 manifest, ui-tooling-data:1.0.0 manifest, coil-base:1.3.1 manifest, firebase-analytics-ktx:19.0.0 manifest, localbroadcastmanager:1.0.0 manifest, swiperefreshlayout:1.1.0-alpha03 manifest, constraintlayout-compose:1.0.0-beta02 manifest, core-ktx:1.6.0 manifest, firebase-database-collection:18.0.0 manifest, coil-compose-base:1.3.1 manifest, activity:1.3.1 manifest, AndroidManifest.xml navigation file, facebook-messenger:11.1.0 manifest, print:1.0.0 manifest, customview:1.1.0 manifest, material-icons-core:1.0.0 manifest, play-services-measurement-sdk:19.0.0 manifest, fragment:1.3.4 manifest, firebase-appcheck-interop:16.0.0-beta01 manifest, facebook-login:11.1.0 manifest, cardview:1.0.0 manifest, runtime-rxjava2:1.0.0 manifest, viewpager2:1.0.0 manifest, play-services-ads-identifier:17.0.0 manifest, play-services-measurement-impl:19.0.0 manifest, lifecycle-livedata-core:2.3.1 manifest, play-services-safetynet:17.0.0 manifest, AndroidManifest.xml navigation file, lifecycle-viewmodel-ktx:2.3.1 manifest, transport-backend-cct:3.0.0 manifest, fragment-ktx:1.2.4 manifest, appcompat:1.3.0 manifest, transport-runtime:3.0.0 manifest, lifecycle-livedata-core-ktx:2.2.0 manifest, firebase-firestore-ktx:23.0.0 manifest, legacy-support-v4:1.0.0 manifest, play-services-basement:17.1.1 manifest, firebase-storage:20.0.0 manifest, play-services-auth-api-phone:17.4.0 manifest, leakcanary-android:2.0-alpha-3 manifest, firebase-auth-interop:20.0.0 manifest, lifecycle-viewmodel:2.3.1 manifest, browser:1.0.0 manifest, firebase-auth:21.0.1 manifest, material:1.2.1 manifest, slidingpanelayout:1.0.0 manifest, vectordrawable:1.1.0 manifest, recyclerview:1.1.0 manifest, play-services-auth:19.0.0 manifest, room-runtime:2.1.0 manifest, dagger-lint-aar:2.35.1 manifest, navigation-dynamic-features-runtime:2.3.5 manifest, play-services-measurement-api:19.0.0 manifest, firebase-encoders-json:18.0.0 manifest, sqlite:2.0.1 manifest, facebook-android-sdk:11.1.0 manifest, firebase-components:17.0.0 manifest, transport-api:3.0.0 manifest, protolite-well-known-types:18.0.0 manifest, markdown-processor:0.1.3 manifest, play-services-measurement-base:19.0.0 manifest, firebase-common-ktx:20.0.0 manifest, activity-ktx:1.3.1 manifest, firebase-crashlytics-ktx:18.0.0 manifest, coil-compose:1.3.1 manifest, multidex:2.0.1 manifest, core-runtime:2.1.0 manifest, fragment-testing:1.2.0 manifest, ui-graphics:1.0.1 manifest, AndroidManifest.xml navigation file, ui-tooling:1.0.0 manifest, grpc-android:1.28.0 manifest, ui-unit:1.0.1 manifest, play-services-measurement:19.0.0 manifest, play:core:1.9.1 manifest, annotation-experimental:1.1.0 manifest, play-services-measurement-sdk-api:19.0.0 manifest, play-services-tasks:17.0.0 manifest, firebase-analytics:19.0.0 manifest, facebook-common:11.1.0 manifest, drawerlayout:1.1.1 manifest, AndroidManifest.xml navigation file, navigation-compose:2.4.0-alpha09 manifest, facebook-gamingservices:11.1.0 manifest, firebase-firestore:23.0.0 manifest, lifecycle-livedata:2.2.0 manifest, legacy-support-core-ui:1.0.0 manifest, test:monitor:1.2.0 manifest, AndroidManifest.xml navigation file, facebook-applinks:11.1.0 manifest, viewpager:1.0.0 manifest, ui-geometry:1.0.1 manifest, lifecycle-runtime-ktx:2.3.1 manifest, constraintlayout:2.0.4 manifest, ui-text:1.0.1 manifest, AndroidManifest.xml navigation file, firebase-installations-interop:17.0.0 manifest, transition:1.3.0 manifest, foundation-layout:1.0.1 manifest, appcompat-resources:1.3.1 manifest, runtime-livedata:1.0.0 manifest, runtime-saveable:1.0.1 manifest, firebase-measurement-connector:19.0.0 manifest, vectordrawable-animated:1.1.0 manifest, main nav_graph.xml navigation file Merging Errors: Error: android:exported needs to be explicitly specified for . 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. Dairy.app main manifest (this file) Error: android:exported needs to be explicitly specified for . 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. Dairy.app main manifest (this file) Error: android:exported needs to be explicitly specified for . 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. Dairy.app main manifest (this file)

TanvirChowdhury
  • 2,498
  • 23
  • 28
Android Developer
  • 9,157
  • 18
  • 82
  • 139
  • 1
    Check your merged manifest (e.g., via the sub-tab in the manifest editor in Android Studio) to see if you have a component from a library that needs to be addressed. – CommonsWare Sep 22 '21 at 15:52
  • @CommonsWare Merged manifest has nothng to show with same error-"Error: android:exported needs to be explicitly specified for . 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" – Android Developer Sep 22 '21 at 15:56
  • @CommonsWare If it's due to some library i believe i can't change the manifest for library activities?nd i am not using any other library except basic android libraries like jetpack compose,hilt,room,firebase etc – Android Developer Sep 22 '21 at 15:57
  • @CommonsWare added merged manifest complete error/logs in question. – Android Developer Sep 22 '21 at 16:03
  • 1
    "If it's due to some library i believe i can't change the manifest for library activities" -- you should be able to override the `android:exported` value using `tools:replace`, but you need to identify the components that need it. – CommonsWare Sep 22 '21 at 16:25
  • @AndroidDeveloper I had the same error last week, it was an android library module (without any activity inside) which was causing the problem, but I couldn't understand the reason. I wonder if it is a bug from the framework. – Oya Canli Sep 24 '21 at 17:55
  • Related question: https://stackoverflow.com/q/68554294/8583692 – Mahozad Jan 23 '22 at 11:53

23 Answers23

42

androidx.test:core library version 1.3.0. Upgrading to version 1.4.0 fixed the issue.

faizy
  • 504
  • 5
  • 17
33

See also android:exported needs to be explicitly specified for <activity>. Apps targeting Android 12 and higher are required to specify.

Thanks to @faizy, @Android Developer I made this.

Upgrade these libraries to new versions:

androidTestImplementation "androidx.test.ext:junit:1.1.3"
androidTestImplementation "androidx.fragment:fragment-testing:1.4.1"
androidTestImplementation "androidx.test:core:1.4.0"

I replaced debugImplementation with androidTestImplementation in these dependencies.

Press Sync Project with Gradle Files. Run the project (or rebuild, or run Lint). Probably it won't help. Then you should make this.

  1. Downgrade targetSdkVersion to 30.

Run the project again. Probably it will compile.

In my case all needed android:exported="true" and android:exported="false" presented in activity, service, receiver and provider of merged AndroidManifest where <intent-filter> occured.

To find merged AndroidManifest, switch to Project and expand app module, then build > intermediates > merged_manifest > debug.

enter image description here

If some android:exported was missing, find a corresponding AndroidManifest and add it there.

  1. Upgrade targetSdkVersion to 31.

Run the project again. If it won't compile, probably you should rebuild the project. As usually, Build > Rebuild Project, File > Invalidate Caches > Invalidate and Restart.

After some time (several gradle syncs, restarts of Android Studio) it compiled.

CoolMind
  • 26,736
  • 15
  • 188
  • 224
  • 1
    Thank you, I just upgraded the dependencies you mentioned and boom it worked! Thanks for saving my time. – MG Developer Oct 04 '22 at 01:24
  • 1
    Thank you. I target to android SDK 33 now and it also works. The secret is the "androidx.test:core:1.4.0". It must be >= 1.4.0. Otherwise it will complain. – flame3 Oct 21 '22 at 10:13
  • 1
    Thank you for the step-by-step to find the mergedmanifest. Turns out it was a 3rd-party library we included. Tip: If you run ./gradlew in the command line, the output tells you which line of the merged manifest is to blame. In my case: `/data/app/vmdl487574943.tmp/base.apk (at Binary XML file line #326): leakcanary.internal.activity.LeakLauncherActivity:` – ArtHare Jun 26 '23 at 13:31
  • Thanks @CoolMind. This worked for me. – Nishara MJ Jul 12 '23 at 15:34
28

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 Developer
  • 9,157
  • 18
  • 82
  • 139
  • Followed the same steps, still i'm facing the same issue in xamarin android – Suchith Apr 21 '22 at 07:14
  • This is probably the wrong place but I also ended up here from a Xamarin error. I was able to resolve by setting `Exported` in my `Activity` attribute: `[Activity(..., Exported = true)]`. @Suchith – garie May 04 '22 at 02:12
  • Per [docs](https://developer.android.com/guide/topics/manifest/activity-element#exported) `exported` should be `true` if external apps will launch the activity, and `false` if not. – garie May 04 '22 at 02:13
  • 1
    For anyone who wonder changing target sdk can be done in `config.xml` file by adding or modifying `` this line. In Ionic 6, merged manifest file can be found at `/platforms/android/app/src/main/AndroidManifest.xml`. – Myo Win Sep 13 '22 at 10:50
  • Could we get more details on this solution? How does one "go to the merged manifest"? How do you check if there are "activity, servicer, receiver, or provider" with android:exported not set? – Meekohi Sep 13 '22 at 15:07
11

The following in app/build.gradle may be the cause.

dependencies {
    debugImplementation androidx.fragment:fragment-testing:<1.4.0-alpha02 or lower>’
}
Solution 1

Update fragment-testing to 1.4.0-alpha03 or higher.

Solution 2

Add the following to AndroidManifest.xml.

<manifest>
    <application>
        <activity
            android:name="androidx.test.core.app.InstrumentationActivityInvoker$BootstrapActivity"
            android:exported="false" />
        <activity
            android:name="androidx.test.core.app.InstrumentationActivityInvoker$EmptyActivity"
            android:exported="false" />
        <activity
            android:name="androidx.test.core.app.InstrumentationActivityInvoker$EmptyFloatingActivity"
            android:exported="false" />
    </application>
</manifest>
Tatsuya Fujisaki
  • 1,434
  • 15
  • 18
  • 1
    This worked like a charm man! Actually I even found the issue by checking manifest merger tab. It was this library during upgrade to Android 12, but wanted to make sure I was right. – sud007 Oct 03 '22 at 19:19
9

if you are using flutter , upgrading flutter_local_notifications to the latest version (now is 9.3.2) solved this error for me..

Amer Alzibak
  • 1,489
  • 15
  • 16
8

In my case the problem was with a dependency that strictly uses version 1.0.0 of androidx.test.core, so i can't upgrade it. what i did is to add android:exported="false" to androidx.test.core activity in my main manifest with tools:node="merge" so it can be merged with origin manifest

<activity
            android:name="androidx.test.core.app.InstrumentationActivityInvoker$EmptyActivity"
      android:exported="false"
      tools:node="merge" >
</activity>
<activity
            android:name="androidx.test.core.app.InstrumentationActivityInvoker$EmptyFloatingActivity"
       android:exported="false"
       tools:node="merge">
</activity>

and add the tools namespace.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp"
xmlns:tools="http://schemas.android.com/tools">
TahaOUARRAK
  • 150
  • 3
  • 9
2

Explicitly add the conflicting service to Properties\AndroidManifest.xml file, so that when it is merged in by your plugin it retains the android:exported="true" (or false).

<application>
    ...
    <service android:name="1234.PNFirebaseMessagingService" android:exported="true">
      <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT" />
      </intent-filter>
    </service>
</application>
Meekohi
  • 10,390
  • 6
  • 49
  • 58
  • Updating my dependencies caused all sorts of other issues. Using this method seem to be more successful for my use case. – jackofallcode Apr 04 '23 at 11:44
2

In my case also updating library implementation "androidx.test:core-ktx:1.3.0" to implementation "androidx.test:core-ktx:1.4.0" worked!

It also solved merged manifest errors.

1

I had this problem, I add android:exported="true" and also tools:node="merge" to AndroidManifest.xml but however this error was appeared . I found this is not about my project's Activates rather is about some dependencies, like this:

implementation 'com.najva.sdk:najva-android-sdk:1.3.3'

so check your project dependencies, you will find it surely.

Mori
  • 2,653
  • 18
  • 24
1

if you use ogury Ads put this in youre AndroidManifest file

 <activity
        android:name="io.presage.mraid.browser.ShortcutActivity"
        android:theme="@style/Presage.AdScreen"
        android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
        </intent-filter>
    </activity>
1
  1. android { compileSdk 31

  2. It is important to use latest version of Gradle and Gradle Plugin.

  3. Update your all dependencies to latest version also.

If problem still persists.

  1. Go to your manifest file.
  2. Click merged manifest at the bottom.

Merged Manifest

  1. Check the error at the bottom right side, which dependency is causing the error.
  2. Go to that particular dependency from above mentioned dependencies.

Dependencies

  1. Set android:exported="true" or android:exported="false" where error was mentioned in merged manifest.

Note: Updating that dependency to the latest version will probably also fix that issue. Because in the latest versions of dependenciesexported properties are already set.

  • Using the "Merged Manifest" tab is really useful indeed to identify the activity, service or receiver missing the exported attribute. In my case the problem was caused by the android-beacon-library dependency. Upgrading it to latest version fixed the problem. – matdev Feb 02 '23 at 09:59
1

The solution is very simple, all you have to do is make sure that all of these tags are present...

<activity
        android:exported="true"/>

<receiver
        android:exported="true"/>

<service 
        android:exported="true"/>

just add android:exported="true" to all dont change any thing and If you do not have any of the tags, you must add them all

1

if you are using flutter , upgrading flutter_local_notifications to the latest version (now is 9.3.2) may solve this error..

Dahar Youssef
  • 487
  • 4
  • 10
1

Add these dependencies :

`// To use the androidx.test.core APIs
androidTestImplementation("androidx.test:core:1.5.0")
// Kotlin extensions for androidx.test.core
androidTestImplementation("androidx.test:core-ktx:1.5.0")`
Ali Sidhu
  • 119
  • 9
0

This issue originates from dependencies of project. Right click on intent-filter and select find usages option. Now, in all usage places check that if exported assigned value or nor. If not, assign a value (Even in cache folders for libraries). This will fix issue until cache refresh but you have identifies the libraries creating this problem.

0

I found the answer,

you should add android:exported="true" to all activities, services and receivers in the AndroidManifest.xml file as following.

<activity
        android:name="com.ryanheise.audioservice.AudioServiceActivity"
        android:exported="true"
        android:launchMode="singleTop"
        android:theme="@style/LaunchTheme"
        android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
        android:hardwareAccelerated="true"
        android:usesCleartextTraffic="true"

        android:windowSoftInputMode="adjustResize">


<service android:name="com.ryanheise.audioservice.AudioService"
        android:exported="true"
    >

and for receiver

<receiver android:name="com.ryanheise.audioservice.MediaButtonReceiver"

        android:exported="true"
0

for me the solution was to add this tools:node="merge" behind each android:exported="true" and add xmlns:tools="http://schemas.android.com/tools" property in your manifest balise.

0

Got the solution for this one for Nativescript project. [Tried and Tested]

  1. Search intent-filter in the build project directory (./platforms)

    enter image description here

  2. Check if each intent-filter parent (activity, service, reciever..) have property android:exported="true".

  3. If it does not have android:exported="true" then copy the whole <service/activity/reciever></service/activity/reciever> block

    enter image description here

and put it into AndroidMenifest.xml under App_resource folder, update the tag with android:exported="true" and again build the project.

Should Work Now.

0

I want to answer this question because soon or later I will come back here.

The problem is everywhere in the manifest where a tag <intent-filter> is defined, the tag which contains it must have an attribute android:exported="true|false" because people in google are too lazy to make a default implementation when no value is specified.

The tags that can contain a <intent-filter> are: <activity>, <service>, <receiver> and <provider>. So you can go to your src/main/Manifest.xml and check if everything is well configured.

But this is not enough to assure your build is correct because the final manifest is the result of the merge of multiple manifest files. You can check the file /build/intermediates/merged_manifests/release/AndroidManifest.xml to see the real manifest configuration which the app was build.

Now, here is when the things starts to get dizzy. I'm working with a capacitor app through Quasar framework, so capacitor adds some defaults manifest files to the merge which does not have the correct configuration described at the beginning of this explanation.

The manifest with the issue is a firebase implementation (which I'm not using but is added by default anyways) located in the node_modules, so I add a ./scripts/fix_firebase.sh script to my project to edit my node_modules every time I need it.

The script is the nex one:

#!/bin/bash

FILE='../src-capacitor/node_modules/@capacitor/android/capacitor/src/main/AndroidManifest.xml'
TO_SEARCH='<service android:name="com.getcapacitor.CapacitorFirebaseMessagingService" android:stopWithTask="false">'
REPLACEMENT='<service android:name="com.getcapacitor.CapacitorFirebaseMessagingService" android:stopWithTask="false" android:exported="true">'

if [ ! -f "$FILE" ]; then
  echo "Error: file '$FILE' does not exist." >&2
  exit 1
fi

if ! grep -q "$TO_SEARCH" "$FILE"; then
  echo "Error: search string '$TO_SEARCH' not found in '$FILE'." >&2
  exit 1
fi

sed -i "s/$TO_SEARCH/$REPLACEMENT/g" "$FILE"

echo "'$FILE' fixed."

Probably, as long as I keep adding more plugins, some of them will have a similar issue so I will need to add a correction to my fix script.

asceta
  • 77
  • 2
  • 12
0

If you build from the command line with ./gradlew installDebug in your project folder, you can actually get a pretty good idea of what's wrong.

My error output:

  • Failed parse during installPackageLI: /data/app/vmdl487574943.tmp/base.apk (at Binary XML file line #326): leakcanary.internal.activity.LeakLauncherActivity: Targeting S+ (version 31 and above) requires that an explicit value for android:exported be defined when intent filters are present

If the package name (in my case leakcanary) doesn't tell you enough, the "binary XML file line #326" tells you which line in the merged manifest is offending. You can find the merged manifest at (project path)/build/intermediates/merged_manifests/(release or debug)/AndroidManifest.xml

ArtHare
  • 1,798
  • 20
  • 22
0

Add this to app/build.gradle

androidTestImplementation "androidx.test.ext:junit:1.1.3"
androidTestImplementation "androidx.fragment:fragment-testing:1.4.1"
androidTestImplementation "androidx.test:core:1.4.0"
Kristoffer
  • 264
  • 2
  • 4
  • 16
0

I faced similar issue(exact error below).

Manifest merger failed : android:exported needs to be explicitly specified for element <service#com.mapzen.android.lost.internal.GeofencingIntentService>. 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.

After some self investigation I figure out, one of the dependency was causing the issue. In my case the dependency was

implementation 'com.airmap.airmapsdk:airmapsdk:3.0.0'

How did I figure out this? I commented all 3rd party dependencies. The error was gone. I started uncommenting one by one till I found out the actual culprit. It is tedious task but as the error didn't give me any sort of hint I tried this approach.

Bottom line: if none of the answers here help then play around and figure out if any of the dependency is causing the issue.

tanni tanna
  • 544
  • 4
  • 12
-4

These steps solve the problem:

  1. targetSdkVersion if 31 change to 30

  2. add line in AndroidManifest inside <activity android:exported="true" />

  3. update gradle and gradle tools latest version.

  4. remove fabric imports and tools.

  5. clean and run

nullromo
  • 2,165
  • 2
  • 18
  • 39
u0j
  • 116
  • 1
  • 2