Skip to content

Commit

Permalink
🐛 - Fix Android crash: Unable to instantiate fragment (#390)
Browse files Browse the repository at this point in the history
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 software-mansion/react-native-screens#17 (comment) 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`.
  • Loading branch information
guytepper authored Nov 14, 2024
1 parent 20cb079 commit b1a2876
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
4 changes: 2 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand Down
10 changes: 10 additions & 0 deletions android/app/src/main/java/com/betterrail/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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() {

Expand All @@ -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)
}
}
10 changes: 8 additions & 2 deletions ios/BetterRail.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -3108,7 +3108,7 @@ SPEC CHECKSUMS:
SocketRocket: abac6f5de4d4d62d24e11868d7a2f427e0ef940d
SPAlert: 735da1f16a887e294719217572ce1f936d8c8782
SPIndicator: 93e0a4fb23de51294ac48e874c0f081a5e293e4f
Yoga: 055f92ad73f8c8600a93f0e25ac0b2344c3b07e6
Yoga: aa3df615739504eebb91925fc9c58b4922ea9a08

PODFILE CHECKSUM: 44a26264f6cd33442848b186227025ac1a856570

Expand Down

0 comments on commit b1a2876

Please sign in to comment.