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

[Bug]: consumer-proguard-rules.pro - Out of date for version 5.0.0 #1810

Closed
1 task done
michael-winkler opened this issue Aug 22, 2023 · 33 comments
Closed
1 task done

Comments

@michael-winkler
Copy link

michael-winkler commented Aug 22, 2023

What happened?

Out of date for version 5.0.0

https://github.com/OneSignal/OneSignal-Android-SDK/blob/main/OneSignalSDK/onesignal/consumer-proguard-rules.pro

We regret to inform you that the current Consumer ProGuard rules included in your project for OneSignal version 5.0.0 are no longer up to date. This is due to recent changes in class and method names within the OneSignal SDK.

To ensure the smooth functioning and proper optimization of your application, it's imperative to update the ProGuard rules in accordance with the latest version of OneSignal. Failing to do so might lead to unexpected behavior, decreased performance, or even app crashes.

Steps to reproduce?

-

What did you expect to happen?

Updated proguard rules for OneSignal version 5.0.0

OneSignal Android SDK version

5.0.0

Android version

13, 12, 11, 10, 9, 8, 7.1, 7.0, 6, 5.1, 5.0, 4.4, 4.3 or below

Specific Android models

No response

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@michael-winkler
Copy link
Author

see also my coment here #1779 (comment)

@jennantilla
Copy link
Contributor

Hello @michael-winkler thank you for reaching out! We'll look into this and get back to you as soon as possible.

@michael-winkler
Copy link
Author

Any news? @jennantilla

@michael-winkler
Copy link
Author

I tried to convert the rules by myself.

-dontwarn com.onesignal.**

# These 2 methods are called with reflection.
-keep class com.google.android.gms.common.api.GoogleApiClient {
    void connect();
    void disconnect();
}

I dont know the new correct lines for these:


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

# Observer backcall methods are called with reflection
-keep class com.onesignal.OSSubscriptionState {
    void changed(com.onesignal.OSPermissionState);
}

-keep class com.onesignal.OSPermissionChangedInternalObserver {
    void changed(com.onesignal.OSPermissionState);
}

-keep class com.onesignal.OSSubscriptionChangedInternalObserver {
    void changed(com.onesignal.OSSubscriptionState);
}

And here is the rest which i converted:

-keep class * implements com.onesignal.notifications.IPermissionObserver{
    void onNotificationPermissionChange(java.lang.Boolean);
}

-keep class * implements com.onesignal.user.subscriptions.IPushSubscriptionObserver {
    void onPushSubscriptionChange(com.onesignal.user.subscriptions.PushSubscriptionChangedState);
}

-keep class com.onesignal.notifications.internal.badges.impl.shortcutbadger.impl.AdwHomeBadger { <init>(...); }
-keep class com.onesignal.notifications.internal.badges.impl.shortcutbadger.impl.ApexHomeBadger { <init>(...); }
-keep class com.onesignal.notifications.internal.badges.impl.shortcutbadger.impl.AsusHomeBadger { <init>(...); }
-keep class com.onesignal.notifications.internal.badges.impl.shortcutbadger.impl.DefaultBadger { <init>(...); }
-keep class com.onesignal.notifications.internal.badges.impl.shortcutbadger.impl.EverythingMeHomeBadger { <init>(...); }
-keep class com.onesignal.notifications.internal.badges.impl.shortcutbadger.impl.HuaweiHomeBadger { <init>(...); }
-keep class com.onesignal.notifications.internal.badges.impl.shortcutbadger.impl.LGHomeBadger { <init>(...); }
-keep class com.onesignal.notifications.internal.badges.impl.shortcutbadger.impl.NewHtcHomeBadger { <init>(...); }
-keep class com.onesignal.notifications.internal.badges.impl.shortcutbadger.impl.NovaHomeBadger { <init>(...); }
-keep class com.onesignal.notifications.internal.badges.impl.shortcutbadger.impl.OPPOHomeBader { <init>(...); }
-keep class com.onesignal.notifications.internal.badges.impl.shortcutbadger.impl.SamsungHomeBadger { <init>(...); }
-keep class com.onesignal.notifications.internal.badges.impl.shortcutbadger.impl.SonyHomeBadger { <init>(...); }
-keep class com.onesignal.notifications.internal.badges.impl.shortcutbadger.impl.VivoHomeBadger { <init>(...); }
-keep class com.onesignal.notifications.internal.badges.impl.shortcutbadger.impl.XiaomiHomeBadger { <init>(...); }
-keep class com.onesignal.notifications.internal.badges.impl.shortcutbadger.impl.ZukHomeBadger { <init>(...); }

