Apps targeting Android 12 and higher are required to specify an explicit value for `android:exported`

Hey guys, im having a problem when I run build in Android Studio, a few days ago I finish some upgrades, not a big deal but I left the app working and using in testing y Google Play Console and TestFlights, but today i just got this error and im trying to figure out whats the problem, if someone facing the same error or found the solution i really appreciate if give some help

Code error:

Task :capacitor-cordova-android-plugins:processDebugManifest FAILED
/Users/imaccec/Documents/GitHub/SalvalaIonic/android/capacitor-cordova-android-plugins/src/main/AndroidManifest.xml 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 <activity>  |  Android Developers for details.

See http://g.co/androidstudio/manifest-merger for more information about the manifest merger.

Execution failed for task ‘:capacitor-cordova-android-plugins:processDebugManifest’.

A failure occurred while executing com.android.build.gradle.tasks.ProcessLibraryManifest$ProcessLibWorkAction
Manifest merger failed with multiple errors, see logs

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Ionic:

   Ionic CLI       : 6.16.3 (/usr/local/lib/node_modules/@ionic/cli)
   Ionic Framework : @ionic/vue 5.7.0

Capacitor:

   Capacitor CLI      : 3.2.2
   @capacitor/android : 3.2.2
   @capacitor/core    : 3.2.2
   @capacitor/ios     : 3.2.2

Utility:

   cordova-res : 0.15.3
   native-run  : 1.4.1

System:

   NodeJS : v14.17.3 (/usr/local/bin/node)
   npm    : 6.14.13
   OS     : macOS Big Sur

AndroidManifest.xml

<?xml version='1.0' encoding='utf-8'?>
<manifest package="cl.cecsoluciones.salvala" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools">
    <application android:allowBackup="true" android:hardwareAccelerated="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme" android:usesCleartextTraffic="true">
        <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>
        <meta-data android:name="com.facebook.sdk.ClientToken" android:value="@string/facebook_client_token"/>
        <activity android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation" android:label="@string/app_name" android:name="com.facebook.FacebookActivity" android:exported="false"/>
        <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode" android:label="@string/title_activity_main" android:launchMode="singleTask" android:name="cl.cecsoluciones.salvala.MainActivity" android:theme="@style/AppTheme.NoActionBarLaunch" android:exported="false">
            <tools:validation testUrl="https://api.salvala.cl" />
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="@string/custom_url_scheme" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:host="api.salvala.cl" android:scheme="example" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:host="api.salvala.cl/login" android:scheme="example" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:host="api.salvala.cl" android:pathPattern="/.*" android:scheme="https" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:host="api.salvala.cl" android:pathPattern="/.*" android:scheme="http" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:host="api.salvala.cl" android:scheme="https" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:host="api.salvala.cl" android:scheme="http" />
            </intent-filter>
        </activity>
        <provider android:authorities="${applicationId}.fileprovider" android:exported="false" android:grantUriPermissions="true" android:name="androidx.core.content.FileProvider">
            <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" />
        </provider>
    </application>
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-feature android:name="android.hardware.location.gps" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-sdk tools:overrideLibrary="com.google.zxing.client.android" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
</manifest>

variables.gradle

ext {
    minSdkVersion = 23
    compileSdkVersion = 31
    targetSdkVersion = 31
    androidxActivityVersion = '1.2.0'
    androidxAppCompatVersion = '1.2.0'
    androidxCoordinatorLayoutVersion = '1.1.0'
    androidxCoreVersion = '1.3.2'
    androidxFragmentVersion = '1.3.0'
    junitVersion = '4.13.1'
    androidxJunitVersion = '1.1.2'
    androidxEspressoCoreVersion = '3.3.0'
    cordovaAndroidVersion = '7.0.0'
}

if something is missing please comment, and thanks

Why are you targeting Android 12? it’s not final yet and Capacitor doesn’t officially support it, nor the Capacitor plugins.

In your case, there is some Cordova plugin that doesn’t support it neither, you’ll have to find which one is causing the issue and report it to the plugin author.

Hi @jcesarmobile, thanks for the reply

The root of the problem was when I tried to deploy on a real device and an error appeared that required uploading the android version from 30 to 31, I really don’t understand why, nor can I recreate the situation since the logic of the app is somewhat complicated, I did not do the development from the beginning, I just started it again to make it work.

After uploading the android version, the problem I described above appeared and in order to make it work I had to put in a variable inside capacitor-cordova-plugins, in the android manifest file this property android: exported = “false”, in the label receiver

I don’t really understand why this error was generated, but placing the variable in the indicated label it worked for me, but every time I do an “ionic cap sync android” it leaves it as it was again, update the dependencies to see if indeed it was somewhat out of date and was not the case.

<?xml version='1.0' encoding='utf-8'?>

<manifest package="capacitor.android.plugins"

xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:amazon="http://schemas.amazon.com/apk/res/android">

<application >

<receiver android:name="nl.xservices.plugins.ShareChooserPendingIntent" android:enabled="true" android:exported="false"> <!-- this line triggers the error merge manifest's files' -->

<intent-filter>

<action android:name="android.intent.action.SEND"/>

</intent-filter>

</receiver>

<provider android:authorities="${applicationId}.sharing.provider" android:exported="false" android:grantUriPermissions="true" android:name="nl.xservices.plugins.FileProvider">

<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/sharing_paths"/>

</provider>

</application>

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

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

</manifest>

I think your problem is related to google releasing some alpha/beta AndroidX libraries and your project is picking those as latest instead of the latest stable ones (specially if using jetifier). Those, as they are alpha/beta, target SDK 31 and that is showing you the error that forces you to update to SDK 31.

You can force latest stable versions of the AndroidX libraries by adding this in your root build.gradle file.

configurations.all {
  resolutionStrategy {
    force 'androidx.core:core:1.6.0'
    force 'androidx.core:core-ktx:1.6.0'
  }
}

That’s only for androidx.core, you might need some other libraries depending on your plugins.

1 Like

thanks @jcesarmobile i’ll try that configuration!
but i guest you’re right when you said my app is always looking/taking the last version of everything and thats kinda annoying, how can i fix that and work always in stable version of capacitor dependencies? im new using Ionic and always try to fix every errors when appears.

again, thanks a lot for ur time for answers my doubts

Well, it’s not clear to me if it was Google who marked those alpha/beta releases as latest or if it’s jetifier who is picking those for some reason when patching your cordova plugins. So there is nothing you can really do other than fixing the version yourself with the code I shared.

Ideally, those plugins should move to AndroidX dependencies so you can stop using jetifier to patch them.