I am need to publish a Cordova application on Google Play targeting Android 12. When I uploaded my APK file, I get error
You uploaded an APK or Android App Bundle which has an activity, activity alias, service or broadcast receiver with intent filter, but without the 'android:exported' property set. This file can't be installed on Android 12 or higher. See: developer.android.com/about/versions/12/behavior-changes-12#exported
I did some reaserch on internet and I found, that this configuration should be add to config.xml:
<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application/activity">
<activity android:exported="true"/>
</edit-config>
It works fine for some of my applications, but one of them still shows the error, when uploaded to Google Play. Its AndroidManifest.xml looks like this:
<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="750" android:versionName="7.5.0" package="cz.foxtrot.motoquest" 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:hardwareAccelerated="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:usesCleartextTraffic="true">
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode" android:exported="true" android:label="@string/activity_name" android:launchMode="singleTask" android:name="MainActivity" android:theme="@android:style/Theme.DeviceDefault.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>
<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="true" android:grantUriPermissions="true" android:name="nl.xservices.plugins.FileProvider">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/sharing_paths" />
</provider>
<meta-data android:name="com.transistorsoft.locationmanager.license_key" android:value="b2c8e0bf1863da91b0f941ddf8278f699d320a320182cf7eb1d1e5c660ee17be" />
</application>
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
<uses-permission android:name="com.android.vending.BILLING" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>
Any ideas, what can be wrong?
Following up to the answer from Carl Smith. You might need to set the exported on more tags. The edit-config tag does as the name says, it edits the XML configuration file after it has been generated. In this case it will add the android:exported tag.
Try adding this to your config.xml file inside the tag:
<edit-config file="app/src/main/AndroidManifest.xml" target="/manifest/application/activity" mode="merge">
<activity android:exported="true"/>
</edit-config>
<edit-config file="app/src/main/AndroidManifest.xml" target="/manifest/application/service" mode="merge">
<service android:exported="true" />
</edit-config>
<edit-config file="app/src/main/AndroidManifest.xml" target="/manifest/application/provider" mode="merge">
<provider android:exported="true" />
</edit-config>
<edit-config file="app/src/main/AndroidManifest.xml" target="/manifest/application/receiver" mode="merge">
<receiver android:exported="true" />
</edit-config>
It will not only set the flag for the activity and service tags but also for the provider and the receiver.
Notice that this will set the exported flag to true. The best solution is to wait until all maintainers of your plugins have updated the plugin but until then at least you can submit your working apps to the Play Store and confirm to the required use of API 31+.
Please notice that you might not need all these 4 edits for your config. This depends on the plugins you use and how well they are updated. Start with one (from top to bottom) if it doesn't work add more and if it works try to remove the others to find out what the minimum is you need. Don't change more then needed.
I have added the following code in config.xml
<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application/activity" xmlns:android="http://schemas.android.com/apk/res/android">
<activity android:exported="true" />
</edit-config>
I tried adding <edit-config> for service, provider & receiver but, that was throwing the following error
Unable to graft xml at selector "/manifest/application/receiver"
When I added only for activity, it started working.
Also dont forget to include xmlns:android="http://schemas.android.com/apk/res/android" in the <edit-config> for activity
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With