创建开发版本时,React-Native iOS 应用程序在启动后立即崩溃

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

我使用 React Native 创建了一个 iOS 应用程序。我已经通过 Expo App 在 iPhone 模拟器上运行了该应用程序。它甚至可以在创建要使用 TestFlight 进行分发的应用程序构建时发挥作用。现在,我想将 Google Ads 添加到应用程序中。不过,我了解到 Google Ads 无法通过 Expo 版本运行。相反,人们必须创建一个开发版本来测试应用程序中的广告并查看它们的外观。

我终于能够使用 eas(世博应用服务)编译成功的开发版本。然而,当我在模拟器上安装该应用程序并尝试打开它时,该应用程序几乎立即崩溃,我不知道为什么。我尝试破译符号化的崩溃报告,但我无法找出可能导致错误的原因。看起来它与用户界面有关。

下面是应用程序崩溃的线程:

Thread 0 Crashed::  Dispatch queue: com.apple.main-thread
0   libsystem_kernel.dylib                 0x11324a14a __pthread_kill + 10
1   libsystem_pthread.dylib                0x1132abebd pthread_kill + 262
2   libsystem_c.dylib                   0x7ff80016dd1c abort + 133
3   libc++abi.dylib                     0x7ff8002c6d12 abort_message + 241
4   libc++abi.dylib                     0x7ff8002b951a demangling_terminate_handler() + 266
5   libobjc.A.dylib                     0x7ff800061fba _objc_terminate() + 96
6   libc++abi.dylib                     0x7ff8002c616b std::__terminate(void (*)()) + 6
7   libc++abi.dylib                     0x7ff8002c6126 std::terminate() + 54
8   libdispatch.dylib                   0x7ff8001796ec _dispatch_client_callout + 28
9   libdispatch.dylib                   0x7ff80017d1e2 _dispatch_block_invoke_direct + 508
10  FrontBoardServices                  0x7ff807a8b3a7 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 30
11  FrontBoardServices                  0x7ff807a8b281 -[FBSMainRunLoopSerialQueue _targetQueue_performNextIfPossible] + 188
12  FrontBoardServices                  0x7ff807a8b3cf -[FBSMainRunLoopSerialQueue _performNextFromRunLoopSource] + 19
13  CoreFoundation                      0x7ff800429ff3 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
14  CoreFoundation                      0x7ff800429f35 __CFRunLoopDoSource0 + 157
15  CoreFoundation                      0x7ff800429732 __CFRunLoopDoSources0 + 215
16  CoreFoundation                      0x7ff800423e67 __CFRunLoopRun + 919
17  CoreFoundation                      0x7ff8004236ed CFRunLoopRunSpecific + 557
18  GraphicsServices                    0x7ff8103ba08f GSEventRunModal + 137
19  UIKitCore                           0x7ff805cdf6ee -[UIApplication _run] + 972
20  UIKitCore                           0x7ff805ce416e UIApplicationMain + 123
21  LeftOff                                0x10f870380 main + 96
22  dyld_sim                               0x112d3a3e0 start_sim + 10
23  dyld                                   0x113d57366 start + 1942

我已经尝试解决这个问题好几天了,确实需要一些帮助。我也尝试过更改应用程序中的依赖项版本,重点关注那些管理 UI 的依赖项。例如,我更改了react-native-ranimated、react-navigation/stack、react-native-gesture-handler 和react-native-screens 等软件包。到目前为止还没有任何效果。请帮忙。

为了了解更多上下文,我使用

eas build --profile development-simulator --platform ios --local

在终端中创建开发版本。这允许我创建一个 .tar.gz 文件,我可以解压缩该文件,然后安装在模拟器上。

这是我的 eas.json 文件:

{
  "cli": {
    "version": ">= 7.6.0"
  },
  "build": {
    "development": {
      "developmentClient": true,
      "distribution": "internal"
    },
    "preview": {
      "distribution": "internal"
    },
    "production": {
      "ios": {
        "image": "latest"
      }
    },
    "development-simulator": {
      "developmentClient": true,
      "distribution": "internal",
      "ios": {
        "simulator": true
      }
    }
  },
  "submit": {
    "production": {}
  }
}

这是我的 package.json 文件:

