-
Notifications
You must be signed in to change notification settings - Fork 369
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
Proguard -assumenosideeffects Compatibility #1492
Conversation
Fix compatibility issue with apps that use -assumenosideeffects with java.lang.Class.getName() with progurad or dexguard. No issue with R8. Addressed this by adding a new private hasClass method and utilized it in all existing class exist helper methods. This method has the "Keep" annotation on it so proguard will never change it's code and will not make a wrong assumptions about side effects.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 0 of 1 files reviewed, 1 unresolved discussion (waiting on @Jeasmine, @jkasten2, @nan-li, and @rgomezp)
OneSignalSDK/onesignal/src/main/java/com/onesignal/OSUtils.java, line 161 at r1 (raw file):
static boolean hasFCMLibrary() { try { return hasClass(com.google.firebase.messaging.FirebaseMessaging.class);
Isn't this (and the additional below) try/catch redundant now?
The extra getName and catch housed in hasClass was not needed after further testing. Renamed to opaqueHasClass to provide a more specific name to what it does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 0 of 1 files reviewed, 1 unresolved discussion (waiting on @adamschlesinger, @Jeasmine, @nan-li, and @rgomezp)
OneSignalSDK/onesignal/src/main/java/com/onesignal/OSUtils.java, line 161 at r1 (raw file):
Previously, adamschlesinger (Adam Schlesinger) wrote…
Isn't this (and the additional below) try/catch redundant now?
I simplified the code in hasClass
(renamed to opaqueHasClass
) so the 2nd catch isn't needed. I also updated my PR description to show the smali code differences and the configs I used to test with.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 1 files at r2, all commit messages.
Reviewable status: complete! all files reviewed, all discussions resolved (waiting on @Jeasmine, @nan-li, and @rgomezp)
Description
One Line Summary
Fix compatibility issue with apps that use
-assumenosideeffects
withjava.lang.Class.getName()
with Proguard or Dexguard. (No issue with R8.)Details
Motivation
To fix issue #1423 which cause a crash on some devices when aggressive minification setting
-assumenosideeffects
withjava.lang.Class.getName()
is used.Scope
This effects code paths that check if a Java class exists for feature detection. No logic was changed, just a proxy class was added to prevent Proguard from striping code.
How this prevents the issue
Addressed this by adding a new private
opaqueHasClass
method and utilized it in all existing class exist helper methods.This method has the "Keep" annotation on it so proguard will never change it's code and will not make a wrong assumptions about side effects.
Before code change
Here in the smali output you can see the try-catch was removed by Proguard from
hasHMSAvailabilityLibrary
, even when the rule-keep class com.onesignal.OSUtils** {*;}
or@Keep
is added to try to prevent this modification.After code change
After you see
opaqueHasClass
is kept as-is.hasHMSAvailabilityLibrary
is renamed which is ok, the important thing is that the try-catch is kept which is required.Testing
Unit testing
No unit tests where added since this is a build issue and it has to run on a device to verify.
Manual testing
Tested on a FireOS tablet and a Android 12 emulator without the FCM library.
Disabled R8 in
gradle.properties
, this forces the Android Gradle Plugin to use Proguard.Tested with
classpath 'net.sf.proguard:proguard-gradle:6.1.1'
and with the followingproguard-rules.pro
file contents:Affected code checklist
Checklist
Overview
Testing
Final pass
This change is