首页 > 解决方案 > Expo React Native App在android上崩溃

问题描述

自从我开始在 React Native 中使用 Expo 编程以来,我一直在使用 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 上运行应用程序,请始终同时监视两者,以免您的应用程序太大而无法知道问题出在哪里......

帮助表示赞赏

标签: androidnode.jsreactjsreact-nativeexpo

解决方案


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

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

推荐阅读