React Native应用程序-在Android 8真实设备上启动时崩溃/关闭 [英] React Native app - crash/close on startup on Android 8 real device

查看:96
本文介绍了React Native应用程序-在Android 8真实设备上启动时崩溃/关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用react native init myapp初始化的React Native项目(不是Expo). 我可以在具有Android 5的模拟器和真实设备上运行此应用程序,但不能在具有Android 8的Android Mobile上运行该应用程序.

I have a React Native project (not Expo) initialized with react native init myapp. I can run this application on Emulator and Real Device with Android 5, but cannot run the app on my Android Mobile with Android 8.

这是package.json:

{
  "name": "myapp",
  "version": "2.0.0",
  "private": true,
  "main": "lib/index.js",
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
  },
  "dependencies": {
    "axios": "^0.18.0",
    "formik": "^1.5.1",
    "iso-639-1": "^2.0.3",
    "jsrsasign": "^8.0.12",
    "moment": "^2.24.0",
    "moment-jalaali": "^0.8.3",
    "react": "16.6.3",
    "react-native": "0.58.6",
    "react-native-app-intro-slider": "^1.0.1",
    "react-native-document-picker": "^2.3.0",
    "react-native-elements": "^1.1.0",
    "react-native-gesture-handler": "^1.1.0",
    "react-native-i18n": "^2.0.15",
    "react-native-modal-datetime-picker": "^6.0.0",
    "react-native-paper": "^2.12.0",
    "react-native-persian-calendar-picker": "^2.2.2",
    "react-native-settings-list": "^1.8.0",
    "react-native-simple-dialogs": "^1.1.0",
    "react-native-vector-icons": "^6.3.0",
    "react-navigation": "^3.3.2",
    "react-navigation-material-bottom-tabs": "^1.0.0",
    "realm": "^2.24.0",
    "yup": "^0.26.10"
  },
  "devDependencies": {
    "babel-cli": "^6.26.0",
    "babel-core": "7.0.0-bridge.0",
    "babel-jest": "24.1.0",
    "babel-preset-flow": "^6.23.0",
    "flow-bin": "^0.86.0",
    "jest": "24.1.0",
    "metro-react-native-babel-preset": "0.53.0",
    "react-test-renderer": "16.6.3"
  },
  "jest": {
    "preset": "react-native",
    "transformIgnorePatterns": [
      "node_modules/(?!(jest-)?react-native|react-navigation|react-navigation-redux-helpers)"
    ]
  },
  "rnpm": {
    "assets": [
      "./assets/fonts/"
    ]
  }
}

我已经在带有Android 5的Genymotion模拟器和带有Android 5的真实LG设备上对其进行了测试,并且一切正常.

I've tested it on Genymotion emulator with Android 5 and on a real LG device with Android 5 too and everything works fine.

但是最近,我尝试在装有Android 8的 Honor 8X 设备上运行该项目.但是,从Metro获得JS Bundle之后,该应用程序将被关闭,没有任何错误!

But lately, I tried to run this project on an Honor 8X device with Android 8. But the application will be closed without any error just after getting JS Bundle from Metro!

  • 运行命令:react-native run-android

这是react-native log-android的日志:

--------- beginning of crash
--------- beginning of system
--------- beginning of main
03-05 23:28:52.567  5513  5513 D ReactNative: ReactInstanceManager.ctor()
03-05 23:28:52.604  5513  5513 D ReactNative: ReactInstanceManager.createReactContextInBackground()
03-05 23:28:52.604  5513  5513 D ReactNative: ReactInstanceManager.recreateReactContextInBackgroundInner()
03-05 23:29:32.605  5513  5513 D ReactNative: ReactInstanceManager.onJSBundleLoadedFromServer()
03-05 23:29:32.608  5513  5513 D ReactNative: ReactInstanceManager.recreateReactContextInBackground()
03-05 23:29:32.608  5513  5513 D ReactNative: ReactInstanceManager.runCreateReactContextOnNewThread()
03-05 23:29:32.642  5513  5617 D ReactNative: ReactInstanceManager.createReactContext()

仅在最后一行显示之后,应用程序将在设备上关闭!

Just after the last line appears, the application will be closed on the device!

  • 我还授予了该应用程序所有的权限,包括在其他应用程序上绘制存储权限,并且也将其从省电模式"中排除了> ...
  • Also, I gave all of the permissions to the app, including Draw on other apps, Storage permission and also excluded it from Battery Saver...

