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

Unable to instantiate receiver com.onesignal.GcmBroadcastReceiver when using R8 code shrinker (com.onesignal.FCMBroadcastReceiver when using OneSignal 4.0.0) #235

Open
Hakim83 opened this issue Apr 17, 2021 · 7 comments

Comments

@Hakim83
Copy link

Hakim83 commented Apr 17, 2021

Description:
I followed the documentation to make Xamarin.Forms OneSignal notification app targeting Android. In release mode, it works well, I receive push notification message (I tried it using tags), but if I recompile with Android code shrinker set to 'r8' the app crashes when receiving notification. following is the android device monitor log:

04-17 10:22:35.468: E/AndroidRuntime(16674): java.lang.RuntimeException: Unable to instantiate receiver com.onesignal.GcmBroadcastReceiver: java.lang.ClassNotFoundException: Didn't find class "com.onesignal.GcmBroadcastReceiver" on path: DexPathList[[zip file "/data/app/com.myonesignalapp-Nk9WnS6KwJ6M4tnRd4FiwA==/base.apk"],nativeLibraryDirectories=[/data/app/com.myonesignalapp-Nk9WnS6KwJ6M4tnRd4FiwA==/lib/x86, /data/app/com.myonesignalapp-Nk9WnS6KwJ6M4tnRd4FiwA==/base.apk!/lib/x86, /system/lib]]
04-17 10:22:35.468: E/AndroidRuntime(16674): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.onesignal.GcmBroadcastReceiver" on path: DexPathList[[zip file "/data/app/com.myonesignalapp-Nk9WnS6KwJ6M4tnRd4FiwA==/base.apk"],nativeLibraryDirectories=[/data/app/com.myonesignalapp-Nk9WnS6KwJ6M4tnRd4FiwA==/lib/x86, /data/app/com.myonesignalapp-Nk9WnS6KwJ6M4tnRd4FiwA==/base.apk!/lib/x86, /system/lib]]

AndroidManifest.xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.myonesignalapp">
    <uses-sdk android:minSdkVersion="21" android:targetSdkVersion="30" />
	<permission android:name="${applicationId}.permission.C2D_MESSAGE" android:protectionLevel="signature" />
	<uses-permission android:name="${applicationId}.permission.C2D_MESSAGE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <application android:label="OneSignalTest.Android" android:theme="@style/MainTheme">
		<receiver 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="${applicationId}" />
			</intent-filter>
		</receiver>
	</application>
</manifest>

Environment
Visual Studio Community 2019 version 16.9.2
Xamarin.Android SDK 11.2.2.1
Com.OneSignal Nuget version 3.10.5

Steps to Reproduce Issue:

  1. Create new Xamarin.Forms project
  2. setup it as described in documentation for app.xaml.cs file and android project androidmanifest.xml
  3. register notification in your code
  4. in release mode android settings set code shrinker to r8
  5. run the app and try to send notification from backend
@tanaynigam
Copy link
Contributor

@Hakim83 Thanks for reporting the issue. We have a release OneSignalSDK.Xamarin-4.0.0 in which this issue no longer seems to exist. Please note that we have changed the package name and namespace for the SDK from Com.OneSignal to OneSignalSDK.Xamarin and would require you to remove the previous package name and add the new package name to import the SDK in your code.

Additionally, when searching for the package on nuget.org, you will be required to search for OneSignalSDK.Xamarin to import the package

@dush135
Copy link

dush135 commented May 31, 2022

Problem still exits. If we use r8 shrinking in Android we are facing this issue. Only way to get away with this crash is adding a custom proguard.cfg file and add following lines to it

-dontobfuscate

-keep class com.onesignal.FCMBroadcastReceiver

@jkasten2
Copy link
Member

@dush135 Could you let us know what Android versions and device models you are seeing this issue on?

@dush135
Copy link

dush135 commented Jun 1, 2022

Tested devices

Samsung s10+ = Android 12
Samsung A51 = Android 12
Sony ZS1 = Android 9

Tested on both MAC and Windows Visual Studio 2022

Xamarin.Forms 5.0.0.2401
OneSignalSDK.Xamarin-4.0.0

@it11111111
Copy link

This is still an issue for me as well. Using Visual Studio 2022 - OneSIgnalXamarin SDK

Using R8 and release mode.

Tested devices:
Samsung s20 = Android 12
Samsung S21fe = Android 12
Samsung S20 Ultra = Android 12

Xamarin.Forms 5.0.0.2401
OneSignalSDK.Xamarin-4.1.3

@jkasten2 jkasten2 changed the title Unable to instantiate receiver com.onesignal.GcmBroadcastReceiver when using R8 code shrinker Unable to instantiate receiver com.onesignal.GcmBroadcastReceiver when using R8 code shrinker (com.onesignal.FCMBroadcastReceiver when using OneSignal 4.0.0) Oct 13, 2022
@jkasten2
Copy link
Member

jkasten2 commented Oct 13, 2022

Original Issue - com.onesignal.GcmBroadcastReceiver

For those seeing this with com.onesignal.GcmBroadcastReceiver when using OneSignal-Xamarin-SDK 4.0.0 or newer, make sure you have removed all packages with Com.OneSignal and replaced them with OneSignalSDK.Xamarin. com.onesignal.GcmBroadcastReceiver was removed and replaced with com.onesignal.FCMBroadcastReceiver in this version. If you still see the error about GcmBroadcastReceiver when using OneSignal 4.0.0 then I recommend you clean your project in Visual Studio, as well as manually removed the bin and obj folders in your project.

com.onesignal.FCMBroadcastReceiver

For those seeing this with com.onesignal.FCMBroadcastReceiver, I am surprised this isn't correctly picked up by Visual Studio as FCMBroadcastReceiver is defined in OneSignal's AndroidManifest.xml. This seems like a bug with Visual Studio as native apps nor other frameworks like Flutter have this issue.

The next step here would be to see if the issue still happens with a MAUI project. Either way, it could be reported to Microsoft to see if they can address it in a future update.

@jkasten2 jkasten2 reopened this Oct 13, 2022
@van8tka
Copy link

van8tka commented Feb 10, 2024

OneSignalSDK.DotNet v 5.10
Net-8-android
removed <receiver android:name="com.onesignal.FCMBroadcastReceiver"... from AndroidManifest.xml - its' work for me

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

No branches or pull requests

6 participants