React-native 应用程序在真正的 android 设备上崩溃
Posted
技术标签:
【中文标题】React-native 应用程序在真正的 android 设备上崩溃【英文标题】:React-native app crashes on real android device 【发布时间】:2019-07-20 03:48:28 【问题描述】:我正在使用 react-native,目前开始使用 redux 并创建了一个应用程序,但是当我在模拟器上运行该应用程序时,它运行良好。然后我通过USB将我的手机与android 6连接起来,它也在工作。但是在 Android 8 的其他设备中它不起作用然后我将 targetSdkVersion 更改为 28 然后它也不起作用我没有得到什么问题。
以下是我的 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)
我不知道问题出在哪里。提前致谢
【问题讨论】:
你能发布崩溃日志吗?所以我们可以看到错误是什么。当设备插入计算机时,您可以使用adb logcat -d > logs.txt
从设备中获取它们。
但应用程序甚至没有打开
对不起,我没有完整阅读让我检查一下
但是如何使用该命令我应该在运行-android之前在终端中触发它
您应该能够从 Android Studio 读取日志,从它们而不是从终端构建应用程序
【参考方案1】:
来自Ahtesham Shah在上述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)
这些表明该错误与以下react-native
issue 有关。其中react-native
在 Android 上不支持 64 位。
problem 的解决方案应添加到app/build.gradle
。解决方案是定义打包选项。可以这样做。
android
...
// add the following packagingOptions
packagingOptions
pickFirst 'lib/x86_64/libjsc.so'
pickFirst 'lib/arm64-v8a/libjsc.so'
我们还在app/build.gradle
中的defaultConfig
中添加了以下内容
ndk
abiFilters 'armeabi-v7a', 'x86'
然后我们清理了构建。
然后重启应用。
【讨论】:
还添加了ndk abiFilters 'armeabi-v7a', 'x86'
【参考方案2】:
最好的解决方案是将以下代码添加到您的 app/build.gradle 文件中。
defaultConfig
...
ndk
abiFilters "armeabi-v7a", "x86", "arm64-v8a", "x86_64", 'armeabi'
packagingOptions
exclude "lib/arm64-v8a/libgnustl_shared.so"
exclude '/lib/mips64/**'
exclude '/lib/arm64-v8a/**'
exclude '/lib/x86_64/**'
【讨论】:
以上是关于React-native 应用程序在真正的 android 设备上崩溃的主要内容,如果未能解决你的问题,请参考以下文章
react-native fastlane自动化构建分发应用管理工具for iOS and Android
React-Native:在 Android 10 和 9(API 28 和 29)dalvik.system.BaseDexClassLoader.findClass 上崩溃