From b1a28769dc7f50936caa287c6b1f606d9d658321 Mon Sep 17 00:00:00 2001 From: Guy Tepper Date: Thu, 14 Nov 2024 11:35:59 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20-=20Fix=20Android=20crash:=20Una?= =?UTF-8?q?ble=20to=20instantiate=20fragment=20(#390)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Crashlytics started to report the following crash on Android devices: ``` Unable to instantiate fragment com.swmansion.rnscreens.ScreenStackFragment: calling Fragment constructor caused an exception ``` A thrown error has suggested this fix: ``` Screen fragments should never be restored. Follow instructions from https://github.com/software-mansion/react-native-screens/issues/17#issuecomment-424704067 to properly configure your main activity. ``` We had the `MainActivity.java` configured properly, but when migrating to Kotlin on the latest version (2.3.3), we forgot to add it to `MainActivity.kt`. --- android/app/build.gradle | 4 ++-- .../src/main/java/com/betterrail/MainActivity.kt | 10 ++++++++++ ios/BetterRail.xcodeproj/project.pbxproj | 10 ++++++++-- ios/Podfile.lock | 14 +++++++------- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index 6c3b1756b..94b5c1707 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -105,8 +105,8 @@ android { applicationId "com.betterrail" minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion - versionCode 90 - versionName "2.3.3" + versionCode 92 + versionName "2.3.4" missingDimensionStrategy "store", "play" } diff --git a/android/app/src/main/java/com/betterrail/MainActivity.kt b/android/app/src/main/java/com/betterrail/MainActivity.kt index 4a1506d4a..64e56e006 100644 --- a/android/app/src/main/java/com/betterrail/MainActivity.kt +++ b/android/app/src/main/java/com/betterrail/MainActivity.kt @@ -4,6 +4,7 @@ import com.facebook.react.ReactActivity import com.facebook.react.ReactActivityDelegate import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.fabricEnabled import com.facebook.react.defaults.DefaultReactActivityDelegate +import android.os.Bundle; class MainActivity : ReactActivity() { @@ -19,4 +20,13 @@ class MainActivity : ReactActivity() { */ override fun createReactActivityDelegate(): ReactActivityDelegate = DefaultReactActivityDelegate(this, mainComponentName, fabricEnabled) + + /** + * React Native Screens setup: + * https://reactnavigation.org/docs/getting-started/#installing-dependencies-into-a-bare-react-native-project + * Required to avoid crashes related to View state being not persisted consistently across Activity restarts. + */ + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(null) + } } diff --git a/ios/BetterRail.xcodeproj/project.pbxproj b/ios/BetterRail.xcodeproj/project.pbxproj index aa333c5d9..2bcb2164a 100644 --- a/ios/BetterRail.xcodeproj/project.pbxproj +++ b/ios/BetterRail.xcodeproj/project.pbxproj @@ -1438,7 +1438,10 @@ ); MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; - OTHER_LDFLAGS = "$(inherited) "; + OTHER_LDFLAGS = ( + "$(inherited)", + " ", + ); REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native"; SDKROOT = iphoneos; SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited) DEBUG"; @@ -1504,7 +1507,10 @@ "\"$(inherited)\"", ); MTL_ENABLE_DEBUG_INFO = NO; - OTHER_LDFLAGS = "$(inherited) "; + OTHER_LDFLAGS = ( + "$(inherited)", + " ", + ); REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native"; SDKROOT = iphoneos; USE_HERMES = true; diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 3438d0a7e..61b29912d 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -829,10 +829,10 @@ PODS: - Libuv-gRPC (= 0.0.10) - gRPC-Core/Interface (1.44.0) - GTMSessionFetcher/Core (3.5.0) - - hermes-engine (0.75.2): - - hermes-engine/Pre-built (= 0.75.2) - - hermes-engine/Pre-built (0.75.2) - - leveldb-library (1.22.5) + - hermes-engine (0.75.4): + - hermes-engine/Pre-built (= 0.75.4) + - hermes-engine/Pre-built (0.75.4) + - leveldb-library (1.22.6) - Libuv-gRPC (0.0.10): - Libuv-gRPC/Implementation (= 0.0.10) - Libuv-gRPC/Interface (= 0.0.10) @@ -3009,8 +3009,8 @@ SPEC CHECKSUMS: "gRPC-C++": 9675f953ace2b3de7c506039d77be1f2e77a8db2 gRPC-Core: 943e491cb0d45598b0b0eb9e910c88080369290b GTMSessionFetcher: 5aea5ba6bd522a239e236100971f10cb71b96ab6 - hermes-engine: 3b6e0717ca847e2fc90a201e59db36caf04dee88 - leveldb-library: e8eadf9008a61f9e1dde3978c086d2b6d9b9dc28 + hermes-engine: ea92f60f37dba025e293cbe4b4a548fd26b610a0 + leveldb-library: cc8b8f8e013647a295ad3f8cd2ddf49a6f19be19 Libuv-gRPC: 55e51798e14ef436ad9bc45d12d43b77b49df378 nanopb: d4d75c12cd1316f4a64e3c6963f879ecd4b5e0d5 PromisesObjC: f5707f49cb48b9636751c5b2e7d227e43fba9f47 @@ -3108,7 +3108,7 @@ SPEC CHECKSUMS: SocketRocket: abac6f5de4d4d62d24e11868d7a2f427e0ef940d SPAlert: 735da1f16a887e294719217572ce1f936d8c8782 SPIndicator: 93e0a4fb23de51294ac48e874c0f081a5e293e4f - Yoga: 055f92ad73f8c8600a93f0e25ac0b2344c3b07e6 + Yoga: aa3df615739504eebb91925fc9c58b4922ea9a08 PODFILE CHECKSUM: 44a26264f6cd33442848b186227025ac1a856570