{
  "name": "mycoolapp",
  "version": "1.0.0",
  "scripts": {
    "start": "expo start --dev-client",
    "android": "expo run:android",
    "ios": "expo run:ios",
    "web": "expo start --web"
  },
  "dependencies": {
    "@babel/preset-env": "^7.24.5",
    "@babel/runtime": "^7.24.5",
    "@expo/config-plugins": "^8.0.4",
    "@expo/prebuild-config": "^7.0.4",
    "@react-native-community/masked-view": "^0.1.11",
    "@react-native-masked-view/masked-view": "^0.2.9",
    "@react-navigation/bottom-tabs": "^6.5.11",
    "@react-navigation/native": "^6.1.9",
    "@react-navigation/native-stack": "^6.9.17",
    "@react-navigation/stack": "^6.3.20",
    "apisauce": "^3.0.1",
    "core-js": "^3.35.1",
    "expo": "^51.0.8",
    "expo-build-properties": "~0.12.1",
    "expo-constants": "~16.0.2",
    "expo-dev-client": "~4.0.15",
    "expo-font": "~12.0.6",
    "expo-modules-core": "^1.12.12",
    "expo-secure-store": "~13.0.1",
    "expo-splash-screen": "^0.20.5",
    "expo-status-bar": "~1.12.1",
    "firebase": "^10.7.1",
    "formik": "^2.4.5",
    "hermes-engine": "^0.11.0",
    "jwt-decode": "^4.0.0",
    "postinstall": "^0.10.3",
    "react": "18.2.0",
    "react-inspector": "^6.0.2",
    "react-native": "^0.74.2",
    "react-native-device-info": "^10.12.0",
    "react-native-gesture-handler": "^2.16.2",
    "react-native-google-mobile-ads": "^13.3.0",
    "react-native-reanimated": "^3.12.0",
    "react-native-safe-area-context": "^4.10.4",
    "react-native-screens": "^3.31.1",
    "react-native-svg": "^15.3.0",
    "yup": "^1.3.3"
  },
  "devDependencies": {
    "@babel/core": "^7.24.0",
    "react-native-dotenv": "^3.4.11"
  },
  "private": true
}
ios react-native expo stack-trace react-native-google-mobile-ads
1个回答
0
投票

事实证明,我需要使用

npx 博览会预构建 --clean

清除与我之前创建的版本相关的信息。我还删除了所有以前的 zip 文件并从我的应用程序的根目录中构建。之后我就可以使用

eas build --profile dev-sim --platform ios --local

构建成功了!

这是我完整的苹果崩溃报告中的一个片段。显示更多上下文:

Last Exception Backtrace:
0   CoreFoundation  … __exceptionPreprocess + 226
1   libobjc.A.dylib … objc_exception_throw + 48
2   CoreFoundation  … -[NSException initWithCoder:] + 0
3   LlllOoo         … -[RCTAppDelegate bundleURL] + 52
4   LlllOoo         … -[EXAppDelegateWrapper createRCTRootViewFactory] + 65
5   LlllOoo         … -[RCTAppDelegate application:didFinishLaunchingWithOptions:] + 223
6   LlllOoo         … -[EXAppDelegateWrapper application:didFinishLaunchingWithOptions:] + 112
7   LlllOoo         … -[AppDelegate application:didFinishLaunchingWithOptions:] + 176
8   UIKitCore       … -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 297
…

我了解到 RCTAppDelegate(我相信它代表 React App Delegate)导致出现 NSException(或 NeXTSTEP 异常)。我想知道为什么 RCTAppDelegate 会引发异常。经过几个小时对 RN、Apple 崩溃报告等进行搜索和研究后,我心想:也许是bundleURL 错误或丢失,从而导致语法或语言异常。我认为 RCTAppDelegate 试图找到正确的bundleURL,但当它在根目录中发现多个bundleURL 时感到困惑。

对于 Google Ads,发生了另一个错误,直到测试我从头开始创建的新应用程序时我才意识到。除了有这个

"expo": {
...
},
 "react-native-google-mobile-ads":{
     "android_app_id": "ca-app-pub-456456...",
     "ios_app_id": "ca-app-pub-789789..."
 }
}

在我的 app.json 底部,我还需要上面 ios 键中的 Google 移动广告应用程序 ID,就像这样

"expo":{    
 ...
 "ios":{
   ...
   "config":{
    "googleMobileAdsAppId": "ca-app-pub-1231231213..."
   }
 },
 ...
 }
...
© www.soinside.com 2019 - 2024. All rights reserved.