Repository navigation
Fix the launch crash on Android under NativePHP v4 - #6
Open
Ikromjon1998 wants to merge 1 commit into
Open
Ikromjon1998 wants to merge 1 commit into
Ikromjon1998 wants to merge 1 commit into
Conversation
NativePHP v4 creates bridge functions on a background thread after the activity has resumed. The Scan function registered its result launcher with registerForActivityResult() in its constructor, which Android only allows before the activity is STARTED, so every v4 Android app with this plugin died at launch with an IllegalStateException. v3 creates bridge functions in onCreate and was not affected. Register with the activity's result registry directly, which is valid at any point in the lifecycle, and re-register when the activity instance changes. Reproduced and verified on an Android 16 emulator: the app crashed at launch on nativephp/mobile 4.6.0 before, and now launches on 4.6.0 and 3.3.9 and opens the scanner.
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.
What
Fixes a crash at app launch on Android under NativePHP for Mobile v4. It affects 1.5.0-beta.1, the first version that can be installed on v4.
Why
NativePHP v3 calls
registerBridgeFunctions()inMainActivity.onCreate. v4 moved it intoinitializeEnvironmentAsync, on a background thread after the activity has resumed. TheScanbridge function registered its result launcher withregisterForActivityResult()in its constructor, and Android only allows that call before the activity is started.The launcher is now registered with the activity's
ActivityResultRegistrydirectly, which is valid at any point in the lifecycle. It is also re-registered when the activity instance changes.Verified
On an Android 16 (API 36) emulator, in a Laravel 13 app with this plugin:
nativephp/mobile4.6.0The emulator image cannot download the ML Kit scanner module, so the scan itself stops at Google's download screen. A complete scan still needs a physical device.
composer check(133 tests, Pint, Rector, PHPStan) and ktlint pass.Release
The changelog entry is
1.5.0-beta.2, replacing beta.1.