-dontwarn com.amazon.**

# Proguard ends up removing this class even if it is used in AndroidManifest.xml so force keeping it.
-keep public class com.onesignal.notifications.services.ADMMessageHandler {*;}

-keep class com.onesignal.JobIntentService$* {*;}

-keep class ** implements com.onesignal.notifications.INotificationServiceExtension{
   void onNotificationReceived(com.onesignal.notifications.INotificationReceivedEvent);
}

@michael-winkler
Copy link
Author

Maybe this line is needed to:

-keep class com.onesignal.user.subscriptions.** { *; }

@ahmtbrk
Copy link

ahmtbrk commented Sep 3, 2023

Maybe this line is needed to:

-keep class com.onesignal.user.subscriptions.** { *; }

I am getting the following error even though I have defined all the proguard rules. Also i see on firebase crashlytics.
com.onesignal.OneSignal.initWithContext (OneSignal.kt:126)
com.onesignal.core.internal.operations.impl.OperationModelStore.create (OperationModelStore.kt:58)
Unrecognized operation: login-user-from-subscription

@Petr-Kubista
Copy link

OneSignal.initWithContext is crashing at getService even with updated proguard rules on 5.0.1

@michael-winkler
Copy link
Author

@Petr-Kubista Please provide more details that OneSignal can find the bug.
@emawby Please look again into the proguard rules. It looks like 5.0.1 does not fix the problem.

@michael-winkler
Copy link
Author

It would be great if we also can see a new file like this https://github.com/OneSignal/OneSignal-Android-SDK/blob/main/OneSignalSDK/onesignal/consumer-proguard-rules.pro which contains all new rules.

@Petr-Kubista
Copy link

@michael-winkler the situation is described in a related issue:
#1811

@emawby
Copy link
Contributor

emawby commented Sep 11, 2023

@Petr-Kubista Which class is it not able to find? I am no longer able to reproduce the issue on 5.0.1

@michael-winkler
Copy link
Author

@emawby I think @Petr-Kubista means this one:
java.lang.Exception: Service class com.onesignal.core.internal.config.ConfigModelStore could not be instantiated

@emawby
Copy link
Contributor

emawby commented Sep 11, 2023

I am not able to reproduce that problem on 5.0.1. Does your app have any custom proguard rules set?

@jdonlan
Copy link

jdonlan commented Sep 12, 2023

I can verify that the issue still happens on 5.0.1 using the included consuer-proguard rules.

@emawby
Copy link
Contributor

emawby commented Sep 12, 2023

@jdonlan can you clarify what you mean by "included consumer-proguard rules". Do you have custom rules that are running?

Are you getting this error or something else?

com.onesignal.OneSignal.initWithContext (OneSignal.kt:126)
com.onesignal.core.internal.operations.impl.OperationModelStore.create (OperationModelStore.kt:58)
Unrecognized operation: login-user-from-subscription

@jdonlan
Copy link

jdonlan commented Sep 12, 2023

@jdonlan can you clarify what you mean by "included consumer-proguard rules". Do you have custom rules that are running?

Are you getting this error or something else?

com.onesignal.OneSignal.initWithContext (OneSignal.kt:126)
com.onesignal.core.internal.operations.impl.OperationModelStore.create (OperationModelStore.kt:58)
Unrecognized operation: login-user-from-subscription

I'm using these rules: https://github.com/OneSignal/OneSignal-Android-SDK/blob/main/OneSignalSDK/onesignal/consumer-proguard-rules.pro provided in your repo.

