Search code examples
xamarinxamarin.androidonesignal

Didn't find class "com.onesignal.GcmBroadcastReceiver" on path: DexPathList


I'm new to Xamarin and trying to get OneSignal push notifications working in Android. When running the emulator and I fire a push notification from OneSignal, it comes through successfully on the emulator. However, when I deploy the app via Play Store, and I have the app open, firing a push notification crashes the app with the following error:

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.woodfordgroup.whybuycars-Bl5_t81uXklo5mpGZRvJcw==/base.apk"],nativeLibraryDirectories=[/data/app/com.woodfordgroup.whybuycars-Bl5_t81uXklo5mpGZRvJcw==/lib/arm64, /data/app/com.woodfordgroup.whybuycars-Bl5_t81uXklo5mpGZRvJcw==/base.apk!/lib/arm64-v8a, /system/lib64]]
    at android.app.ActivityThread.handleReceiver(ActivityThread.java:3432)
    at android.app.ActivityThread.access$1400(ActivityThread.java:207)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1712)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:201)
    at android.app.ActivityThread.main(ActivityThread.java:6831)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:927)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.onesignal.GcmBroadcastReceiver" on path: DexPathList[[zip file "/data/app/com.woodfordgroup.whybuycars-Bl5_t81uXklo5mpGZRvJcw==/base.apk"],nativeLibraryDirectories=[/data/app/com.woodfordgroup.whybuycars-Bl5_t81uXklo5mpGZRvJcw==/lib/arm64, /data/app/com.woodfordgroup.whybuycars-Bl5_t81uXklo5mpGZRvJcw==/base.apk!/lib/arm64-v8a, /system/lib64]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:171)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
    at android.app.AppComponentFactory.instantiateReceiver(AppComponentFactory.java:84)
    at androidx.core.app.CoreComponentFactory.instantiateReceiver(Unknown Source:0)
    at android.app.ActivityThread.handleReceiver(ActivityThread.java:3425)
    ... 8 more

Is this because the OneSignal library is not being included in the release? I've also seen mention of AndroidX or multi-dex issues. Here is the android manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="15" android:versionName="1.0" package="com.woodfordgroup.whybuycars" android:installLocation="auto">
    <uses-sdk android:minSdkVersion="21" android:targetSdkVersion="29" />
    <application android:label="WhyBuyCars" android:theme="@style/MainTheme" android:icon="@drawable/whybuycars_icon_512x512">
        <provider android:name="android.support.v4.content.FileProvider" android:authorities="${applicationId}.fileprovider" android:exported="false" android:grantUriPermissions="true">
            <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" />
        </provider>
        <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="com.woodfordgroup.whybuycars" />
            </intent-filter>
        </receiver>
    </application>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-feature android-name="android.hardware.camera" android:required="false" android:glEsVersion="0x00030002" />
    <permission android:name="com.woodfordgroup.whybuycars.permission.C2D_MESSAGE" android:protectionLevel="signature" />
    <uses-permission android:name="com.woodfordgroup.whybuycars.permission.C2D_MESSAGE" />
</manifest>

And here are my android project properties (target version is 29):

enter image description here

I also wonder if something went wrong with the inclusion of various libraries while I was installing OneSignal from Nuget. Here is my list of project references:

enter image description here


Solution

  • Add this to the proguard file.

    -keep class com.onesignal.** { *; }
    

    Source: See oncky's comment on question.