OneSignal / OneSignal-Unity-SDK

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

[Bug]: AndroidJavaException: java.lang.ClassNotFoundException: com.onesignal.OneSignal #562

Open GorkemSvn opened 1 year ago

GorkemSvn commented 1 year ago

What happened?

Update: I've figured out unity's proguard minify doesn't include some dependencies onesignal needs, resulting one signal initialization to fail. I can't disable minify because i can't build without it. So onesignal needs to patch itself to be compatible with proguard minify.

It looks like unity's single dex file is not enought to hold firebase firestore,auth and onesignal and using minify breaks things

I'm followed one signal unity sdk setup steps , no problems in editor. Wrote single line of code in my notificationsmanager c# script( OneSignal.Default.Initialize("xcvsdv");) But when i had built in my samsung phone a70, i didn't receive any notification ( i sent notification from dashbouard.) I noticed my phone haven't subscribed to audience. And got this message from autoconnected profiler

note: i did not do steps for amazon-store

AndroidJavaException: java.lang.ClassNotFoundException: com.onesignal.OneSignal image

image

Steps to reproduce?

1. open empty project
2. import onesignal sdk
3. use unity's minify at publish settings to build
4. enable autoconnect profiler
5. classnotfound exception: com.onesignal.onesignal at mobile phone

What did you expect to happen?

App to subscribe to onesignal audience

Unity version

2020.3.42

OneSignal Unity SDK version

3.0.6

Platform

Android

Relevant log output

No response

Code of Conduct

GorkemSvn commented 1 year ago

Update I've updated sdk to 3.0.7 Created an empty project(unity 2020.3.42), imported onesignal sdk. get a build while minify is off. Saw my phone succesfully register to audience of onesignal enabled the minify, cleared the audience from onesignal site. got another build no audience registered. fail

ridwanfauzy commented 1 year ago

Perbarui Saya telah memperbarui sdk ke 3.0.7 Membuat proyek kosong (unity 2020.3.42), mengimpor sdk satu sinyal. dapatkan build saat minify tidak aktif. Melihat ponsel saya berhasil mendaftar ke audiens onesignal mengaktifkan minify, menghapus audiens dari situs onesignal. mendapat build lain, tidak ada audiens yang terdaftar. gagal

Can we build now using minify?

jkasten2 commented 1 year ago

Can you try adding this line to your Proguard config:

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

This will ensure all OneSignal classes are kept when minifying. You can consider this as a work around for now.

We will look into designing a Proguard config that can still allow some minification to OneSignal and include it in a future update so a manual step won't alway be required.

GorkemSvn commented 1 year ago

Okay I’ll try it. Thanks!

From: Josh @.> Sent: Friday, May 5, 2023 18:55 To: @.> Cc: @.>; @.> Subject: Re: [OneSignal/OneSignal-Unity-SDK] [Bug]: AndroidJavaException: java.lang.ClassNotFoundException: com.onesignal.OneSignal (Issue #562)

Can you try adding this line to your Proguard config:

-keep com.onesignal.* { ; }

This will ensure all OneSignal classes are kept when minifying. You can consider this as a work around for now.

We will look into designing a Proguard config that can still allow some minification to OneSignal and include it in a future update so a manual step won't alway be required.

— Reply to this email directly, view it on GitHubhttps://github.com/OneSignal/OneSignal-Unity-SDK/issues/562#issuecomment-1536457023, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AKPMVB4UTAJ5CR54KXZ7K7LXEUPFXANCNFSM6AAAAAASLAK7SE. You are receiving this because you authored the thread.Message ID: @.***>

pus2meong commented 5 months ago

I have the same issue. I test on editor, no error found. I build the apk, and test it on my android phone, nothing happen. It should have asking to subscribe or something, right? I check on onesignal dashboard, no entry at all.

I found out that the code went error when calling this line: OneSignal.Initialize("MY ONE SIGNAL ID"); Using try and catch in the build apk, I managed to print to text UI, the error message from exception variable: java.lang.ClassNotFoundException: com.onesignal.OneSignal

I don't use proguard, I just follow the step from onesignal unity sdk setup steps. I don't use any other plugins, just this one.

jacoposcala commented 5 months ago

Same issue. No proguard/minify active. Using the last OneSignal version "5.0.5" and Unity 2022.3.2. Getting_ java.lang.ClassNotFoundException: com.onesignal.OneSignal on android build

jkasten2 commented 3 months ago

On this ClassNotFoundException with OneSignal-Unity-SDK v5 versions, this should have been fixed when updating to OneSignal-Unity-SDK 5.0.3, however it is important you follow this step from the release notes if coming from an older SDK version:

You must run the "Copy Android plugin to Assets" step in Window > OneSignal SDK Setup.

Please let us know if following this step fixes the issue for you. If not please provide an example Unity project so we can produce the issue on our end.