OneSignal / OneSignal-Xamarin-SDK

OneSignal is a free push notification service for mobile apps. This plugin makes it easy to integrate your Xamarin app with OneSignal. https://onesignal.com
Other
104 stars 50 forks source link

Android - Crash when first launch and received Notification on Release (Xamarin) - com.google.firebase.iid.FirebaseInstanceIdService cannot be instantiated #228

Closed QuangKhanDo closed 2 years ago

QuangKhanDo commented 3 years ago

Description:

I have release my Xamarin Android to apk and installing it. On the first launch after Splash Screen it'll crash and from the second time beyond it start normally. But when receive the notification it will crashing no matter on background or foreground. I have searching for a while and find out the cause of problem is: androidx.core.app.CoreComponentFactory.instantiateReceiver

Environment

  1. What version of the Xamarin OneSignal SDK are you using? 3.10.2
  2. Provide a list of your project dependencies Xamarin AndroidX
  3. Does the issue occur only in iOS, Android, etc? Just only Android.

Steps to Reproduce Issue:

  1. Installing App
  2. Open it
  3. Crashing after Spasl Screen
  4. Open it again
  5. Push Notification to the app
  6. App will start crashing when receive the message no matter on background or foreground

Stack traces:

androidx.core.app.CoreComponentFactory.instantiateReceiver
java.lang.InstantiationException: java.lang.Class<com.google.firebase.iid.FirebaseInstanceIdReceiver> cannot be instantiated

java.lang.Class.newInstance Class.java
android.app.AppComponentFactory.instantiateReceiver AppComponentFactory.java:110
androidx.core.app.CoreComponentFactory.instantiateReceiver
android.app.ActivityThread.handleReceiver ActivityThread.java:3773
android.app.ActivityThread.access$1400 ActivityThread.java:225
android.app.ActivityThread$H.handleMessage ActivityThread.java:1876
android.os.Handler.dispatchMessage Handler.java:107
android.os.Looper.loop Looper.java:359
android.app.ActivityThread.main ActivityThread.java:7418
java.lang.reflect.Method.invoke Method.java
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run RuntimeInit.java:492
com.android.internal.os.ZygoteInit.main ZygoteInit.java:935

android.app.ActivityThread.handleReceiver ActivityThread.java:3780
android.app.ActivityThread.access$1400 ActivityThread.java:225
android.app.ActivityThread$H.handleMessage ActivityThread.java:1876
android.os.Handler.dispatchMessage Handler.java:107
android.os.Looper.loop Looper.java:359
android.app.ActivityThread.main ActivityThread.java:7418
java.lang.reflect.Method.invoke Method.java
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run RuntimeInit.java:492
com.android.internal.os.ZygoteInit.main ZygoteInit.java:935
scream4-me commented 3 years ago

We are experiencing this exact issue, any news or updates on a solution?

GKG4 commented 3 years ago

Seems like everyone is facing this issue. Kindly provide a solution.

jkasten2 commented 3 years ago

@QuangKhanDo @scream4-me @GKG4 I was not able to reproduce the issue on a new Xamarin project targeting Android 11 (API 30) and just Com.OneSignal 3.10.4 running on an Android 8.1 emulator. https://github.com/jkasten2/Xamarin-AndroidAPI30-OneSignal3.10.4

Needs more details

1. Dependencies

Could you provide the full list of Packages in your project? Preferably copy all <PackageReference> entries from your .Android.csproj file. Example:

<ItemGroup>
    <PackageReference Include="Xamarin.Forms" Version="5.0.0.2012" />
    <PackageReference Include="Xamarin.Essentials" Version="1.6.1" />
    <PackageReference Include="Xamarin.AndroidX.Migration">
      <Version>1.0.8</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Android.Support.Annotations">
      <Version>28.0.0.3</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Android.Support.Collections">
      <Version>28.0.0.3</Version>
    </PackageReference>
    <PackageReference Include="Com.OneSignal">
      <Version>3.10.4</Version>
    </PackageReference>
  </ItemGroup>

https://github.com/jkasten2/Xamarin-AndroidAPI30-OneSignal3.10.4/blob/f6013b6ef086b7a7a4455dd89ecbdcea71140f4f/OneSignalXamarinTest.Android/OneSignalXamarinTest.Android.csproj#L55-L70

2. Android versions

What Android versions does this error happen on?

rarendra commented 3 years ago

I am facing the same issue,

Platform: xamarin forms Android 11 com.onesignal nuget version: 3.10.6

Steps to repeat

  1. Send Notification to app in release mode, app crashes, in debug works fine. Stack Trace java.lang.InstantiationException: java.lang.Class cannot be instantiated java.lang.Class.newInstance Class.java android.app.AppComponentFactory.instantiateService AppComponentFactory.java:129 androidx.core.app.CoreComponentFactory.instantiateService android.app.ActivityThread.handleCreateService ActivityThread.java:4598

Package References in Forms Project

 <ItemGroup>
    <PackageReference Include="Com.OneSignal" Version="3.10.6" />
    <PackageReference Include="Microsoft.AppCenter.Analytics" Version="4.3.0" />
    <PackageReference Include="Microsoft.AppCenter.Crashes" Version="4.3.0" />
    <PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
    <PackageReference Include="NodaTime" Version="3.0.5" />
    <PackageReference Include="NodaTime.NetworkClock" Version="2.0.0" />
    <PackageReference Include="sqlite-net-pcl" Version="1.8.0-beta" />
    <PackageReference Include="Toasts.Forms.Plugin" Version="3.3.2" />
    <PackageReference Include="Xam.Plugin.Media" Version="5.0.1" />
    <PackageReference Include="Xam.Plugin.SimpleAudioPlayer" Version="1.4.0" />
    <PackageReference Include="Xamarin.Forms" Version="5.0.0.2012" />
    <PackageReference Include="Xamarin.Essentials" Version="1.6.1" />
    <PackageReference Include="Xamarin.Forms.GoogleMaps" Version="3.3.0" />
  </ItemGroup>

Package References in Android Project

<ItemGroup>
    <PackageReference Include="Toasts.Forms.Plugin">
      <Version>3.3.2</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Android.Support.CustomTabs">
      <Version>28.0.0.3</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Android.Support.Design">
      <Version>28.0.0.3</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.AndroidX.Browser">
      <Version>1.3.0.5</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.AndroidX.Lifecycle.LiveData">
      <Version>2.3.1</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Firebase.Crashlytics">
      <Version>118.0.1</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Firebase.Messaging">
      <Version>122.0.0</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Forms" Version="5.0.0.2012" />
    <PackageReference Include="Xamarin.Essentials" Version="1.6.1" />
    <PackageReference Include="Xamarin.Forms.GoogleMaps">
      <Version>4.0.0-BETA1</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Forms.Maps">
      <Version>5.0.0.2012</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Google.Android.Material">
      <Version>1.3.0.1</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Google.Dagger">
      <Version>2.37.0</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.GooglePlayServices.Base">
      <Version>117.6.0</Version>
    </PackageReference>
  </ItemGroup>
ghost commented 2 years ago

Any updates on this ? am getting it on my app in the same way first crashes then continues normally .... i have been on this for a whole day

salahAldeen98 commented 2 years ago

i fix this issue by disable startup tracing and set code shrinking to none

tanaynigam commented 2 years ago

@QuangKhanDo 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