这是Metro Bundler的输出(看起来不错):

Here's the Metro Bundler output (which looks fine):

Loading dependency graph, done.
 DELTA  [android, dev] ..\..\../index.js ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ 100.0% (1169/1169), done.

::ffff:127.0.0.1 - - [05/Mar/2019:20:02:17 +0000] "GET /index.delta?platform=android&dev=true&minify=false HTTP/1.1" 200 - "-" "okhttp/3.12.1"

  • 我尝试在Honor 8X设备上运行 Hello World 应用程序,并且该应用程序成功运行,所以我认为设备和Android都没有问题...
  • 还考虑到myapp在Android 5的模拟器和设备上成功运行,我完全感到困惑... Maby依赖项之一出现问题
    • I tried to run a Hello World application on my Honor 8X device and it runs successfully, so I think there's no problem with device and Android...
    • Also considering that myapp runs successfully on Emulator and Device with Android 5, I'm completely confused... Maby there's a problem with one of Dependencies
    • 环境: -Windows 10企业版

      Environment: - Windows 10 Enterprise

      Android专用文件: android/build.gradle :

      Android Specific Files: android/build.gradle:

      buildscript {
          ext {
              buildToolsVersion = "28.0.2"
              minSdkVersion = 16
              compileSdkVersion = 28
              targetSdkVersion = 27
              supportLibVersion = "28.0.0"
          }
          repositories {
              google()
              jcenter()
          }
          dependencies {
              classpath 'com.android.tools.build:gradle:3.2.1'
          }
      }
      allprojects {
          repositories {
              mavenLocal()
              google()
              jcenter()
              maven {
                  url "$rootDir/../node_modules/react-native/android"
              }
          }
      }
      task wrapper(type: Wrapper) {
          gradleVersion = '4.7'
          distributionUrl = distributionUrl.replace("bin", "all")
      }
      

      android/gradle.properties :

      android/gradle.properties:

      org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
      org.gradle.parallel=true
      

      android/app/build.gradle

      android/app/build.gradle

      apply plugin: "com.android.application"
      import com.android.build.OutputFile
      project.ext.react = [
          entryFile: "index.js"
      ]
      apply from: "../../node_modules/react-native/react.gradle"
      def enableSeparateBuildPerCPUArchitecture = true
      def enableProguardInReleaseBuilds = true
      android {
          compileSdkVersion rootProject.ext.compileSdkVersion
          buildToolsVersion rootProject.ext.buildToolsVersion
          defaultConfig {
              applicationId "ir.mokhtaresho.tnet.users"
              minSdkVersion rootProject.ext.minSdkVersion
              targetSdkVersion rootProject.ext.targetSdkVersion
              versionCode 1
              versionName "2.0.0"
          }
          splits {
              abi {
                  reset()
                  enable enableSeparateBuildPerCPUArchitecture
                  universalApk true
                  include "armeabi-v7a", "x86", "arm64-v8a"
              }
          }
          buildTypes {
              release {
                  minifyEnabled enableProguardInReleaseBuilds
                  proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
              }
          }
          applicationVariants.all { variant ->
              variant.outputs.each { output ->
                  def versionCodes = ["armeabi-v7a":1, "x86":2, "arm64-v8a": 3]
                  def abi = output.getFilter(OutputFile.ABI)
                  if (abi != null) {
                      output.versionCodeOverride =
                              versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
                  }
              }
          }
      }
      dependencies {
          implementation project(':realm')
          implementation project(':react-native-vector-icons')
          implementation project(':react-native-i18n')
          implementation project(':react-native-gesture-handler')
          implementation project(':react-native-document-picker')
          implementation fileTree(dir: "libs", include: ["*.jar"])
          implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
          implementation "com.facebook.react:react-native:+"
      }
      task copyDownloadableDepsToLibs(type: Copy) {
          from configurations.compile
          into 'libs'
      }
      

      推荐答案

      您是否尝试清除缓存?通常是这样的:

      Did you try to clear the cache? Usually with something like this:

      rm package-lock.json
      rm -rf node_modules
      rm -rf $TMPDIR/metro-*
      rm -rf $TMPDIR/haste-map-*
      npm cache clean
      npm install
      npm start -- --reset-cache
      

      但是您可能只需要删除都会和急速地图缓存.抱歉,如果您已经尝试过.

      But you probably need to remove only the metro and haste map cache. Sorry if you already tried that.

      这篇关于React Native应用程序-在Android 8真实设备上启动时崩溃/关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