OneSignal 3.0.3 not compatible with Android 12 (API 31)
Description:
I updated my project with the last OneSignal Unity SDK but I cannot build it for Android 12 because Google rejects my app bundle. It says that android:exported is missing somewhere. If I check the OneSignal manifests in my project there isn't this line of code, and I don't know how to add it.
Environment
OneSignal SDK 3.0.3 Unity 2020.3.17f1
Steps to Reproduce Issue:
- Create a blank project with the latest OneSignalSDK.unitypackage
- Upload the project in the Google Play Console
Having the same issue with SDK 3.0.3 and Unity 202.3.23f1
If i export the project and open it in android studio it points at the specific file:
Merging Errors: Error: android:exported needs to be explicitly specified for element <receiver#com.onesignal.GcmBroadcastReceiver>. 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. Exports.launcher main manifest (this file), line 10
[temp solution] Just add below lines inside <receiver android:exported="false" android:name="com.onesignal.GcmBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND" > <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <category android:name="***PACKAGE_NAME***" /> </intent-filter> </receiver>
Thank you for reporting, I was unable to reproduce your issue. Could you provide an example repo with steps to reproduce and also provide your application's AndroidManifest.xml file?
I have the same problem but @PrisedRabbit solution is not working for me.
This is fixed in version 3.0.3
you may need to add the following to your main AndroidManifest file (under Assets/Plugins/Android) to prevent exceptions upon receiving a push notification, or to be able to upload to Play Store successfully:
<receiver android:name="com.onesignal.GcmBroadcastReceiver" android:exported="false" tools:replace="android:exported"></receiver>
The following is a workaround for older versions, but may not work for you. I leave it here because it can be useful to some people.
If you don't want to upgrade, and want to use a workaround for the older version, add these to the AndroidManifest.xml file in Assets/Plugins/Android/AndroidManifest.xml:
<activity android:name="com.onesignal.NotificationOpenedActivityHMS" android:exported="true" tools:replace="android:exported"></activity>
<receiver android:name="com.onesignal.GcmBroadcastReceiver" android:exported="true" tools:replace="android:exported"></receiver>
<receiver android:name="com.onesignal.BootUpReceiver" android:exported="true" tools:replace="android:exported"></receiver>
<receiver android:name="com.onesignal.UpgradeReceiver" android:exported="true" tools:replace="android:exported"></receiver>
Hi @roointan, i used your code suggestion i could make a build, But the notification is not receiving, but if i make a build with the older sdk i could receive the notification(Just for your info that onesignal is configured correct). Can you guide me ? Thank you
Hi @roointan, i used your code suggestion i could make a build, But the notification is not receiving, but if i make a build with the older sdk i could receive the notification(Just for your info that onesignal is configured correct). Can you guide me ? Thank you
Hello!
Unfortunately not, I used the latest SDK myself. I edited the comment so it's not misleading.
I use the version 3.0.5 with unity and i'm facing the same. @roointan please how did you do finally ?
@GaneshMBabu21 where did you add the code ? I added in the main manifest but got the namespace prefix tools is not defined
I use the version 3.0.5 with unity and i'm facing the same. @roointan please how did you do finally ?
use version 3.0.3, from asset store
I resolved using onesignal 3.0.3 (I don't know if this workaroung works with 3.0.5 either), and modifying my custom LauncherManifest.xml in this way:
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.unity3d.player"
xmlns:tools="http://schemas.android.com/tools"
android:installLocation="preferExternal">
<supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:anyDensity="true"/>
<application android:extractNativeLibs="true"
android:label="@string/app_name"
android:icon="@mipmap/app_icon">
<receiver
android:exported="true"
android:name="com.onesignal.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.mycompany.myapp" />
</intent-filter>
</receiver>
</application>
</manifest>
This is fixed in version 3.0.1
-- Edit: This workaround doesn't work. But I leave it here, only to help someone find a working workaround. --
But if you don't want to upgrade, and want to use a workaround for the older version, add these to the AndroidManifest.xml file in Assets/Plugins/Android/AndroidManifest.xml:
<activity android:name="com.onesignal.NotificationOpenedActivityHMS" android:exported="true" tools:replace="android:exported"></activity> <receiver android:name="com.onesignal.GcmBroadcastReceiver" android:exported="true" tools:replace="android:exported"></receiver> <receiver android:name="com.onesignal.BootUpReceiver" android:exported="true" tools:replace="android:exported"></receiver> <receiver android:name="com.onesignal.UpgradeReceiver" android:exported="true" tools:replace="android:exported"></receiver>
this works! just take care: MUST put this content into the project AndroidMenifest.xml. NOT the one signal plugin manifest.
Seem like the one signal dynamically append these into the manifest when android build, because even in the gradle output I can see the exported tag added to all element, but still does not work. So OneSignal plugin MUST do some magic when building abb from Gradle output. Therefore, I guess after adding this content to the manifest, the Plugin cannot override it.
Btw, it work in old version even v2
Update: the workaround is updated
Thanks, it works now.
@GaneshMBabu21 where did you add the code ? I added in the main manifest but got the
namespace prefix tools is not defined
add xmlns:tools="http://schemas.android.com/tools" after xmlns:android="http://schemas.android.com/apk/res/android"
also it works for me ty
This is fixed in version 3.0.3
you may need to add the following to your main AndroidManifest file (under Assets/Plugins/Android) to prevent exceptions upon receiving a push notification, or to be able to upload to Play Store successfully:
<receiver android:name="com.onesignal.GcmBroadcastReceiver" android:exported="false" tools:replace="android:exported"></receiver>The following is a workaround for older versions, but may not work for you. I leave it here because it can be useful to some people.
If you don't want to upgrade, and want to use a workaround for the older version, add these to the AndroidManifest.xml file in Assets/Plugins/Android/AndroidManifest.xml:
<activity android:name="com.onesignal.NotificationOpenedActivityHMS" android:exported="true" tools:replace="android:exported"></activity> <receiver android:name="com.onesignal.GcmBroadcastReceiver" android:exported="true" tools:replace="android:exported"></receiver> <receiver android:name="com.onesignal.BootUpReceiver" android:exported="true" tools:replace="android:exported"></receiver> <receiver android:name="com.onesignal.UpgradeReceiver" android:exported="true" tools:replace="android:exported"></receiver>
Thanks. Works for me.