-
Notifications
You must be signed in to change notification settings - Fork 370
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]: has no zero argument constructor while creating class in reflection - R8 #1779
Comments
Converted the code of the NotificationServiceExtension to Java and still getting this error |
I can confirm that it is bug related in the R8! Since the service extension is an unused class, i think it is removed or shrinked by proguard! Timber.i("fix ${NotificationServiceExtension()}") // or just creating instance of the class that will be created by reflection could work before calling OneSignal.init fixed for me! |
@iballan thank you for the additional details and following up with what works for you! We'll look into potentially adding some documentation around this. Let us know if you have any additional questions or concerns! |
From the stack trace it seems like |
@sgjesse I agree with you, OneSignal developers agree with you too, That's why they added this rule:
in their proguard. Timber.i("fix ${NotificationServiceExtension()}") // this indicate that the class is used for R8 was the only solution for me for now. |
Isn't it then just the keep rule missing keeping the no-args constructor?
The exception java.lang.InstantiationException: java.lang.Class<com.mypackage.app.NotificationServiceExtension> has no zero argument constructor indicate that the class has not been removed. R8 should not remove anything which has an unconditional keep rukle. |
@sgjesse -keep class my.package.NotificationServiceExtension { *; }
-keep classmembers my.package.NotificationServiceExtension { *; }
-keep public class my.package.NotificationServiceExtension { public protected *; } Unfortunately nothing worked! still R8 removed it's constructor or removed it completely since it is not used or referenced anywhere in the code |
If you have the keep rule
then the class Same for the |
@sgjesse yeah thats why I reported this issue! |
That sounds like the configuration is not correctly passed to the compiler. Could you try to add the following rule:
That should work, as that keeps everything in the application. If that does not work then the configuration is not picked up. If it works, when the configuration is picked up, but maybe the class name for |
Adding this to my modules
|
Fix in my case was to add:
to my |
@tajchert, are you doing reflection into classes in the OneSignal SDK? If not then library has consumer keep rules defined in |
Should this:
not be changed to this:
for 'com.onesignal:OneSignal:5.0.0' ? |
Same issue. In 5.0.x we have to manually keep (the @sgjesse workaround) our implementation of the INotificationServiceExtension or R8 removes it and we get the trace about the no zero argument constructor. Suggestion: internally OneSignal should create a sample app that overrides INotificationServiceExtension, INotificationClickListener, and IPushSubscriptionObserver that you build with r8 and verify as part of automated testing for your library. |
Thanks for your suggestion, we have had no further reports of this so I will close out this issue. If this is still a problem, please open a new report with updated information. |
What happened?
Error while initializing OneSignal with custom Notification Service Extension
This crash took place after upgrading gradle version and the default is now R8 enabled
Steps to reproduce?
What did you expect to happen?
While initializing onesignal, it is trying to create instance of the service extension. there it crashes. The extension class is written in Kotlin, that can be the reason with R8 it has no constructor maybe
OneSignal Android SDK version
Release 4.8.6
Android version
12, 11, 10
Specific Android models
No response
Relevant log output
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: