将 React Native 升级到 0.60-RC2 后找不到库“libjsc.so”

Posted

技术标签:

【中文标题】将 React Native 升级到 0.60-RC2 后找不到库“libjsc.so”【英文标题】:Getting library "libjsc.so" not found after upgrading React Native to 0.60-RC2 【发布时间】:2019-11-06 03:51:21 【问题描述】:

我已将 React Native 更新到 0.60-RC2,使用 android Studio refractor 迁移到 AndroidX,并使用了此处提到的 jetifier:https://github.com/react-native-community/discussions-and-proposals/issues/129

执行此操作后,我在运行 react-native run-android 时收到错误 library "libjsc.so" not found。我在运行发布 APK 时遇到同样的错误。

堆栈跟踪是:

06-24 15:55:01.823  8579  8656 E SoLoader: Error when loading lib: dlopen failed: library "libjsc.so" not found lib hash: 83f1717c1dc187d9f252a9f1fc66d430 search path is /data/app/com.jtv.testapp-4hvCKbqEmbyyOPykuQhm4Q==/lib/arm
06-24 15:55:01.823  8579  8656 E SoLoader: couldn't find DSO to load: libjscexecutor.so caused by: dlopen failed: library "libjsc.so" not found
06-24 15:55:01.825  8579  8656 E AndroidRuntime: FATAL EXCEPTION: create_react_context
06-24 15:55:01.825  8579  8656 E AndroidRuntime: Process: com.jtv.testapp, PID: 8579
06-24 15:55:01.825  8579  8656 E AndroidRuntime: java.lang.UnsatisfiedLinkError: couldn't find DSO to load: libjscexecutor.so caused by: dlopen failed: library "libjsc.so" not found
06-24 15:55:01.825  8579  8656 E AndroidRuntime:    at com.facebook.soloader.SoLoader.doLoadLibraryBySoName(SoLoader.java:738)
06-24 15:55:01.825  8579  8656 E AndroidRuntime:    at com.facebook.soloader.SoLoader.loadLibraryBySoName(SoLoader.java:591)
06-24 15:55:01.825  8579  8656 E AndroidRuntime:    at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:529)
06-24 15:55:01.825  8579  8656 E AndroidRuntime:    at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:484)
06-24 15:55:01.825  8579  8656 E AndroidRuntime:    at com.facebook.react.jscexecutor.JSCExecutor.<clinit>(JSCExecutor.java:19)
06-24 15:55:01.825  8579  8656 E AndroidRuntime:    at com.facebook.react.jscexecutor.JSCExecutorFactory.create(JSCExecutorFactory.java:29)
06-24 15:55:01.825  8579  8656 E AndroidRuntime:    at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:949)
06-24 15:55:01.825  8579  8656 E AndroidRuntime:    at java.lang.Thread.run(Thread.java:764)

我的package.json 是:


  "name": "TestApp",
  "version": "0.0.1",
  "private": true,
  "scripts": 
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
  ,
  "dependencies": 
    "@react-native-community/async-storage": "^1.2.0",
    "@react-native-community/blur": "^3.3.1",
    "@react-native-community/netinfo": "^1.2.3",
    "@react-native-community/slider": "^1.0.4",
    "axios": "^0.18.0",
    "jetifier": "^1.4.0",
    "native-base": "^2.10.0",
    "prop-types": "^15.6.2",
    "qs": "^6.6.0",
    "react": "^16.8.6",
    "react-native": "^0.60.0-rc.2",
    "react-native-appsee": "^2.6.21",
    "react-native-device-info": "^0.24.3",
    "react-native-dialog": "^5.5.0",
    "react-native-draggable-flatlist": "^1.1.7",
    "react-native-elements": "^0.19.1",
    "react-native-email": "^1.0.2",
    "react-native-fast-image": "^5.1.2",
    "react-native-gesture-handler": "^1.0.12",
    "react-native-iap": "^2.4.0",
    "react-native-image-picker": "^0.28.0",
    "react-native-iphone-x-helper": "^1.2.0",
    "react-native-keyboard-aware-scroll-view": "^0.8.0",
    "react-native-kochava-tracker": "^1.1.0",
    "react-native-linear-gradient": "^2.5.3",
    "react-native-material-dropdown": "^0.11.1",
    "react-native-modal": "^9.0.0",
    "react-native-orientation": "^3.1.3",
    "react-native-scrollable-tab-view": "^0.10.0",
    "react-native-snap-carousel": "^3.7.5",
    "react-native-super-grid": "^2.4.4",
    "react-native-tab-view": "^1.3.1",
    "react-native-underline-tabbar": "^1.3.6",
    "react-native-vector-icons": "^6.1.0",
    "react-native-video": "^4.3.1",
    "react-native-webview": "^5.12.0",
    "react-navigation": "^3.0.9",
    "react-navigation-backhandler": "^1.2.0",
    "react-redux": "^6.0.1",
    "redux": "^4.0.1",
    "redux-logger": "^3.0.6",
    "redux-thunk": "^2.3.0"
  ,
  "devDependencies": 
    "@babel/core": "^7.4.0",
    "@babel/runtime": "^7.4.2",
    "@react-native-community/eslint-config": "^0.0.3",
    "babel-jest": "^24.5.0",
    "babel-plugin-transform-remove-console": "^6.9.4",
    "eslint": "^5.15.3",
    "eslint-config-airbnb": "^17.1.0",
    "eslint-plugin-import": "^2.16.0",
    "eslint-plugin-jsx-a11y": "^6.2.1",
    "eslint-plugin-react": "^7.12.4",
    "eslint-plugin-react-hooks": "^1.5.1",
    "jest": "^24.5.0",
    "metro-react-native-babel-preset": "^0.53.1",
    "react-devtools-core": "^3.6.0",
    "react-test-renderer": "^16.8.6",
    "remote-redux-devtools": "^0.5.16"
  ,
  "jest": 
    "preset": "react-native"
  

