Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OneSignal 3.0.3 not compatible with Android 12 (API 31) #528

Open
areavisuale opened this issue Aug 4, 2022 · 16 comments
Open

OneSignal 3.0.3 not compatible with Android 12 (API 31) #528

areavisuale opened this issue Aug 4, 2022 · 16 comments

Comments

@areavisuale
Copy link

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:

  1. Create a blank project with the latest OneSignalSDK.unitypackage
  2. Upload the project in the Google Play Console
@WillowZAR
Copy link

WillowZAR commented Aug 9, 2022

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

@PrisedRabbit
Copy link

[temp solution] Just add below lines inside in global AndroidManifest.xml
<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>

@shepherd-l
Copy link
Contributor

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?

@devendraatxpertaapp
Copy link

I have the same problem but @PrisedRabbit solution is not working for me.

@roointan
Copy link

roointan commented Nov 9, 2022

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>

@GaneshMBabu21
Copy link

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

@roointan
Copy link

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.

@KOSSOKO
Copy link

KOSSOKO commented Nov 19, 2022

I use the version 3.0.5 with unity and i'm facing the same. @roointan please how did you do finally ?

@KOSSOKO
Copy link

KOSSOKO commented Nov 19, 2022

@GaneshMBabu21 where did you add the code ? I added in the main manifest but got the namespace prefix tools is not defined

@roointan
Copy link

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

@areavisuale
Copy link
Author

areavisuale commented Nov 21, 2022

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>

@xinatcg
Copy link

xinatcg commented Nov 21, 2022

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

@roointan
Copy link

Update: the workaround is updated

@KOSSOKO
Copy link

KOSSOKO commented Nov 22, 2022

Thanks, it works now.

@mrerenimo
Copy link

mrerenimo commented May 4, 2023

@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

@fabiofns
Copy link

fabiofns commented Aug 2, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests