如何使用EAS BUILD解决iOS应用程序在启动时崩溃问题

huangapple go评论75阅读模式
英文:

How to resolve IOS APP Crash on Launch using EAS BUILD

问题

背景

我一直在使用React-Native和expo托管工作流开发一个应用程序。在本地使用expo start进行开发时,应用程序一直运行良好。我在本地工作时,日志中没有看到任何错误信息。

问题

在运行和配置Eas Build后,我看到我的构建成功(所有项目都有对号)。但是当我在IOS模拟器上查看.ipa文件或将其通过“Transporter”发送到Apple账户以在TestFlight中使用时,应用程序在加载时崩溃。我只能看到启动画面然后就崩溃了。

崩溃日志(摘录)

我在我的IOS设备上检查了日志,并看到了以下崩溃原因。

线程1名称:  Dispatch队列:com.facebook.react.ExceptionsManagerQueue
线程1崩溃:
0   libsystem_kernel.dylib         0x1de9f7160 __pthread_kill + 8
1   libsystem_pthread.dylib        0x1ef1141ac pthread_kill + 268
2   libsystem_c.dylib              0x1a86fcc8c abort + 180
3   libc++abi.dylib                0x1ef053b8c abort_message + 132
4   libc++abi.dylib                0x1ef043a80 demangling_terminate_handler() + 336
5   libobjc.A.dylib                0x19a355d3c _objc_terminate() + 144
6   libc++abi.dylib                0x1ef052f28 std::__terminate(void (*)()) + 20
7   libc++abi.dylib                0x1ef052ec4 std::terminate() + 56
8   libdispatch.dylib              0x1a8698ff0 _dispatch_client_callout + 40
9   libdispatch.dylib              0x1a86a0694 _dispatch_lane_serial_drain + 672
10  libdispatch.dylib              0x1a86a11e0 _dispatch_lane_invoke + 384
11  libdispatch.dylib              0x1a86abe10 _dispatch_workloop_worker_thread + 652
12  libsystem_pthread.dylib        0x1ef10ddf8 _pthread_wqthread + 288
13  libsystem_pthread.dylib        0x1ef10db98 start_wqthread + 8

一些谷歌搜索暗示我的堆栈导航器依赖项未完全安装,这是正确的。我后来安装了它们,但得到了相同的结果。我认为这可能是我的app.json文件或我的依赖项不匹配的问题。

这是我的package.json:

Package.json

{
  "name": "应用名称",
  "version": "1.0.0",
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web"
  },
  "dependencies": {
    "@react-native-async-storage/async-storage": "1.17.11",
    "@react-navigation/bottom-tabs": "6.5.7",
    "@react-navigation/native": "6.1.6",
    "@react-navigation/native-stack": "6.9.12",
    "@stripe/stripe-react-native": "0.23.3",
    "expo": "48.0.9",
    "expo-firebase": "0.0.0-alpha.0",
    "expo-status-bar": "1.4.4",
    "firebase": "9.18.0",
    "formik": "2.2.9",
    "lottie-react-native": "5.1.4",
    "openai": "3.2.1",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "react-native": "0.71.8",
    "react-native-dotenv": "3.4.8",
    "react-native-element-dropdown": "2.9.0",
    "react-native-gesture-handler": "2.12.0",
    "react-native-vector-icons": "9.2.0",
    "react-native-web": "0.18.11",
    "yup": "1.0.2",
    "react-native-screens": "3.20.0",
    "react-native-safe-area-context": "4.5.0"
  },
  "private": true,
  "devDependencies": {
    "@babel/core": "7.21.3"
  }
}

这是我的app.json:

App.json

{
  "expo": {
    "name": "名称",
    "slug": "slug",
    "version": "1.0.1",
    "orientation": "portrait",
    "icon": "./assets/Icon.png",
    "userInterfaceStyle": "light",
    "splash": {
      "image": "./assets/splash.png",
      "resizeMode": "contain",
      "backgroundColor": "#ffffff"
    },
    "assetBundlePatterns": [
      "**/*"
    ],
    "ios": {
      "infoPlist": {
        "NSCameraUsageDescription": "This app supports use of camera for scanning",
        "UIAppFonts": [
          "LucidaGrande.ttf",
          "LucidaGrandeBold.ttf",
          "Luminari.ttf"
        ]
      },
      "config": {
        "usesNonExemptEncryption": false
      },
      "supportsTablet": true,
      "bundleIdentifier": "id",
      "buildNumber": "10"
    },
    "android": {
      "adaptiveIcon": {
        "foregroundImage": "./assets/adaptive-icon.png",
        "backgroundColor": "#ffffff"
      },
      "package": "id"
    },
    "web": {
      "favicon": "./assets/favicon.png"
    },
    "extra": {
      "eas": {
        "projectId": "uid"
      }
    },
    "owner": "owner"
  }
}

问题

有没有人从我的情况和配置文件中看到可能导致崩溃的原因?我的下一个尝试是在一个新的代码库中逐个安装每个依赖项,然后使用每个依赖项进行发布,以确定问题的包。但希望避免这样做,因为这将花费几天的时间。

英文:

Background

I have been working on an application using React-Native using expo managed workflow. The application has been working fine while developing locally using expo start. I don't see any errors in my logs when working locally.

Issue

Upon running and configuring Eas Build I see that my build are successful (check marks across the board). However when I either view the .IPA on my IOS simulator or send it up to Apple Account via "Transporter" for use in TestFlight; the application crashes on load. I only see the splash screen and then a crash.

Crash Logs (snippet)

I checked my logs on my IOS device and see the following reason for the crash.

Thread 1 name:   Dispatch queue: com.facebook.react.ExceptionsManagerQueue
Thread 1 Crashed:
0   libsystem_kernel.dylib        	       0x1de9f7160 __pthread_kill + 8
1   libsystem_pthread.dylib       	       0x1ef1141ac pthread_kill + 268
2   libsystem_c.dylib             	       0x1a86fcc8c abort + 180
3   libc++abi.dylib               	       0x1ef053b8c abort_message + 132
4   libc++abi.dylib               	       0x1ef043a80 demangling_terminate_handler() + 336
5   libobjc.A.dylib               	       0x19a355d3c _objc_terminate() + 144
6   libc++abi.dylib               	       0x1ef052f28 std::__terminate(void (*)()) + 20
7   libc++abi.dylib               	       0x1ef052ec4 std::terminate() + 56
8   libdispatch.dylib             	       0x1a8698ff0 _dispatch_client_callout + 40
9   libdispatch.dylib             	       0x1a86a0694 _dispatch_lane_serial_drain + 672
10  libdispatch.dylib             	       0x1a86a11e0 _dispatch_lane_invoke + 384
11  libdispatch.dylib             	       0x1a86abe10 _dispatch_workloop_worker_thread + 652
12  libsystem_pthread.dylib       	       0x1ef10ddf8 _pthread_wqthread + 288
13  libsystem_pthread.dylib       	       0x1ef10db98 start_wqthread + 8

Some google searches alluded to the fact that my stack navigator dependencies were not all installed and this was truthful. I have since installed them but get the same result. I assume this is either an issue with my app.json or my mis-match of my dependencies.

Here is my package.json:

Package.json

{
  "name": "app name",
  "version": "1.0.0",
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web"
  },
  "dependencies": {
    "@react-native-async-storage/async-storage": "1.17.11",
    "@react-navigation/bottom-tabs": "6.5.7",
    "@react-navigation/native": "6.1.6",
    "@react-navigation/native-stack": "6.9.12",
    "@stripe/stripe-react-native": "0.23.3",
    "expo": "48.0.9",
    "expo-firebase": "0.0.0-alpha.0",
    "expo-status-bar": "1.4.4",
    "firebase": "9.18.0",
    "formik": "2.2.9",
    "lottie-react-native": "5.1.4",
    "openai": "3.2.1",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "react-native": "0.71.8",
    "react-native-dotenv": "3.4.8",
    "react-native-element-dropdown": "2.9.0",
    "react-native-gesture-handler": "2.12.0",
    "react-native-vector-icons": "9.2.0",
    "react-native-web": "0.18.11",
    "yup": "1.0.2",
    "react-native-screens": "3.20.0",
    "react-native-safe-area-context": "4.5.0"
  },
  "private": true,
  "devDependencies": {
    "@babel/core": "7.21.3"
  }
}

Here is my app.json:

App.json

{
  "expo": {
    "name": "name",
    "slug": "slug",
    "version": "1.0.1",
    "orientation": "portrait",
    "icon": "./assets/Icon.png",
    "userInterfaceStyle": "light",
    "splash": {
      "image": "./assets/splash.png",
      "resizeMode": "contain",
      "backgroundColor": "#ffffff"
    },
    "assetBundlePatterns": [
      "**/*"
    ],
    "ios": {
      "infoPlist": {
        "NSCameraUsageDescription": "This app supports use of camera for scanning",
        "UIAppFonts": [
          "LucidaGrande.ttf",
          "LucidaGrandeBold.ttf",
          "Luminari.ttf"
        ]
      },
      "config": {
        "usesNonExemptEncryption": false
      },
      "supportsTablet": true,
      "bundleIdentifier": "id",
      "buildNumber": "10"
    },
    "android": {
      "adaptiveIcon": {
        "foregroundImage": "./assets/adaptive-icon.png",
        "backgroundColor": "#ffffff"
      },
      "package": "id"
    },
    "web": {
      "favicon": "./assets/favicon.png"
    },
    "extra": {
      "eas": {
        "projectId": "uid"
      }
    },
    "owner": "owner"
  }
}

Question

Does anyone see from my scenario and or configuration files what may be causing the crash? My next approach is to systematically install each dependency into a new codebase and publish with each one to identify the problem package. Would like to avoid this as it will take days.

答案1

得分: 1

看起来,我的上述问题是由于多个问题引起的,所以我将概述每个问题,以防将来有其他人遇到此问题。

问题 1

在使用 @react-navigation/native 时,您将需要多个包。在阅读文档时,我忽略了这一点。您需要确保安装以下包:

npx expo install react-native-screens react-native-safe-area-context @react-native-community/masked-view react-native-gesture-handler react-native-safe-area-context react-native-reanimated

我怀疑您不需要所有这些包,但由于每个构建都需要超过 20 分钟,我没有时间测试它们。

确保根据文档在使用导航时导入手势。

问题 2

我的环境变量没有设置正确。我使用了库 @react-native-dotenv,然后按照文档导入了每个环境变量。然而,Expo 希望您通过 process.env 访问环境变量,这可以通过多种方式填充。FYI;只要按照 react-native-dotenv 的文档导入环境变量,您仍然可以通过 process.env 访问它们,这将使您的代码在本地和构建时都能正常工作。

问题 3

Expo-Font 包未安装,但出于某种原因此功能仍在工作。请确保安装此依赖项,因为在发布时它将无法正常工作。

问题 4

一些依赖项不受 Expo 支持,仅在构建时成为问题。确保运行 npm expo install --check。然后,它将允许您安装正确的依赖项。

总结

您可能会遇到此错误,但没有出现上述任何问题。这一切都取决于您的本地环境与构建环境之间的差异,或者依赖项不匹配。确保依赖项都存在并正确使用,即使在本地构建上也能正常工作。

为了发现所有这些问题,我从一个新的 Expo 项目开始,然后逐渐添加了每个功能。我希望您不必这样做,但如果遇到困难,这是对我有效的方法。

英文:

It appears my issue above was due to multiple issues so I will outline each one just encase someone else runs into this issue in the future.

Issue 1

When using @react-navigation/native you will need multiple packages. I missed this when reading the documentation. You will want to ensure you install:

npx expo install react-native-screens react-native-safe-area-context @react-native-community/masked-view react-native-gesture-handler react-native-safe-area-context react-native-reanimated
> I doubt you need all these packages but I ran out of time testing them all since each build took over 20 minutes.

Make sure you import your gestures where you use your navigation as per the documentation

Issue 2

I did not have my environment variables setup right. I used the library @react-native-dotenv and then imported each one as per the documentation . However, expo wants you to access environment variables through process.env which can be populated multiple ways. FYI; as long as you import your environment variables as per the documentations for react-native-dotenv, you can still access them through process.env which will allow your code to works both locally and when built.

Issue 3

Expo-Font package was not installed however this feature still worked for some reason. Make sure you install this dependency as it won't work when published.

Issue 4

Some dependencies were note supported by expo and only became an issue when building. Make sure you run npm expo install --check. It will then allow you to install the correct dependencies.

Summary

You may get this error but no have any of the issues listed above. This all comes down to your local behaving different than your build environment and or mis-matched dependencies. Make sure you dependencies are all there and used correctly even if it does work on your local builds.

To find all these issues I started with a fresh expo project and slowly added in each feature. I hope you don't have to but if your stuck, this is what worked for me.

huangapple
  • 本文由 发表于 2023年6月19日 05:03:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/76502514.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定