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

[question]: Unable to instantiate receiver on Android #728

Closed
1 task done
Rashber opened this issue May 8, 2024 · 6 comments
Closed
1 task done

[question]: Unable to instantiate receiver on Android #728

Rashber opened this issue May 8, 2024 · 6 comments

Comments

@Rashber
Copy link

Rashber commented May 8, 2024

How can we help?

I've lately updated the onesignal sdk from 3.0.6 to 5.1.4 (installed from the asset store), running unity 2022.3.21.
in a large portion of android devices i keep seeing this runtime error

`Caused by java.lang.ClassNotFoundException: Didn't find class "com.onesignal.BootUpReceiver" on path: DexPathList[...]`
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:218)
       at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
       at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
       at android.app.AppComponentFactory.instantiateReceiver(AppComponentFactory.java:110)
       at androidx.core.app.CoreComponentFactory.instantiateReceiver(CoreComponentFactory.java:60)
       at android.app.ActivityThread.handleReceiver(ActivityThread.java:4801)
       at android.app.ActivityThread.access$1800(ActivityThread.java:315)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2297)
       at android.os.Handler.dispatchMessage(Handler.java:106)
       at android.os.Looper.loopOnce(Looper.java:226)
       at android.os.Looper.loop(Looper.java:313)
       at android.app.ActivityThread.main(ActivityThread.java:8751)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)

this error appears for both UpgradeReceiver and BootUpReceiver.
this is the onesignal block from my manifest

<receiver android:name="com.onesignal.UpgradeReceiver" android:exported="true">
      <intent-filter>
        <action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
      </intent-filter>
    </receiver>
    <receiver android:name="com.onesignal.BootUpReceiver" android:exported="true">
      <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED" />
        <action android:name="android.intent.action.QUICKBOOT_POWERON" />
      </intent-filter>
    </receiver>
    <activity android:name="com.onesignal.NotificationOpenedActivityHMS" android:theme="@android:style/Theme.Translucent.NoTitleBar" tools:replace="android:exported" android:exported="false">
      <intent-filter>
        <action android:name="android.intent.action.VIEW" />
      </intent-filter>
    </activity>

tried removing one signal package, and installing it both from the asset store again, and through the scoped registry, and got the same errors.
followed the instructions here: https://documentation.onesignal.com/docs/unity-sdk-setup
In some devices I still manage to get notifications, despite the errors.
any advice on what might have gone wrong?

Code of Conduct

  • I agree to follow this project's Code of Conduct
@shepherd-l
Copy link
Contributor

Thanks for reporting! Your manifest looks to still have old v3 OneSignal code which was changed in v5.

(For context, v5 does not have com.onesignal.UpgradeReceiver or com.onesignal.BootUpReceiver and was changed to com.onesignal.notifications.receivers.UpgradeReceiver and com.onesignal.notifications.receivers.BootUpReceiver)

Could you make sure to run all the steps in Window > OneSignal SDK Setup and to resolve your Android dependencies with Assets > External Dependency Manager > Android Resolver > Force Resolve

Let me know if you are still experiencing the issue

@Rashber
Copy link
Author

Rashber commented May 8, 2024

Thanks for the reply! I ran all the steps a few times, and ran the installation process again and again. And deleting all references in between to start fresh.
I tried deleting this block of code, and after reinstalling, resolving and running the setup, this block kept re-appearing with the same class namespace.
Can I assume that by changing the class path to the path you've wrote, it might solve it?

Any chance I can have the right manifest block for all oneSignal related receivers / activities, so I can compare and see what's missing?

@shepherd-l
Copy link
Contributor

shepherd-l commented May 8, 2024

Thanks for the detailed update! I think you might still have some old files that are inserting the old dependencies. Have you followed the Migration v3 to v5 Guide? If you haven't already, I recommend doing:

  1. Delete the directory at Assets/OneSignal
  2. In Unity, open Window > Package Manager
  3. From the Package Manager window, select Packages: in the top left and click on My Assets
  4. Select the OneSignal SDK from the list and press the Update button.
  5. Once the update has completed, click the Import button
  6. Navigate to Window > OneSignal SDK Setup
  7. Click Run All Steps
  8. Navigate back to the menu at Window > OneSignal SDK Setup to see if there are any remaining steps to run

I think "Deleting the directory at Assets/OneSignal" is the step you may have missed. I tested upgrading from 3.0.6 to 5.1.4 on a blank project with the following steps and my Android manifest is updated. If this was the issue, I apologize for the confusion and will update our docs to make this clear.

Can I assume that by changing the class path to the path you've wrote, it might solve it?

I think this could solve it but you would need to export your Unity project and manually edit your APK's manifest every time. Ideally I think it would be better if the project exported the APK correctly.

Any chance I can have the right manifest block for all oneSignal related receivers / activities, so I can compare and see what's missing?

If the above doesn't work, I can provide the manifest of our example project's APK for you! You can also produce one with a new blank project with 5.1.4

@Rashber
Copy link
Author

Rashber commented May 9, 2024

Thanks for the reply!
I opened a fresh new project, downloaded and installed OneSignal 5.1.4 through the package manager, following all the stages, and yet it did not add the references to the manifest.
I see the OnesSignal folder, and all of it's dependencies in my project, the "OneSignal SDK setup" worked fine without errors, and so did the "Force Resolve".
At this point i'm at lost, and reverted to 3.0.12.

@shepherd-l
Copy link
Contributor

3.x.x to 5.x.x upgrade

Are you able to reproduce the crash yourself or are you only seeing crash reports?

It sounds like the 3.x.x SDK is not fully being removed due to some unknown reason, as the reference to some of the classes are not being cleaned up such as com.onesignal.UpgradeReceiver. Could you fully remove OneSignal again ensuring that the manifest entries are completely removed from all AndroidManifest.xml files? Making sure all pieces of OneSignal are removed is critical here, search your full Unity project for any OneSignal references. Restart Unity and then install OneSignal 5.x.x SDK again.

Fresh new project with 5.x.x

When you tested a fresh new project, how did you check the manifest references? Did you run into any crashes on the new project?
In 5.x.x, the manifest entires for OneSignal are not visible within Unity. The only way you would see them is if you extract it from the resulting APK.

Did you see any runtime crashes after building the new project with OneSignal?

@shepherd-l
Copy link
Contributor

Closing due to inactivity. If you are still having issues, feel free to open a new issue

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

2 participants