Repository navigation
Android: fix launch crash under R8 optimization - #71
Merged
Merged
Conversation
… (ReactModuleInfo looked up by reflection)
Merged
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.
Problem
Android apps built with R8 and
proguard-android-optimize.txtcrash on every launch.SdkReactNativePackage.getReactModuleInfoProvider()picked aReactModuleInfoconstructor by parameter count (7, else.first { size == 6 }). R8 removes unused constructor parameters, so neither count matched and.firstthrewNoSuchElementExceptionwhile React Native built its module registry. The package shipped no consumer R8 rules, and CI built only a debug example.DiditAuthPackagehad the same lookup.Solution
ReactModuleInfoconstructor directly. It is the primary, non-deprecated constructor on every React Native release from 0.76 to 0.86; the 7-parameter one is the deprecated extra. A future React Native without it would fail the host build, not the app.android/consumer-rules.pro, wired withconsumerProguardFiles, keepsReactModuleInfo's public constructors in every host app. Neither package uses other reflection.proguard-android-optimize.txt. A new CI job builds it, checks the keep rule reached R8, launches it on an emulator and starts a verification, failing on any crash.Verification
yarn lint,yarn typecheckand the newandroid-r8-consumer-rules.test.ts(3 tests) pass. Annpm packarchive containspackage/android/consumer-rules.pro.13cc015: all six jobs pass. The minified release launches, and an offline verification returns a failed result without crashing.Refs #61
Visual proof
Screenshots from the CI job "Minified Android release launches" on an emulator. The example app was built as a release with R8 and
proguard-android-optimize.txt.The app launches without crashing:
Starting a verification with a dummy token while offline reaches the native module, which returns a failed result instead of crashing. The SDK's own screens need a real session, so they are not shown here.