Fatal Exception: java.lang.NullPointerException:
at com.onesignal.inAppMessages.internal.display.impl.WebViewManager.showMessageView(WebViewManager.java:228)
at com.onesignal.inAppMessages.internal.display.impl.WebViewManager.access$showMessageView(WebViewManager.java)
at com.onesignal.inAppMessages.internal.display.impl.WebViewManager$showMessageView$1.invokeSuspend(WebViewManager.java:12)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(BaseContinuationImpl.java:8)
at kotlinx.coroutines.UndispatchedCoroutine.afterResume(UndispatchedCoroutine.java:53)
at kotlinx.coroutines.AbstractCoroutine.resumeWith(AbstractCoroutine.java:22)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(BaseContinuationImpl.java:31)
at kotlinx.coroutines.DispatchedTaskKt.resume(DispatchedTask.kt:52)
at kotlinx.coroutines.DispatchedTaskKt.dispatch(DispatchedTask.kt:137)
at kotlinx.coroutines.CancellableContinuationImpl.dispatchResume(CancellableContinuationImpl.java:137)
at kotlinx.coroutines.CancellableContinuationImpl.resumeImpl(CancellableContinuationImpl.java:44)
at kotlinx.coroutines.CancellableContinuationImpl.resumeImpl$default(CancellableContinuationImpl.java:23)
at kotlinx.coroutines.CancellableContinuationImpl.resumeUndispatched(CancellableContinuationImpl.java:23)
at kotlinx.coroutines.android.HandlerContext$scheduleResumeAfterDelay$$inlined$Runnable$1.run(HandlerContext.java:6)
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8757)
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:1067)

@jdonlan
Copy link

jdonlan commented Sep 12, 2023

With 5.0.1 and the above proguard rules, I can init OneSignal and even show an In-App notification, but then get this crash shortly after.

@emawby
Copy link
Contributor

emawby commented Sep 12, 2023

@jdonlan This looks like a separate issue with an InAppMessage crashing when trying to be displayed. Could you kindly create a separate issue on the repository for this problem?

@jdonlan
Copy link

jdonlan commented Sep 12, 2023

It isn't though, as this ticket is concerning proguard rules and this issue only occurs after minification.

@emawby
Copy link
Contributor

emawby commented Sep 12, 2023

Oh I see ok I am able to successfully display InAppMessages in my testing as well. I don't believe that you should need to add those proguard rules to your app yourself since the relevant rules are already included in 5.0.1 of the SDK. Are you able to get the same issue on a blank app with just a OneSignal integration?

@jdonlan
Copy link

jdonlan commented Sep 12, 2023

I have been able to confirm functionality in 5.0.1 and that it no longer crashes related to proguard. I'll open a separate ticket with the above, as I get the same crash without custom proguard rules on debug builds now.

@michael-winkler
Copy link
Author

@emawby Why are the rules below not added for the new proguard rules?

-keep class com.onesignal.notifications.internal.badges.impl.shortcutbadger.impl.AdwHomeBadger { <init>(...); }
-keep class com.onesignal.notifications.internal.badges.impl.shortcutbadger.impl.ApexHomeBadger { <init>(...); }
-keep class com.onesignal.notifications.internal.badges.impl.shortcutbadger.impl.AsusHomeBadger { <init>(...); }
-keep class com.onesignal.notifications.internal.badges.impl.shortcutbadger.impl.DefaultBadger { <init>(...); }
-keep class com.onesignal.notifications.internal.badges.impl.shortcutbadger.impl.EverythingMeHomeBadger { <init>(...); }
-keep class com.onesignal.notifications.internal.badges.impl.shortcutbadger.impl.HuaweiHomeBadger { <init>(...); }
-keep class com.onesignal.notifications.internal.badges.impl.shortcutbadger.impl.LGHomeBadger { <init>(...); }
-keep class com.onesignal.notifications.internal.badges.impl.shortcutbadger.impl.NewHtcHomeBadger { <init>(...); }
-keep class com.onesignal.notifications.internal.badges.impl.shortcutbadger.impl.NovaHomeBadger { <init>(...); }
-keep class com.onesignal.notifications.internal.badges.impl.shortcutbadger.impl.OPPOHomeBader { <init>(...); }
-keep class com.onesignal.notifications.internal.badges.impl.shortcutbadger.impl.SamsungHomeBadger { <init>(...); }
-keep class com.onesignal.notifications.internal.badges.impl.shortcutbadger.impl.SonyHomeBadger { <init>(...); }
-keep class com.onesignal.notifications.internal.badges.impl.shortcutbadger.impl.VivoHomeBadger { <init>(...); }
-keep class com.onesignal.notifications.internal.badges.impl.shortcutbadger.impl.XiaomiHomeBadger { <init>(...); }
-keep class com.onesignal.notifications.internal.badges.impl.shortcutbadger.impl.ZukHomeBadger { <init>(...); }

Do we really not longer need them?
Because they was there https://github.com/OneSignal/OneSignal-Android-SDK/blob/main/OneSignalSDK/onesignal/consumer-proguard-rules.pro

And what is with the rest of rules? Not all old rules are added to new rules that. But why?

@Petr-Kubista
Copy link

@emawby For me it's still not working on OneSignal 5.0.1:

java.lang.RuntimeException: Unable to create application org.xxx.Application: java.lang.Exception: Service interface ja.a could not be instantiated
	at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7053)
	at android.app.ActivityThread.access$1800(ActivityThread.java:254)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2184)
	at android.os.Handler.dispatchMessage(Handler.java:106)
	at android.os.Looper.loopOnce(Looper.java:233)
	at android.os.Looper.loop(Looper.java:344)
	at android.app.ActivityThread.main(ActivityThread.java:8212)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:584)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1034)
Caused by: java.lang.Exception: Service interface ja.a could not be instantiated
	at e9.d.getService(Unknown Source:58)
	at com.onesignal.internal.OneSignalImp.initWithContext(Unknown Source:235)
	at com.onesignal.OneSignal.g(Unknown Source:16)
	at org.xxx.Application.p(Unknown Source:7)
	at org.xxx.Application.onCreate(Unknown Source:180)
	at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1226)
	at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7046)
	at android.app.ActivityThread.access$1800(ActivityThread.java:254) 
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2184) 
	at android.os.Handler.dispatchMessage(Handler.java:106) 
	at android.os.Looper.loopOnce(Looper.java:233) 
	at android.os.Looper.loop(Looper.java:344) 
	at android.app.ActivityThread.main(ActivityThread.java:8212) 
	at java.lang.reflect.Method.invoke(Native Method) 
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:584) 
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1034) 

This is happening during Application.onCreate. When I include this line in my proguard-rules, the crash doesn't happen:
-keep class com.onesignal.** { *; }

@emawby
Copy link
Contributor

emawby commented Sep 18, 2023

@Petr-Kubista If possible could you share your code that initializes/sets up OneSignal. I would like to reproduce the crash to figure out exactly which service interface is missing.

@Petr-Kubista
Copy link

@emawby I have this function being called in Application.onCreate

public void initPushNotifications() {
    if (!AppConfig.DISABLE_NOTIFICATIONS) {
        // OneSignal Initialization
        OneSignal.initWithContext(this, getString(R.string.onesignal_app_id));
        OneSignal.getNotifications().addForegroundLifecycleListener(willDisplayEvent -> {
            if (AppConfig.DISABLE_NOTIFICATIONS || !AppSharedPreferences.isNotificationEnabled()) {
                willDisplayEvent.preventDefault();
            }
        });

        if (oneSignalHandler == null) {
            oneSignalHandler = new OneSignalNotificationOpenedHandler();
            OneSignal.getNotifications().addClickListener(oneSignalHandler);
        }

        sendOneSignalPrimaryServiceTag();

        if (!ServiceModel.isNotificationEnabled()) {
            OneSignal.getUser().getPushSubscription().optOut();
        }

        OneSignal.getInAppMessages().addTrigger(APP_VERSION_TRIGGER_KEY, getAppVersion());
        OneSignal.getDebug().setLogLevel(LogLevel.NONE);
    }
}

@emawby
Copy link
Contributor

emawby commented Sep 19, 2023

@Petr-Kubista I am still not able to reproduce unfortunately. Just to confirm is this still only happening for release builds? If you enable minify in your debug config do you still get the issue? If possible could you enable verbose logging that might help identify which service is not being found

@Petr-Kubista
Copy link

@emawby I am really sorry, it must have been another build clogging up the LogCat for me, I had another app with a different build variant installed and I missed the package name in the logs (it's very similar) and that one had the 5.0.0 version of OneSignal in it. So please disregard, I can't reproduce the error either.

@emawby
Copy link
Contributor

emawby commented Sep 20, 2023

@Petr-Kubista Thank you for investigating! Closing as fixed in 5.0.1

@emawby emawby closed this as completed Sep 20, 2023
@michael-winkler
Copy link
Author

michael-winkler commented Sep 20, 2023

@arthurgeron-work
Copy link

arthurgeron-work commented Sep 21, 2023

I was getting the same error mentioned in #1811, adding these two lines to my project's proguard-rules.pro fixed the crash:

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

@theonetheycallneo
Copy link

Seeing same on 5.0.1

All of our Android users:

image

@arthurgeron-work
Copy link

@theonetheycallneo that's a different error, see #1857

@danielesegato
Copy link

btw this is still not fixed in version 5.0.4. no idea how you can close as fixed...

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

9 participants