React-native 应用程序在真正的 Android 设备上崩溃 [英] React-native app crashes on real android device

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

问题描述

我正在使用 react-native,目前开始使用 redux 并创建了一个应用程序,但是当我在模拟器上运行该应用程序时,它运行良好.然后我通过 USB 将我的手机与 android 6 连接,它也在工作.但是在 Android 8 的其他设备中它不起作用然后我将 targetSdkVersion 更改为 28 然后它也不起作用我不明白是什么问题.

以下是我的 package.json

<代码>{"name": "演示",版本":0.0.1",私人":真的,脚本":{"start": "节点 node_modules/react-native/local-cli/cli.js start",测试":开玩笑"},依赖关系":{反应":16.6.3",反应原生":^0.57.8","react-native-flash-message": "^0.1.10","react-native-linear-gradient": "^2.5.3","react-native-modal-datetime-picker": "^6.0.0","react-native-navigation": "^2.8.0","react-native-tab-view": "^1.3.2","react-native-vector-icons": "^6.2.0","react-redux": "^6.0.1","redux": "^4.0.1","redux-thunk": "^2.3.0"},开发依赖":{"babel-core": "^7.0.0-bridge.0","babel-jest": "24.0.0","jest": "24.0.0","metro-react-native-babel-preset": "0.51.1",反应测试渲染器":16.6.3"},开玩笑":{预设":反应原生"}}

android/build.gradle

buildscript {分机{buildToolsVersion = "28.0.3"minSdkVersion = 19compileSdkVersion = 28目标SDK版本= 28supportLibVersion = "28.0.0"}存储库{谷歌()行家本地()MavenCentral()jcenter()}依赖{类路径 'com.android.tools.build:gradle:3.2.1'//注意:不要将您的应用程序依赖项放在这里;他们属于//在单独的模块 build.gradle 文件中}}所有项目{存储库{谷歌()MavenCentral()行家本地()jcenter()行家{//所有 React Native(JS、Obj-C 源代码、Android 二进制文件)都是从 npm 安装的url "$rootDir/../node_modules/react-native/android"}maven { url 'https://jitpack.io' }}}任务包装器(类型:包装器){gradleVersion = '4.7'distributionUrl = distributionUrl.replace("bin", "all")}子项目 { 子项目 ->后评价{if ((subproject.plugins.hasPlugin('android') || subproject.plugins.hasPlugin('android-library'))) {安卓 {变体过滤器 { 变体 ->定义名称=变体.flavors*.nameif (names.contains("reactNative51") || names.contains("reactNative55")) {设置忽略(真)}}}}}}

我不明白问题出在哪里.提前致谢

解决方案

来自

然后重新启动应用程序.

I am using react-native and currently started using redux and created one app but when I am running that app on the emulator it is working fine. Then I connected my mobile with android 6 through USB on that also it is working. But in other devices of Android 8 it is not working then I have changed targetSdkVersion to 28 then also it not working I am not getting what is the problem.

Following is my package.json

{
  "name": "Demo",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
  },
  "dependencies": {
    "react": "16.6.3",
    "react-native": "^0.57.8",
    "react-native-flash-message": "^0.1.10",
    "react-native-linear-gradient": "^2.5.3",
    "react-native-modal-datetime-picker": "^6.0.0",
    "react-native-navigation": "^2.8.0",
    "react-native-tab-view": "^1.3.2",
    "react-native-vector-icons": "^6.2.0",
    "react-redux": "^6.0.1",
    "redux": "^4.0.1",
    "redux-thunk": "^2.3.0"
  },
  "devDependencies": {
    "babel-core": "^7.0.0-bridge.0",
    "babel-jest": "24.0.0",
    "jest": "24.0.0",
    "metro-react-native-babel-preset": "0.51.1",
    "react-test-renderer": "16.6.3"
  },
  "jest": {
    "preset": "react-native"
  }
}

android/build.gradle

buildscript {
    ext {
        buildToolsVersion = "28.0.3"
        minSdkVersion = 19
        compileSdkVersion = 28
        targetSdkVersion = 28
        supportLibVersion = "28.0.0"
    }
    repositories {
        google()
        mavenLocal()
        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
        mavenLocal()
        jcenter()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
        maven { url 'https://jitpack.io' }
    }
}


task wrapper(type: Wrapper) {
    gradleVersion = '4.7'
    distributionUrl = distributionUrl.replace("bin", "all")
}

subprojects { subproject ->
    afterEvaluate {
        if ((subproject.plugins.hasPlugin('android') || subproject.plugins.hasPlugin('android-library'))) {
            android {
                variantFilter { variant ->
                    def names = variant.flavors*.name
                    if (names.contains("reactNative51") || names.contains("reactNative55")) {
                        setIgnore(true)
                    }
                }
            }
        }
    }
}

I am not getting where is the problem. Thanks in advance

解决方案

From the logs that Ahtesham Shah provided in the above chat.

2019-02-26 21:14:08.898 18689-18732/com.namaztiming E/SoLoader: couldn't find DSO to load: libglog_init.so caused by: couldn't find DSO to load: libglog.so caused by: couldn't find DSO to load: libgnustl_shared.so caused by: dlopen failed: "/data/data/com.namaztiming/lib-main/libgnustl_shared.so" is 32-bit instead of 64-bit 
2019-02-26 21:14:08.898 18689-18732/com.namaztiming E/SoLoader: couldn't find DSO to load: libreactnativejni.so caused by: couldn't find DSO to load: libglog_init.so caused by: couldn't find DSO to load: libglog.so caused by: couldn't find DSO to load: libgnustl_shared.so caused by: dlopen failed: "/data/data/com.namaztiming/lib-main/libgnustl_shared.so" is 32-bit instead of 64-bit 
2019-02-26 21:14:08.901 18689-18732/com.namaztiming E/AndroidRuntime: FATAL EXCEPTION: Thread-8 
Process: com.namaztiming, PID: 18689 
java.lang.UnsatisfiedLinkError: couldn't find DSO to load: libreactnativejni.so caused by: couldn't find DSO to load: libglog_init.so caused by: couldn't find DSO to load: libglog.so caused by: couldn't find DSO to load: libgnustl_shared.so caused by: dlopen failed: "/data/data/com.namaztiming/lib-main/libgnustl_shared.so" is 32-bit instead of 64-bit 
at com.facebook.soloader.SoLoader.doLoadLibraryBySoName(SoLoader.java:703) 
at com.facebook.soloader.SoLoader.loadLibraryBySoName(SoLoader.java:564) 
at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:500) 
at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:455) 
at com.facebook.react.bridge.ReactBridge.staticInit(ReactBridge.java:18) 
at com.facebook.react.bridge.NativeMap.<clinit>(NativeMap.java:19) 
at com.facebook.react.bridge.JSCJavaScriptExecutorFactory.create(JSCJavaScriptExecutorFactory.java:21) 
at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:917) 
at java.lang.Thread.run(Thread.java:784)

These suggest that the error is related to the following react-native issue. Where react-native doesn't support 64-bit on Android.

There is a solution to the problem that should be added to the app/build.gradle. The solution is to define the packaging options. This can be done like so.

android {
  ...
  // add the following packagingOptions 
  packagingOptions {
    pickFirst 'lib/x86_64/libjsc.so'
    pickFirst 'lib/arm64-v8a/libjsc.so'
  }
}

We also added the following to the defaultConfig in the app/build.gradle

ndk {
  abiFilters 'armeabi-v7a', 'x86'
}

Then we cleaned the build.

Then restarted the app.

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

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