【问题标题】:React native expection java.lang.UnsatisfiedLinkError: dlopen failed: "/data/data/{package}/lib-main/libgnustl_shared.so" is 32-bit instead of 64-bit反应本机期望 java.lang.UnsatisfiedLinkError: dlopen failed: "/data/data/{package}/lib-main/libgnustl_shared.so" 是 32 位而不是 64 位
【发布时间】:2017-04-03 07:41:01
【问题描述】:

我正在尝试将 React Native 与我现有的 Android 应用程序集成。初始化 React Native Screen 时出现以下异常:

java.lang.UnsatisfiedLinkError:dlopen 失败: “/data/data/com.snapdeal.main/lib-main/libgnustl_shared.so”是 32 位的 而不是 64 位

该应用仅在 64 位设备上崩溃。

根据我目前的学习,我发现这个 issue 报告在 React Native Repo 上,但是这个线程中建议的 solution 没有帮助,因为我没有在现有应用程序中使用任何外部 SO 库。

除此之外,我还发现安装了我的应用程序的设备上的库结构的另一个不同之处。我正在比较我的应用程序与反应本机演示应用程序的结构。

React 演示应用

root@generic_x86_64:**/data/data/com.react.demo/lib** # ls
libfb.so
libfolly_json.so
libglog.so
libglog_init.so
libgnustl_shared.so
libicu_common.so
libimagepipeline.so
libjsc.so
libreactnativejni.so
libreactnativejnifb.so

root@generic_x86_64:/data/data/**com.react.demo**/lib-main # ls
dso_deps
dso_lock
dso_manifest
dso_state

我的应用

root@generic_x86_64:/data/data/**com.my.app**/lib-main # ls
dso_deps
dso_lock
dso_manifest
dso_state
libfb.so
libfolly_json.so
libglog.so
libglog_init.so
libgnustl_shared.so
libicu_common.so
libimagepipeline.so
libjsc.so
libreactnativejni.so
libreactnativejnifb.so

分享一些关于我的项目的更多细节:

package.json

{
  "name": "projectname",
  "version": "1.0.0",
  "description": "Native NPM",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node node_modules/react-native/local-cli/cli.js start"
  },
  "repository": {
    "type": "git",
    "url": ""
  },
  "author": "Ishan D",
  "license": "ISC",
  "dependencies": {
    "react": "^15.3.2",
    "react-native": "^0.37.0",
    "react-native-linear-gradient": "^1.5.15",
    "rn-viewpager": "^1.1.3"
  },
  "devDependencies": {}
}

android 原生项目中使用的依赖项

ext {
    compileSdkVersion = 24
    buildToolsVersion = '24.0.2'
    minSdkVersion = 16
    targetSdkVersion = 24
    supportLibrariesVersion = '23.0.1'
    playServiceVersion = '9.0.2'

    dep = [
            fabricPlugin          : 'io.fabric',
            fabricMavenUrl        : 'https://maven.fabric.io/public',
            fabricClasspath       : 'io.fabric.tools:gradle:1.+',

            playServiceClasspath  : 'com.google.gms:google-services:1.3.0-beta1',
            playServicePlugin     : 'com.google.gms.google-services',

            playServiceAppindexing: "com.google.android.gms:play-services-appindexing:$playServiceVersion",
            playServiceLocation   : "com.google.android.gms:play-services-location:$playServiceVersion",
            playServiceVision     : "com.google.android.gms:play-services-vision:$playServiceVersion",
            playServiceAuth       : "com.google.android.gms:play-services-auth:$playServiceVersion",
            playServiceBase       : "com.google.android.gms:play-services-base:$playServiceVersion",
            playServiceIdentity   : "com.google.android.gms:play-services-identity:$playServiceVersion",
            playServiceAnalytics  : "com.google.android.gms:play-services-analytics:$playServiceVersion",
            playServiceGcm        : "com.google.android.gms:play-services-gcm:$playServiceVersion",

            underCouchClasspath   : 'de.undercouch:gradle-download-task:2.0.0',
            underCouchPluigin     : 'de.undercouch.download',

            crashlytics           : 'com.crashlytics.sdk.android:crashlytics:2.4.0@aar',

            moengage              : 'com.moengage:moe-android-sdk:6.0.29',

            supportV4             : "com.android.support:support-v4:$supportLibrariesVersion",
            supportAppCompatV7    : "com.android.support:appcompat-v7:$supportLibrariesVersion",
            supportCardviewV7     : "com.android.support:cardview-v7:$supportLibrariesVersion",
            supportDesignV7       : "com.android.support:design:$supportLibrariesVersion",

            okhttp                : 'com.squareup.okhttp:okhttp:2.5.0',
            junit                 : 'junit:junit:4.12',
            mockito               : 'org.mockito:mockito-core:1.10.19'
    ]
}

感谢任何线索。

PS:我知道 react-native 确实支持 64 位二进制文​​件,我没有使用任何外部库。

【问题讨论】:

    标签: android react-native java-native-interface react-native-android .so


    【解决方案1】:

    将以下内容添加到 app/gradle 文件中

    defaultConfig {
    ....
    
        ndk {
            abiFilters "armeabi-v7a", "x86", 'armeabi', 'arm64-v8a'
        }
    
        packagingOptions {
            exclude "lib/arm64-v8a/libgnustl_shared.so"
        }
    }
    

    还要确保您使用相同的端口。

    adb reverse tcp:8081 tcp:8081
    

    【讨论】:

    • 还在 abiFilters 中添加“armeabi”,没有它。在三星 s7 等某些手机上工作,facebook 应该做得更好。添加所有过滤器的工作。需要添加以确保这适用于所有设备。
    【解决方案2】:

    它还可以帮助您: build.gradle(应用程序)

    android{
       ...
       defaultConfig {
          ....
          ndk {
            abiFilters "armeabi-v7a", "x86", 'armeabi', 'arm64-v8a'
          }
          packagingOptions {
                   exclude "lib/arm64-v8a/libgnustl_shared.so"
                   exclude '/lib/mips64/**'
                   exclude '/lib/arm64-v8a/**'
                   exclude '/lib/x86_64/**'
          }
          ...
       }
    }
    

    【讨论】:

    • 使用此 build.gradle 部署 APK 是否支持 64 位的 google play 商店?
    • No google will not allowed as 64 bit 也可以检查 Build -> Analyze Apk
    【解决方案3】:

    React Native 不提供 64 位版本的原生代码,系统总是回退到 32 位。 他们已经解决了这个问题,并计划成为RN 0.59 release 的一部分 参考:https://github.com/facebook/react-native/issues/2814#issuecomment-457644191

    【讨论】:

      【解决方案4】:
      Using RN 0.60.5 version.
      If you guys are wondering why your app crashes if you download it from playstore, make the below changes
      
      **packagingOptions {
      exclude '/lib/mips64/'
      exclude '/lib/arm64-v8a/'
      exclude '/lib/x86_64/**'
      //In pickFirst, replace the library name with the library that is causing error.
      pickFirst '/lib/x86/libgnustl_shared.so' 
      pickFirst '/lib/armeabi-v7a/libgnustl_shared.so'
      }**
      
      REASON - We are excluding all 64 bit libraries so that OS will not have confusion of which library to pick.
      
      If you do not know which library is causing the crash, upload your bundle in Firebase test lab and then check. It will tell you which library is throwing the error
      

      【讨论】:

      • 请在您的回答中添加一些描述
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-10-29
      • 1970-01-01
      • 2016-07-13
      • 1970-01-01
      • 2012-12-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多