Expo React Native 应用程序在 Android 上崩溃

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

自从我开始使用 Expo 使用 React Native 进行编程以来,我一直在使用 iOS 物理设备和 Expo 应用程序。我从来没有遇到过任何重大问题。

现在我想开始修复 Android 上的任何错误,但是当在我的 Android 物理设备上运行 Expo 应用程序时,Expo 应用程序在下载捆绑包时崩溃(关闭)。它不会在我的控制台中打印任何错误,所以我什至不知道从哪里开始......

这是我的app.json:

{
  "expo": {
    "name": "PointoUserApp",
    "slug": "PointoUserApp",
    "version": "1.0.0",
    "platforms": [
      "ios",
      "android",
      "web"
    ],
    "orientation": "portrait",
    "icon": "./assets/Images/icon.png",
    "splash": {
      "image": "./assets/Images/splash.png",
      "resizeMode":"contain",
      "backgroundColor": "#ffffff"
    },
    "updates": {
      "fallbackToCacheTimeout": 0
    },
    "assetBundlePatterns": [
      "**/*"
    ],
    "ios": {
      "bundleIdentifier": "com.meretc23.PointoUserApp"
    },
    "android":{
      
    },
    "web": {
      "favicon": "./assets/Images/favicon.png"
    }
  }
}

注意它在android下是空的,因为我不知道需要什么。

下面也是我的 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"
  },
  "dependencies": {
    "@expo-google-fonts/inter": "^0.1.0",
    "@fortawesome/fontawesome-svg-core": "^1.2.30",
    "@fortawesome/free-brands-svg-icons": "^5.14.0",
    "@fortawesome/free-solid-svg-icons": "^5.14.0",
    "@fortawesome/react-native-fontawesome": "^0.2.5",
    "@ionic/react": "^5.3.1",
    "@react-native-community/art": "^1.2.0",
    "@react-native-community/async-storage": "~1.11.0",
    "@react-native-community/datetimepicker": "2.4.0",
    "@react-native-community/masked-view": "0.1.10",
    "@react-navigation/bottom-tabs": "^5.7.3",
    "@react-navigation/material-top-tabs": "^5.2.16",
    "@react-navigation/native": "^5.7.2",
    "@react-navigation/stack": "^5.8.0",
    "@types/react-native-snap-carousel": "^3.8.2",
    "core-js": "^3.6.5",
    "expo": "^38.0.0",
    "expo-constants": "~9.1.1",
    "expo-font": "~8.2.1",
    "expo-linking": "^1.0.3",
    "expo-localization": "~8.2.1",
    "expo-location": "~8.2.1",
    "expo-permissions": "~9.0.1",
    "expo-status-bar": "^1.0.0",
    "firebase": "^7.21.1",
    "geolib": "^3.3.1",
    "i18n-js": "^3.7.1",
    "react": "16.11.0",
    "react-dom": "16.11.0",
    "react-native": "https://github.com/expo/react-native/archive/sdk-38.0.2.tar.gz",
    "react-native-check-box": "^2.1.7",
    "react-native-gesture-handler": "~1.6.0",
    "react-native-localize": "^1.4.1",
    "react-native-map-clustering": "^3.3.9",
    "react-native-map-link": "^2.7.17",
    "react-native-maps": "0.27.1",
    "react-native-modal": "^11.5.6",
    "react-native-picker-select": "^8.0.0",
    "react-native-progress": "^4.1.2",
    "react-native-progress-circle": "^2.1.0",
    "react-native-qrcode-svg": "^6.0.6",
    "react-native-reanimated": "~1.9.0",
    "react-native-restart": "0.0.17",
    "react-native-safe-area-context": "^3.0.7",
    "react-native-screens": "~2.9.0",
    "react-native-snap-carousel": "^4.0.0-beta.5",
    "react-native-svg": "12.1.0",
    "react-native-tab-view": "^2.15.1",
    "react-native-web": "~0.11.7",
    "react-navigation": "^4.4.0",
    "react-navigation-stack": "^2.8.2",
    "react-redux": "^7.2.1",
    "redux": "^4.0.5",
    "redux-thunk": "^2.3.0",
    "yargs-parser": "^18.1.3"
  },
  "devDependencies": {
    "@babel/core": "^7.8.6",
    "babel-preset-expo": "^8.2.3"
  },
  "private": true
}

经验教训:如果您想在 ios 和 android 上运行应用程序,请始终同时监控这两个应用程序,以免您的应用程序太大而无法知道问题出在哪里......

感谢帮助

android node.js reactjs react-native expo
7个回答
6
投票

我现在也遇到了同样的问题。在我的情况下,我已将其范围缩小到 android adjustmentIcon 配置。如果我使用真实 png 的路径,应用程序会在捆绑包下载时崩溃。如果我不在android下包含adaptiveIcon,应用程序就会崩溃。它不会崩溃的唯一方法是包含链接到甚至不存在的文件的adaptiveIcon。这会记录一个错误,指出 Expo 找不到该文件,但应用程序实际上会加载。极其奇怪。尝试将其添加到您的 app.json 文件中。

"android": {
  "adaptiveIcon": {
    "foregroundImage": "./assets/anImageThatDoesNotExist.png",
    "backgroundColor": "#FFFFFF"
   }
 },

3
投票

我也遇到这个问题了。试图在互联网上寻找解决方案,但似乎没有一个答案。所以我做了什么,我安装了 android 模拟器(我没有 android 设备)。我在模拟器上安装了该应用程序。 我运行

adb logcat -v threadtime
然后发现这个错误

12-07 22:28:43.724  5441  5441 E AndroidRuntime: FATAL EXCEPTION: main
12-07 22:28:43.724  5441  5441 E AndroidRuntime: Process: com.danggrianto.eggies, PID: 5441
12-07 22:28:43.724  5441  5441 E AndroidRuntime: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference
12-07 22:28:43.724  5441  5441 E AndroidRuntime:    at com.horcrux.svg.SvgView.setTintColor(SvgView.java:189)
12-07 22:28:43.724  5441  5441 E AndroidRuntime:    at com.horcrux.svg.SvgViewManager.setTintColor(SvgViewManager.java:98)
12-07 22:28:43.724  5441  5441 E AndroidRuntime:    at com.horcrux.svg.SvgViewManager.setTintColor(SvgViewManager.java:32)
12-07 22:28:43.724  5441  5441 E AndroidRuntime:    at com.facebook.react.viewmanagers.RNSVGSvgViewManagerDelegate.setProperty(RNSVGSvgViewManagerDelegate.java:62)
12-07 22:28:43.724  5441  5441 E AndroidRuntime:    at com.facebook.react.uimanager.ViewManagerPropertyUpdater.updateProps(ViewManagerPropertyUpdater.java:46)
12-07 22:28:43.724  5441  5441 E AndroidRuntime:    at com.facebook.react.uimanager.ViewManager.updateProperties(ViewManager.java:84)
12-07 22:28:43.724  5441  5441 E AndroidRuntime:    at com.facebook.react.uimanager.ViewManager.createViewInstance(ViewManager.java:188)
12-07 22:28:43.724  5441  5441 E AndroidRuntime:    at com.facebook.react.uimanager.ViewManager.createView(ViewManager.java:115)
12-07 22:28:43.724  5441  5441 E AndroidRuntime:    at com.facebook.react.uimanager.NativeViewHierarchyManager.createView(NativeViewHierarchyManager.java:281)
12-07 22:28:43.724  5441  5441 E AndroidRuntime:    at com.facebook.react.uimanager.UIViewOperationQueue$CreateViewOperation.execute(UIViewOperationQueue.java:194)
12-07 22:28:43.724  5441  5441 E AndroidRuntime:    at com.facebook.react.uimanager.UIViewOperationQueue$1.run(UIViewOperationQueue.java:909)
12-07 22:28:43.724  5441  5441 E AndroidRuntime:    at com.facebook.react.uimanager.UIViewOperationQueue.flushPendingBatches(UIViewOperationQueue.java:1026)
12-07 22:28:43.724  5441  5441 E AndroidRuntime:    at com.facebook.react.uimanager.UIViewOperationQueue.access$2600(UIViewOperationQueue.java:47)
12-07 22:28:43.724  5441  5441 E AndroidRuntime:    at com.facebook.react.uimanager.UIViewOperationQueue$DispatchUIFrameCallback.doFrameGuarded(UIViewOperationQueue.java:1086)
12-07 22:28:43.724  5441  5441 E AndroidRuntime:    at com.facebook.react.uimanager.GuardedFrameCallback.doFrame(GuardedFrameCallback.java:29)
12-07 22:28:43.724  5441  5441 E AndroidRuntime:    at com.facebook.react.modules.core.ReactChoreographer$ReactChoreographerDispatcher.doFrame(ReactChoreographer.java:175)
12-07 22:28:43.724  5441  5441 E AndroidRuntime:    at com.facebook.react.modules.core.ChoreographerCompat$FrameCallback$1.doFrame(ChoreographerCompat.java:85)
12-07 22:28:43.724  5441  5441 E AndroidRuntime:    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1229)
12-07 22:28:43.724  5441  5441 E AndroidRuntime:    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1239)
12-07 22:28:43.724  5441  5441 E AndroidRuntime:    at android.view.Choreographer.doCallbacks(Choreographer.java:899)
12-07 22:28:43.724  5441  5441 E AndroidRuntime:    at android.view.Choreographer.doFrame(Choreographer.java:827)
12-07 22:28:43.724  5441  5441 E AndroidRuntime:    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1214)
12-07 22:28:43.724  5441  5441 E AndroidRuntime:    at android.os.Handler.handleCallback(Handler.java:942)
12-07 22:28:43.724  5441  5441 E AndroidRuntime:    at android.os.Handler.dispatchMessage(Handler.java:99)
12-07 22:28:43.724  5441  5441 E AndroidRuntime:    at android.os.Looper.loopOnce(Looper.java:201)
12-07 22:28:43.724  5441  5441 E AndroidRuntime:    at android.os.Looper.loop(Looper.java:288)
12-07 22:28:43.724  5441  5441 E AndroidRuntime:    at android.app.ActivityThread.main(ActivityThread.java:7898)
12-07 22:28:43.724  5441  5441 E AndroidRuntime:    at java.lang.reflect.Method.invoke(Native Method)
12-07 22:28:43.724  5441  5441 E AndroidRuntime:    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
12-07 22:28:43.724  5441  5441 E AndroidRuntime:    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)

