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

[Fix] "could not be instantiated" exception when; some modules are omitted AND android.enableR8.fullMode=true #2136

Merged
merged 3 commits into from
Jun 27, 2024

Conversation

jkasten2
Copy link
Member

@jkasten2 jkasten2 commented Jun 26, 2024

Description

One Line Summary

Fix "could not be instantiated" exception when; some modules are omitted AND android.enableR8.fullMode is 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:

  • Added android.enableR8.fullMode=true to Examples/OneSignalDemo/gradle.properties
  • Replaced com.onesignal:OneSignal:5.1.15 with com.onesignal:core:5.1.15 in Examples/OneSignalDemo/app/buidle.gradle
  • Modified OneSignalDemo's code no longer call things that require modules;

Reproduced 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

  • Notifications
    • Display
    • Open
    • Push Processing
    • Confirm Deliveries
  • Outcomes
  • Sessions
  • In-App Messaging
  • REST API requests
  • Public API changes

Checklist

Overview

  • I have filled out all REQUIRED sections above
  • PR does one thing
    • If it is hard to explain how any codes changes are related to each other then it most likely needs to be more than one PR
  • Any Public API changes are explained in the PR details and conform to existing APIs

Testing

  • I have included test coverage for these changes, or explained why they are not needed
    - CI doesn't currently build or run the demo app.
  • All automated tests pass, or I explained why that is not possible
  • I have personally tested this on my device, or explained why that is not possible

Final pass

  • Code is as readable as possible.
  • I have reviewed this PR myself, ensuring it meets each checklist item

This change is Reviewable

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.
@jkasten2 jkasten2 force-pushed the fix/minification_missing_stubs branch from 5e062fd to 61590d2 Compare June 26, 2024 19:16
@jkasten2 jkasten2 assigned jkasten2 and jinliu9508 and unassigned jkasten2 Jun 26, 2024
@jkasten2 jkasten2 changed the title [Fix] "could not be instantiated" exception when; some module are omitted AND android.enableR8.fullMode=true [Fix] "could not be instantiated" exception when; some modules are omitted AND android.enableR8.fullMode=true Jun 26, 2024
Copy link
Contributor

@jinliu9508 jinliu9508 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!!!

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

Successfully merging this pull request may close these issues.

None yet

2 participants