-
Notifications
You must be signed in to change notification settings - Fork 5
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
[Bug]: OneSignal .net-android error in Initialize call. Java.Lang.NoSuchMethodError #89
Comments
Ok, this is an R8 shrinker issue. I've tried adding some custom proguard rules but I'm struggling to get it to work. -keep public class com.onesignal.** {;} Works to get past the basic method missing errors but then I get the following Java.Lang.Exception...
I thought the keep interface line above would resolve this but it didn't. Any ideas what rules are needed? |
Does anyone have working, R8 shrinker rules for OneSignal on Android? I've tried using older proguard rules from here https://github.com/OneSignal/OneSignal-Android-SDK/blob/main/OneSignalSDK/onesignal/consumer-proguard-rules.pro#L51 but this isn't working with R8 shrinking. Turning off R8 works fine, I'm sure our older Xamarin native project using OneSignal was R8 shrinking so this seems a specific problem in the new .net-android SDK support. Can't seem to get the R8 not to break whatever it is that implements IOperationRepo
|
Is there anyone from OneSignal able to advise on how to use this SDK with R8 shrinking on Android? |
This is the Full Proguard rules i've tried for OneSignal (based off the old Xamarin one and the Android project) but not had any success yet...
|
Example Repo of the issue (using MAUI) https://github.com/IainS1986/OneSignal-R8-Test This is a basic MAUI template (from Rider).
When I run a release configuration build to my phone I get the same exception… FATAL EXCEPTION: main |
Same problema here... |
I had to add this instruction to my Proguard file to fix it: |
When I try adding that I'm getting a whole bunch of R8 errors "A type or variable is not in scope." Can you share your whole proguard file? |
OneSignal - Proguard ends up removing this class even if it is used in AndroidManifest.xml so force keeping it.-dontwarn com.onesignal.** OneSignal - These 2 methods are called with reflection.-keep class com.google.android.gms.common.api.GoogleApiClient { -keep class com.onesignal.** {*;} Keep methods annotated with @JavascriptInterface for webview bridge (InApp feature)-keepclassmembers class * { End OneSignal |
It seems only this was enough for my project. At least for initializing the onesignal. |
Cheers, mayhbe theres something else in my proguard colliding with this, i'll try removing bits and adding bits and see how I go, cheers for pointing this line out though 👍 |
My project is Xamarin and it's using the version 5.0.2. |
Might be the difference too, this is specifically about .net-android 8+ (which you'll have to port over too soon). Hard to tell thought 🤷 |
I don't think it doesn't change much because it's using the onesignal android 5.0.3. It should be the same. |
Proguard effects your entire app. Not just onesignal. So it might fix it, but adding that line breaks some other sections in my proguard that (may) be needed for .net-android, I can't say for sure so will need some time to go through things bit by bit. I think it broke an AndroidX section in my proguard but will see. |
|
I tried to change your maui test app using this configuration. |
When I'm refering the my proguard file thats breaking I'm not referring to that test project, that was for the OneSignal team to investigate. The proguard file I have in another app is much larger. But I'll dig more into it but won't be happening for a week or two |
I narrowed it down to the following lines that break with the keepattributes Signature line,
So I need to figure out the exact bits of AndroidX to keep as opposed to an (ugly) blanket keep on the whole thing |
Ok. After a lot of head banging I think I've resolved the issue. So as @arctouch-rafaelpontes above pointed out, you do need to have this in your proguard,
But, you might (like me) have the following your proguard
These two lines do not work together. Ideally, you shouldn't be just having keep on the whole androidx, but its a faff not doing that if you need it. However you'll need to work out all references you are using in androidx and only include those. This is not fun. Thankfully, someone did a lot of leg work already around this issue they were having with a different library here So from this, I managed to make the following proguard that works, you might have some things still fail that you need to add, but this should work.
If all you want is the specific OneSignal rules
tbh, this might be enough
|
Thanks @IainS1986 for this tip. That got my app back in working order. |
What happened?
Updgrading a Xamarin Native to .net-android and .net-ios project.
Added OneSignalSDK.DotnNet/5.0.2
OneSignal.Initialize("MY KEY");
This line then errors with...
Steps to reproduce?
What did you expect to happen?
It initialises.
Relevant log output
Code of Conduct
The text was updated successfully, but these errors were encountered: