React Native Expo - 在生产 iOS 上崩溃,但在 ExpoGo 和独立版上运行良好

问题描述 投票:0回答:1

我的应用程序的最新更新在点击根路由器(反应导航)时崩溃。

即使使用 XCode 和 adb logcat,我也无法找出确切的问题。当我在 ExpoGO 上运行该应用程序时,它运行良好。对于独立的 .apk 和 iOS 模拟器也是如此。

会不会是内存泄漏?还是与振幅分析有关?

在生产环境中运行应用程序时会崩溃:

  • 我登录,它会将我重定向到登录的主屏幕
  • 我已经登录并导航到其中一家餐厅屏幕

一些背景:

Using Expo Managed workflow
eas-cli version: 3.17.01

我的调试日志:

Incident Identifier: A45A65B2-31AC-47B8-BB57-EF813A977C9F
    Beta Identifier:     A66861AD-7877-459B-AB86-E5BABE9AE0B9
    Hardware Model:      iPhone14,4
    Process:             Foodhi [17532]
    Path:                /private/var/containers/Bundle/Application/6B6E18A9-    ED4A-4D55-8D1F-DC676144DAE5/Foodhi.app/Foodhi
    Identifier:          com.foodhi.foodhiapp
    Version:             1.0.5 (1.0.61)
    AppStoreTools:       14E221
    AppVariant:          1:iPhone14,4:16
    Beta:                YES
    Code Type:           ARM-64 (Native)
    Role:                Foreground
    Parent Process:      launchd [1]
    Coalition:           com.foodhi.foodhiapp [3681]

    Date/Time:           2023-08-02 20:28:54.4107 +0200
    Launch Time:         2023-08-02 18:34:28.3462 +0200
    OS Version:          iPhone OS 16.3.1 (20D67)
    Release Type:        User
    Baseband Version:    2.40.01
    Report Version:      104

    Exception Type:  EXC_CRASH (SIGABRT)
    Exception Codes: 0x0000000000000000, 0x0000000000000000
    Triggered by Thread:  9

    Application Specific Information:
    abort() called

    ...
    ...

    Thread 9 name:   Dispatch queue: com.facebook.react.AmplitudeReactNativeQueue
    Thread 9 Crashed:
    0   libsystem_kernel.dylib                 0x1d5c13674 __pthread_kill + 8
    1   libsystem_pthread.dylib                0x1e63771ac pthread_kill + 268
    2   libsystem_c.dylib                      0x19f774c8c abort + 180
    3   libc++abi.dylib                        0x1e62b6b8c abort_message + 132
    4   libc++abi.dylib                        0x1e62a6a80 demangling_terminate_handler()     + 336
    5   libobjc.A.dylib                        0x191295d3c _objc_terminate() + 144
    6   Foodhi                                 0x10462af64 0x1043ac000 + 2617188
    7   libc++abi.dylib                        0x1e62b5f28 std::__terminate(void (*)()) +     20
    8   libc++abi.dylib                        0x1e62b5ec4 std::terminate() + 56
    9   libdispatch.dylib                      0x19f710f9c _dispatch_client_callout + 40
    10  libdispatch.dylib                      0x19f718640 _dispatch_lane_serial_drain + 672
    11  libdispatch.dylib                      0x19f71918c _dispatch_lane_invoke + 384
    12  libdispatch.dylib                      0x19f723e10 _dispatch_workloop_worker_thread + 652
    13  libsystem_pthread.dylib                0x1e6370df8 _pthread_wqthread + 288
    14  libsystem_pthread.dylib                0x1e6370b98 start_wqthread + 8

package.json

