Conversation
If the app project had android.enableR8.fullMode=true (default true with AGP 8+) the stub classes that start with "misconfigured" would removed. This would cause a "could not be instantiated" exception to be thrown when initializing as the code assumes there would be some class that implements the interface, an example INotificationsManager. The stub classes are removed in the minification step since they are created with reflection via ServiceProvider.getService(). Anytime reflection is used there you must add special Proguard consumer rules to keep those classes. In this case we only need to make sure the class itself exists, so we use "<init>(...);" in the rule which means keep the default constructor.
We need to ensure the exception is created at the time of the call instead of upfront. As the stack trace reported by the exception is when it is instantiated.
5e062fd to
61590d2
Compare
1 task
Merged
This was referenced Jul 2, 2024
This was referenced Jul 3, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
One Line Summary
Fix "could not be instantiated" exception when; some modules are omitted AND
android.enableR8.fullModeis enabled.Details
This also fixes the stack traces reported when attempting to use a module that wasn't included 2b2e76a
Motivation
This results in crashes when these two conditions are meet. SDK should include all Proguard rules so app developers don't have to manually add them to avoid issues like this.
Scope
Only effects keeping a bit more code when minification is enabled.
Testing
Manual testing
Tested with the included example app with the following modifications:
android.enableR8.fullMode=truetoExamples/OneSignalDemo/gradle.propertiescom.onesignal:OneSignal:5.1.15withcom.onesignal:core:5.1.15inExamples/OneSignalDemo/app/buidle.gradleReproduced the crash reported in issue #1969 and ensured it no longer happens after the change. Tested on an Android 6.0 emulator.
Affected code checklist
Checklist
Overview
Testing
- CI doesn't currently build or run the demo app.
Final pass
This change is