Getting android:exported error even if it exists in AndroidManifest.xml

After I installed cordova-plugin-x-socialsharing plugin into my ionic cordova project I am getting the below error when executed build command:

> Task :app:processDebugMainManifest FAILED
D:\Project\@Codes Repos\Ionic6-cordova\platforms\android\app\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 https://developer.android.com/guide/topics/manifest/activity-element#exported for details.

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


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processDebugMainManifest'.
> Manifest merger failed : 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.

If I check my AndroidManifest.xml file, the activity tag already has the android:exported="true" property.

AndroidManifest.xml

<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="1" android:versionName="0.0.1" package="com.test.testproj" xmlns:android="http://schemas.android.com/apk/res/android">
    <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
    <uses-permission android:name="android.permission.INTERNET" />
    <application android:exported="true" android:hardwareAccelerated="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:networkSecurityConfig="@xml/network_security_config" android:supportsRtl="true">
        <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode" android:exported="true" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@style/Theme.AppCompat.NoActionBar" android:windowSoftInputMode="adjustResize">
            <intent-filter android:label="@string/launcher_name">
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <provider android:authorities="${applicationId}.fileOpener2.provider" android:exported="false" android:grantUriPermissions="true" android:name="io.github.pwlin.cordova.plugins.fileopener2.FileProvider">
            <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/opener_paths" />
        </provider>
        <receiver android:enabled="true" android:name="nl.xservices.plugins.ShareChooserPendingIntent">
            <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.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
    <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" android:required="true" />
    <uses-permission android:name="android.permission.BLUETOOTH" />
</manifest>

Do I have to add the android:exported somewhere else as well?

Ionic Info

Ionic:

   Ionic CLI                     : 6.19.0 (C:\Users\CGauns\AppData\Roaming\nvm\v16.15.0\node_modules\@ionic\cli)
   Ionic Framework               : @ionic/angular 6.1.5
   @angular-devkit/build-angular : 13.2.6
   @angular-devkit/schematics    : 13.2.6
   @angular/cli                  : 13.2.6
   @ionic/angular-toolkit        : 6.1.0

Cordova:

   Cordova CLI       : 11.0.0
   Cordova Platforms : android 10.1.2
   Cordova Plugins   : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 5.0.0, (and 22 other plugins)

Utility:

   cordova-res                          : 0.15.4
   native-run (update available: 1.6.0) : 1.5.0

System:

   Android SDK Tools : 26.1.1 (D:\Android\sdk)
   NodeJS            : v16.15.0 (C:\Program Files\nodejs\node.exe)
   npm               : 8.5.5
   OS                : Windows 10

Screenshot from 2022-06-25 14-52-19
I’m facing the same issue, did you find any solution yet?

hi @syndeveloper I used older version of cordova-plugin-x-socialsharing and not the latest one.

I used version 5.3.1 as this was working on my ionic 3 app.

Please note that I was getting error while building and not while uploading the APK.

1 Like

@CGauns oh that fixed the problem?
currently i am using “cordova-plugin-x-socialsharing” spec=“^5.6.2”
should i have to update it ?

Using version 5.3.1, I was able to build and run the app. Also the sharing works. But haven’t tried uploading the app on Play store or App store.

@CGauns thank you! are you using android sdk 30+ ?

I have set target sdk as 31.

1 Like

Until the plugin author makes the necessary change, you can modify the file “plugin.xml” under /node_modules/cordova-plugin-x-socialsharing and add the android:exported=“true” there so that each time you compile, the generated manifest file for this plugin gets it:

5 Likes

@vorkapps thank you, but we do build our project on https://dashboard.ionicframework.com
so we won’t be having control over the manifest file :frowning:

hi @vorkapps ,

I did the change you have suggested but I am getting the same error

I checked the AndroidManifest.xml file under \platforms\android\app\src\main folder, android:exported="true" was not added. I had tried removing and adding platform.

hi @CGauns ,

You mentioned \platforms\android\app\src\main folder, which suggests you are not using Capacitor, so I’m not sure if my suggestion still holds, I would guess it should, as I am using Capacitor.

I checked my config.xml again, and there is another section that I had added the android:exported=“true” setting, and it’s this one: (maybe this is what made the effect)

edit: I was going to delete this reply, as I now see it’s irrelevant to the issue… Maybe the difference is the fact that I’m using Capacitor, and something else needs to be done for cordova scenarios… Sorry I couldn’t help further…

Rgrds

1 Like

hi @vorkapps

Your answer might not be related to Cordova, but it works.

I am not sure how it is working in Capacitor, but in Cordova, a separate folder called plugins is created in the root directory. In my case, the plugin configuration were picked from that folder. After setting the same properties in plugins\cordova-plugin-x-socialsharing\plugin.xml file, the issue got resolved.

Thank you for the help. :innocent: :+1:

2 Likes

You marked your reply as the solution, instead of my post providing the solution :slightly_smiling_face:

1 Like

heyy did you manage to solve this? i’m having the same issue with the ionic dashboard

1 Like

Currenty if you set minsdk version and get Android 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 then I have sollution of that…

  1. Open platforms/android/android.json

  2. Put this line in all plugin you used. android:exported="true" or android:exported="false" (Based on your requirement)

  3. After open platforms\android\app\src\main/AndroidManifest.xml file and delete all the activity,meta-data,service,provider…all the things under <application …>
    —delete these all data—
    </application?

Because we changed android.json line. So when we build again than It will auto generate with android:exported…

I spend my whole day in this error. But now I am happy because I got Sollution.

3 Likes

like a charm, added android:exported="true" on all “xml”: "<activity I could find

build and deploy went ok. When tested the installation on a device, it broke. Had to update cordova and go for android@11 platform

Are these are the only two options right now? Either add to the JSON or updated to android@11 ?
Can we not put this in the config.xml and it put it in the manifest? I’m trying that and see it in the android.json but I guess not in the correct format?

I’m not finding any <activity in anrdoid.json
I have one provider (which gets the tag from config.xml)
and under application for the first <service has it (from config)
I added it to the other <service but still getting the error.