{
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web",
    "eject": "expo eject",
    "postinstall": "patch-package"
  },
  "dependencies": {
    "@amplitude/analytics-react-native": "^1.3.2",
    "@expo-google-fonts/quicksand": "^0.2.0",
    "@expo-google-fonts/rubik": "^0.2.0",
    "@expo/html-elements": "^0.3.1",
    "@expo/ngrok": "^4.1.0",
    "@react-native-async-storage/async-storage": "~1.17.3",
    "@react-native-community/datetimepicker": "6.5.2",
    "@react-native-picker/picker": "2.4.8",
    "@react-navigation/drawer": "^6.1.4",
    "@react-navigation/native": "^6.0.2",
    "@react-navigation/stack": "^6.0.7",
    "@sentry/react-native": "4.9.0",
    "axios": "^0.21.1",
    "babel-plugin-inline-dotenv": "^1.6.0",
    "base-64": "^1.0.0",
    "dayjs": "^1.11.7",
    "deprecated-react-native-prop-types": "^2.3.0",
    "expo": "^47.0.0",
    "expo-application": "~5.0.1",
    "expo-camera": "~13.1.0",
    "expo-constants": "~14.0.2",
    "expo-dev-client": "~2.0.1",
    "expo-device": "~5.0.0",
    "expo-font": "~11.0.1",
    "expo-image-picker": "~14.0.2",
    "expo-linking": "~3.3.1",
    "expo-location": "~15.0.1",
    "expo-notifications": "~0.17.0",
    "expo-splash-screen": "~0.17.5",
    "expo-status-bar": "~1.4.2",
    "expo-updates": "~0.15.6",
    "formik": "^2.2.9",
    "html-entities": "^2.3.3",
    "jwt-decode": "^3.1.2",
    "moment": "^2.29.4",
    "patch-package": "^6.5.1",
    "postinstall-postinstall": "^2.1.0",
    "react": "18.1.0",
    "react-native": "0.70.8",
    "react-native-bouncy-checkbox": "^3.0.4",
    "react-native-collapsible": "^1.6.0",
    "react-native-dotenv": "^3.2.0",
    "react-native-elements": "^3.4.3",
    "react-native-form-validator": "^0.4.0",
    "react-native-geocoding": "^0.5.0",
    "react-native-gesture-handler": "~2.8.0",
    "react-native-google-places-autocomplete": "^2.4.1",
    "react-native-maps": "1.3.2",
    "react-native-phone-number-input": "^2.1.0",
    "react-native-picker-select": "^8.0.4",
    "react-native-popover-view": "^5.1.7",
    "react-native-reanimated": "~2.12.0",
    "react-native-safe-area-context": "4.4.1",
    "react-native-safe-area-view": "^1.1.1",
    "react-native-screens": "~3.18.0",
    "react-native-snap-carousel": "^3.9.1",
    "react-native-super-grid": "^4.1.3",
    "react-native-vector-icons": "^9.2.0",
    "react-native-woocommerce-api": "^1.8.8",
    "react-redux": "^7.2.4",
    "redux": "^4.1.1",
    "redux-devtools-extension": "^2.13.9",
    "redux-persist": "^6.0.0",
    "redux-thunk": "^2.3.0",
    "sentry-expo": "~6.0.0",
    "yup": "^0.32.11"
  },
  "devDependencies": {
    "@babel/core": "^7.19.3"
  },
  "private": true
}

eas.json

{
  "build": {
    "development": {
      "developmentClient": true,
      "distribution": "internal",
      "channel": "development",
      "ios": {
        "resourceClass": "m-medium"
      }
    },
    "preview": {
      "ios": {
        "simulator": true,
        "image": "latest",
        "resourceClass": "m-medium"
      },
      "distribution": "internal",
      "channel": "preview"
    },
    "production": {
      "channel": "production",
      "ios": {
        "resourceClass": "m-medium"
      }
    }
  },
  "cli": {
    "version": ">= 0.52.0"
  }
}


Where Amplitude is being initialised (once the user profile is loaded):

const RootRouter = () => {

    const initStackNavigator = createStackNavigator();

    const dispatch = useDispatch();
    const userLoggedIn = useSelector((state) => state.auth.loggedIn);
    const restaurantProfileId = useSelector((state) => state.restaurantProfile.id);
    const loaded = useSelector(state => state.restaurantProfile.profileLoaded);

    useEffect(() => {
        if (loaded) {
            // GET PROFILE DETAILS
            dispatch(readProfileDetails())
            // PROCESS PUSH NOTIFICATION TOKEN
            pushNotificationsSetUp(userLoggedIn, restaurantProfileId)

            dispatch(setScreenName(navigationRef.current.getCurrentRoute().name)) 
        }
    }, [loaded])

    // INITIALIZE AMPLITUDE ANALYTICS ONCE THE USER ID IS RETREIVED
    useEffect(() => {
        if (restaurantProfileId) {
            init(process.env.AMPLITUDE_API, restaurantProfileId, {
                serverZone: 'EU',
            });
        }
    }, [loaded])

任何帮助将不胜感激!

react-native expo crash eas amplitude-analytics
1个回答
0
投票

最后我发现了问题:我在 useEffect 中触发了 Amplitude.init,因为我之前没有包含必要的条件,所以多次触发。显然,同时多次初始化 Amplitude 会在生产中崩溃。

© www.soinside.com 2019 - 2024. All rights reserved.