Pure React Native 应用程序在以发布模式打开后在滑动时崩溃

Har*_*rky 7 android react-native react-native-android react-native-navigation

我正在为我的纯RN 0.61.2应用程序使用React-Navigation。当我在调试模式下使用它时,该应用程序运行完美。但是,在发布模式下,当我尝试打开抽屉导航菜单或在选项卡菜单中向下滚动时,应用程序会立即崩溃。

依赖项:

...
  "dependencies": {
    "@react-native-community/async-storage": "^1.6.2",
    "@react-native-community/netinfo": "^4.4.0",
    "@react-native-community/slider": "^2.0.2",
    "react": "16.9.0",
    "react-native": "0.61.2",
    "react-native-admob": "^2.0.0-beta.6",
    "react-native-gesture-handler": "^1.4.1",
    "react-native-reanimated": "^1.3.0",
    "react-native-screens": "1.0.0-alpha.23",
    "react-native-vector-icons": "^6.6.0",
    "react-navigation": "^4.0.10",
    "react-navigation-drawer": "^2.2.2",
    "react-navigation-stack": "^1.9.3",
    "react-navigation-tabs": "^2.5.5"
  },
...
Run Code Online (Sandbox Code Playgroud)

我已经将这些代码行添加到android/app/build.gradle的依赖项中:

    implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
    implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-alpha02'
Run Code Online (Sandbox Code Playgroud)

在 App.js 中,我试过

import {enableScreens} from 'react-native-screen';
enableScreens();
Run Code Online (Sandbox Code Playgroud)

并且

import {useScreens} from 'react-native-screen';
useScreens();
Run Code Online (Sandbox Code Playgroud)

2.0.0-alpha.12.0.0-alpha.31.0.0-alpha.23版本react-native-screens

然而,我仍然得到相同的结果:调试模式完美运行,释放模式在抽屉导航滑动或标签导航滚动后急剧崩溃。


我使用adb logcat并看到的解决方案

ReactNativeJS: Invariant Violation: Unsupported top level event type "onGestureHandlerStateChange" dispatched
Run Code Online (Sandbox Code Playgroud)

我用谷歌搜索,发现有些人通过在“app.js”文件顶部导入“react-native-gesture-handler”来修复它。所以我补充说:

import 'react-native-gesture-handler'
Run Code Online (Sandbox Code Playgroud)

它现在工作得很好!