我的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 = false

def enableProguardInReleaseBuilds = false

project.ext.vectoricons = [
    iconFontNames: [ 'MaterialIcons.ttf', 'FontAwesome.ttf', 'MaterialCommunityIcons.ttf' ]
]
apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"
android 
    compileSdkVersion rootProject.ext.compileSdkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion

    defaultConfig 
        applicationId "com.jtv.testapp"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 29
        versionName "0.0.1"
        multiDexEnabled true
        renderscriptTargetApi 29
        renderscriptSupportModeEnabled true
        ndk 
            abiFilters "arm64-v8a", "x86_64","armeabi-v7a", "x86"
        
        packagingOptions 
            pickFirst 'lib/x86_64/libjsc.so'
            pickFirst 'lib/arm64-v8a/libjsc.so'
            exclude "lib/arm64-v8a/libimagepipeline.so"
            exclude "lib/arm64-v8a/librealm-jni.so"
        
    
    signingConfigs 
        release 
            if (project.hasProperty('RELEASE_STORE_FILE')) 
                storeFile file(RELEASE_STORE_FILE)
                storePassword RELEASE_STORE_PASSWORD
                keyAlias RELEASE_KEY_ALIAS
                keyPassword RELEASE_KEY_PASSWORD
            
        
    
    splits 
        abi 
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
        
    
    buildTypes 
        release 
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
            signingConfig signingConfigs.release
        
    
    // applicationVariants are e.g. debug, release
    applicationVariants.all  variant ->
        variant.outputs.each  output ->
            def versionCodes = ["armeabi-v7a":1, "x86":2, "arm64-v8a": 3, "x86_64": 4]
            def abi = output.getFilter(OutputFile.ABI)
            if (abi != null)   // null for the universal-debug, universal-release variants
                output.versionCodeOverride =
                        versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
            
        
    
    compileOptions 
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    


dependencies 
    implementation project(':react-native-webview')
    implementation project(':react-native-jtv-comic-reader')
    //implementation project(':@react-native-community_slider')
    implementation project(':@react-native-community_blur')
    implementation project(':@react-native-community_async-storage')
    implementation project(':@react-native-community_netinfo')
    implementation project(':react-native-appsee')
//    implementation project(':react-native-tune-sdk')
    implementation project(':react-native-iap')
    implementation project(':react-native-gesture-handler')
    implementation project(':react-native-video')
    implementation project(':react-native-vector-icons')
    implementation project(':react-native-orientation')
    implementation project(':react-native-linear-gradient')
    implementation project(':react-native-kochava-tracker')
//    implementation project(':react-native-flurry-analytics')
    implementation project(':react-native-device-info')
//    implementation project(':react-native-fbsdk')
    implementation project(':react-native-fast-image')
    implementation project(':react-native-image-picker')
    implementation fileTree(dir: "libs", include: ["*.jar"])

    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation "com.facebook.react:react-native:+"  // From node_modules
    implementation 'com.facebook.fresco:fresco:1.13.0'
    implementation 'com.facebook.fresco:animated-gif:1.13.0'
    implementation 'androidx.mediarouter:mediarouter:1.0.0'

    implementation 'com.google.ads.interactivemedia.v3:interactivemedia:3.11.2'
    implementation 'com.google.android.gms:play-services-ads:18.0.0'
    implementation 'com.google.android.gms:play-services-ads-identifier:17.0.0'
    implementation 'androidx.multidex:multidex:2.0.1'

    implementation 'com.google.android.gms:play-services-ads-identifier:17.0.0'
    implementation 'com.android.installreferrer:installreferrer:1.0'
    implementation 'com.google.android.gms:play-services-location:17.0.0'
    implementation 'com.facebook.android:facebook-android-sdk:4.36.1'
    implementation 'com.swrve.sdk.android:swrve-firebase:6.0.1'
    implementation 'com.google.firebase:firebase-core:17.0.0'
    implementation 'com.google.firebase:firebase-messaging:19.0.0'

    implementation 'androidx.mediarouter:mediarouter:1.0.0'
    implementation 'com.google.android.gms:play-services-cast:17.0.0'
    implementation 'com.googlecode.android-query:android-query:0.25.9'
    implementation 'com.google.android.gms:play-services-cast-framework:17.0.0'


// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) 
    from configurations.compile
    into 'libs'

apply plugin: 'com.google.gms.google-services'

libjsc.so 文件是什么,我该如何解决这个错误?

【问题讨论】:

打开 gradle.properties => 添加 Android.useDeprecatedNdk=true 它已经在那里了。我仍然收到错误消息。 【参考方案1】:

在您的 app/build.gradle 中添加以下内容

// 在文件

顶部
def useIntlJsc = false

//在依赖项

 if (useIntlJsc) 
        implementation 'org.webkit:android-jsc-intl:+'
     else 
        implementation 'org.webkit:android-jsc:+'
    

【讨论】:

我实际上删除了旧项目,从react-native init 创建了一个新项目,并将我的代码复制到新项目中,它工作正常。所以我不能测试这个修复。如果您 100% 确定这可行,那么我会将其标记为已接受。 昨天遇到了同样的问题,我就是这样解决的。对于新项目,您将默认获得上述设置。您可以在生成的 app/build.gradle 中进行验证 这消除了libjsc.so 错误,但现在我在一个全新的 RN 0.60 RC2 项目中找不到libgnustl_shared.so 此解决方案不起作用。我得到 /com.simplewebview E/SoLoader:找不到要加载的 DSO:libjscexecutor.so 原因:dlopen 失败:找不到库“libgnustl_shared.so”/com.simplewebview E/AndroidRuntime:致命异常:create_react_context 进程:com .simplewebview,PID:26654 java.lang.UnsatisfiedLinkError:找不到要加载的 DSO:libjscexecutor.so 原因:dlopen 失败:找不到库“libgnustl_shared.so” 遇到与libgnustl_shared.so 相同的问题。对于为什么它不在 react-native 文档中,有没有人有解决方案和合理的解释?【参考方案2】:

我遇到了这个错误的轻微变化,我在我的 gradle 配置中添加了第三个 buildType,“releaseStaging”

在此实例中的修复是将以下行添加到 app/build.gradle 中的依赖项

releaseStagingImplementation files(hermesPath + "hermes-release.aar")

【讨论】:

救了我!我使用的是自定义暂存变体,但爱马仕无法正常工作,谢谢!【参考方案3】:

为我解决的问题是将 build.gradle 更新 packagingOptions 更改为:

  packagingOptions 
       pickFirst 'lib/x86/libc++_shared.so'
       pickFirst 'lib/x86/libjsc.so'
       pickFirst 'lib/x86_64/libjsc.so'
       pickFirst 'lib/arm64-v8a/libjsc.so'
       pickFirst 'lib/arm64-v8a/libc++_shared.so'
       pickFirst 'lib/x86_64/libc++_shared.so'
       pickFirst 'lib/armeabi-v7a/libc++_shared.so'
       pickFirst 'lib/armeabi-v7a/libjsc.so'
    

【讨论】:

我在 build.gradle 中没有看到任何内容。这是新的 react-native 设置的一部分吗? react-native-community.github.io/upgrade-helper/…【参考方案4】:

我也有这个问题。我需要从这里更新 build.gradle 文件中的 jscFlavor 变量:

def jscFlavor = 'org.webkit:android-jsc:+'

到这里:

def jscFlavor = 'org.webkit:android-jsc-intl:+'

干杯。

【讨论】:

这个真的救了我。万分感谢。我确实在我的应用程序中使用了 i18n。【参考方案5】:

在我的情况下,此错误与 react-native-screen 并添加以下内容有关 在 android/app/build.gradle 中的依赖项部分的两行为我解决了这个问题

implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-alpha02'

来源:Check out this Github answer

【讨论】:

这与原来的问题有什么关系??

以上是关于将 React Native 升级到 0.60-RC2 后找不到库“libjsc.so”的主要内容,如果未能解决你的问题,请参考以下文章

在 React Native 0.59 上将目标 sdk 升级到 29

react-native 升级到 0.56 后的问题

React-native 从 0.61.5 升级到 0.63.2:TypeError: Super expression must be null or a function

如何从 React ^0.14.8 & React-native ^0.24.1 升级到 React 15.0.2 和 React-native 0.26.3

React Native 0.60 升级:未知类型名称“MutexType”

将仅 JS 的 react-native 库升级到 RN 0.60