原来问题出在

com.horcrux.svg.SvgView.setTintColor(SvgView.java:189)

我检查了代码,然后将

react-native-svg
升级到最新版本,这解决了我的问题。


1
投票

我的上一个博览会项目甚至没有android属性,而我的ios属性只有supportsTablet为true。尝试完全删除 android 属性


1
投票

我刚刚学会了非常艰难的方法!我发现 android 对反应本机样式表差异的容忍度较低。如果您的 Expo Go 应用程序在 Android 上崩溃,但在 ios 上运行良好,请检查在哪个导航阶段崩溃。然后仔细查看您的 StyleSheet 道具。就我而言,这是导致错误的原因:

container: {
    flex: 1,
    backgroundColor: '#3f3939',
    alignItems: 'left' // this made my android app crash but not on ios
  },

所以改成

container: {
    flex: 1,
    backgroundColor: '#3f3939',
    alignItems: 'center'
  },

而且效果很好。我想我在早期学习StyleSheet时就犯了这个错误🙁🙁


0
投票

我遇到了完全相同的问题。将

foregroundImage
更改为不存在的位置是可行的,但这不是一个好的解决方案,因为您必须为 Play 商店构建使用真实图像。当您使用真实图像时,某些用户会遇到与在模拟器上看到的相同的立即崩溃情况。

// Not a good solution
"android": {
  "adaptiveIcon": {
    "foregroundImage": "./assets/adaptive-icon.png", // use for release build
    // "foregroundImage": "./assets/anImageThatDoesNotExist.png", // use for development build
    "backgroundColor": "#FFFFFF"
  },

真正的问题是我的启动画面图像太大(~13MB)。我用一个较小的图像(~750KB)替换了它,并修复了看似无关的

adaptive-icon.png
崩溃。检查所有应用程序图像的大小也没什么坏处。


0
投票

我面临同样的问题,https://github.com/expo/expo/issues/20661#issuecomment-1540557732解决了它。

所以你必须安装react-native-reanimated v3,它没有得到解决并导致应用程序崩溃。


0
投票

我之前也遇到过同样的问题,我检查了 abd 日志并过滤了 ReactNative

adb logcat *:S ReactNative:V ReactNativeJS:V

我在日志中收到此错误

react-native-gesture-handler module was not found. Make sure you're running your app on the native platform and your code is linked properly (cd ios && pod install && cd ..)

我已经安装了它,但文档说我们必须将其导入到 App.js 或 index.js 中。

我将以下代码添加到我的 App.js 的标题中

import 'react-native-gesture-handler';
/* Other Imports */

之后我解决了手势处理程序的问题,然后我遇到了另一个问题

04-17 09:37:20.507 26891 26950 E ReactNativeJS: Invariant Violation: requireNativeComponent: "RNSScreen" was not found in the UIManager.

这是因为react-navigation模块所需的一些组件没有安装,我运行了以下代码并安装了依赖项,我错过添加的依赖项是react-native-screens

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

现在我为 Android 构建了预览版 apk,一切都运行良好

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