React native 0.61.5 Crashlytics missing libhermes.so: SoLoader.java com.facebook.soloader.SoLoader.assertInitialized

若如初见. 提交于 2020-08-22 11:50:53

问题


I am building a React-Native application, everything worked fine until I decided to upgrade from version 0.59.x to v 0.61.5.

When I try to release my app in the play store, I've got a lot of crashes reported by Firebase Crashlytics (v 6.2.0) -- even though my version is just available for internal testing, so it must be a pre-launch report triggered by playstore -- and it's exactly the same error for the exact same device => LGE Nexus 5X with android 6.0.1.

Fatal Exception: java.lang.UnsatisfiedLinkError: couldn't find DSO to load: libhermes.so
       at com.facebook.soloader.SoLoader.assertInitialized(SoLoader.java)
       at com.facebook.soloader.SoLoader.assertInitialized(SoLoader.java)
       at com.facebook.soloader.SoLoader.assertInitialized(SoLoader.java)
       at com.facebook.soloader.SoLoader.assertInitialized(SoLoader.java)
       at com.facebook.hermes.reactexecutor.HermesExecutor.<clinit>(HermesExecutor.java)
       at com.facebook.hermes.reactexecutor.HermesExecutorFactory.create(HermesExecutorFactory.java)
       at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java)
       at java.lang.Thread.run(Thread.java:818)

To solved this problem, I tried to submit multiple version with slightly different android configuration (for instance with and without hermes enable) but it doesn't change the end result.

Here is my build.gradle file :

apply plugin: "com.android.application"
apply plugin: "io.fabric"

import com.android.build.OutputFile

/**
 * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
 * and bundleReleaseJsAndAssets).
 * These basically call `react-native bundle` with the correct arguments during the Android build
 * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
 * bundle directly from the development server. Below you can see all the possible configurations
 * and their defaults. If you decide to add a configuration block, make sure to add it before the
 * `apply from: "../../node_modules/react-native/react.gradle"` line.
 *
 * project.ext.react = [
 *   // the name of the generated asset file containing your JS bundle
 *   bundleAssetName: "index.android.bundle",
 *
 *   // the entry file for bundle generation
 *   entryFile: "index.android.js",
 *
  *   // https://facebook.github.io/react-native/docs/performance#enable-the-ram-format
 *   bundleCommand: "ram-bundle",
 *
 *   // whether to bundle JS and assets in debug mode
 *   bundleInDebug: false,
 *
 *   // whether to bundle JS and assets in release mode
 *   bundleInRelease: true,
 *
 *   // whether to bundle JS and assets in another build variant (if configured).
 *   // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
 *   // The configuration property can be in the following formats
 *   //         'bundleIn${productFlavor}${buildType}'
 *   //         'bundleIn${buildType}'
 *   // bundleInFreeDebug: true,
 *   // bundleInPaidRelease: true,
 *   // bundleInBeta: true,
 *
 *   // whether to disable dev mode in custom build variants (by default only disabled in release)
 *   // for example: to disable dev mode in the staging build type (if configured)
 *   devDisabledInStaging: true,
 *   // The configuration property can be in the following formats
 *   //         'devDisabledIn${productFlavor}${buildType}'
 *   //         'devDisabledIn${buildType}'
 *
 *   // the root of your project, i.e. where "package.json" lives
 *   root: "../../",
 *
 *   // where to put the JS bundle asset in debug mode
 *   jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
 *
 *   // where to put the JS bundle asset in release mode
 *   jsBundleDirRelease: "$buildDir/intermediates/assets/release",
 *
 *   // where to put drawable resources / React Native assets, e.g. the ones you use via
 *   // require('./image.png')), in debug mode
 *   resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
 *
 *   // where to put drawable resources / React Native assets, e.g. the ones you use via
 *   // require('./image.png')), in release mode
 *   resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
 *
 *   // by default the gradle tasks are skipped if none of the JS files or assets change; this means
 *   // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
 *   // date; if you have any other folders that you want to ignore for performance reasons (gradle
 *   // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
 *   // for example, you might want to remove it from here.
 *   inputExcludes: ["android/**", "ios/**"],
 *
 *   // override which node gets called and with what additional arguments
 *   nodeExecutableAndArgs: ["node"],
 *
 *   // supply additional arguments to the packager
 *   extraPackagerArgs: []
 * ]
 */

project.ext.react = [
    entryFile: "index.js",
    enableHermes: false,  // clean and rebuild if changing
]

apply from: "../../node_modules/react-native/react.gradle"

/**
 * Set this to true to create two separate APKs instead of one:
 *   - An APK that only works on ARM devices
 *   - An APK that only works on x86 devices
 * The advantage is the size of the APK is reduced by about 4MB.
 * Upload all the APKs to the Play Store and people will download
 * the correct one based on the CPU architecture of their device.
 */
def enableSeparateBuildPerCPUArchitecture = false

/**
 * Run Proguard to shrink the Java bytecode in release builds.
 */
def enableProguardInReleaseBuilds = true

/**
 * The preferred build flavor of JavaScriptCore.
 *
 * For example, to use the international variant, you can use:
 * `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
 *
 * The international variant includes ICU i18n library and necessary data
 * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
 * give correct results when using with locales other than en-US.  Note that
 * this variant is about 6MiB larger per architecture than default.
 */
def jscFlavor = 'org.webkit:android-jsc:+'
/**
 * Whether to enable the Hermes VM.
 *
 * This should be set on project.ext.react and mirrored here.  If it is not set
 * on project.ext.react, JavaScript will not be compiled to Hermes Bytecode
 * and the benefits of using Hermes will therefore be sharply reduced.
 */
def enableHermes = project.ext.react.get("enableHermes", false);

def _applicationId = System.getenv("GRADLE_APP_IDENTIFIER") ?: 'com.clothparency.debug'
def appName = System.getenv("GRADLE_APP_NAME") ?: 'Clear Fashion debug'
def _versionCode = (System.getenv("ANDROID_VERSION_CODE") ?: "1") as Integer
def _versionName = System.getenv("ANDROID_VERSION_NAME") ?: "1.0.0"

android {
    compileSdkVersion rootProject.ext.compileSdkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    packagingOptions {
      exclude 'META-INF/androidx.exifinterface_exifinterface.version'
    }

    defaultConfig {
        applicationId _applicationId
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode _versionCode
        versionName _versionName
        missingDimensionStrategy 'react-native-camera', 'mlkit'
        multiDexEnabled true
    }
    dexOptions {
        javaMaxHeapSize "4g"
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
        }
    }
    signingConfigs {
        release {
            storeFile file(String.valueOf(System.getenv("GRADLE_KEYSTORE")))
            storePassword System.getenv("GRADLE_KEYSTORE_PASSWORD")
            keyAlias System.getenv("GRADLE_KEYSTORE_ALIAS")
            keyPassword System.getenv("GRADLE_KEYSTORE_ALIAS_PASSWORD")
        }
    }
    buildTypes {
        debug {
            resValue "string", "app_name", appName
            debuggable true
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
        release {
            resValue "string", "app_name", appName
            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 ->
            // For each separate APK per architecture, set a unique version code as described here:
            // https://developer.android.com/studio/build/configure-apk-splits.html
            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
            }
        }
    }
}

configurations.all {
     resolutionStrategy {
       force "com.facebook.soloader:soloader:0.8.1"
     }
}

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.facebook.react:react-native:+"  // From node_modules

    if (enableHermes) {
      def hermesPath = "../../node_modules/hermes-engine/android/";
      debugImplementation files(hermesPath + "hermes-debug.aar")
      releaseImplementation files(hermesPath + "hermes-release.aar")
    } else {
      implementation jscFlavor
    }

    implementation 'com.android.support:multidex:1.0.3'
}

// 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'

apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)

Also, my root build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext {
        buildToolsVersion = "28.0.3"
        minSdkVersion = 16
        compileSdkVersion = 28
        targetSdkVersion = 28
    }
    repositories {
        google()
        jcenter()
        maven {
            url 'https://maven.fabric.io/public'
        }
    }
    dependencies {
        classpath('com.android.tools.build:gradle:3.5.3')
        classpath 'com.google.gms:google-services:4.2.0' 

        classpath 'io.fabric.tools:gradle:1.+'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        mavenLocal()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url("$rootDir/../node_modules/react-native/android")
        }
        maven {
            // Android JSC is installed from npm
            url("$rootDir/../node_modules/jsc-android/dist")
        }

        google()
        jcenter()
        maven { url 'https://jitpack.io' }
    }
}

Here is dependencies of my package.json:

  "dependencies": {
    "@react-native-community/async-storage": "^1.6.1",
    "@react-native-firebase/analytics": "^6.2.0",
    "@react-native-firebase/app": "^6.2.0",
    "@react-native-firebase/auth": "^6.2.0",
    "@react-native-firebase/crashlytics": "^6.2.0",
    "@react-native-firebase/perf": "^6.2.0",
    "axios": "^0.18.0",
    "fast-levenshtein": "^2.0.6",
    "formik": "^1.5.7",
    "i18n-js": "^3.2.2",
    "jetifier": "^1.6.5",
    "lodash": "^4.17.11",
    "react": "16.9.0",
    "react-native": "0.61.5",
    "react-native-camera": "^3.13.1",
    "react-native-dialog": "^5.6.0",
    "react-native-fbsdk": "^1.1.1",
    "react-native-formik": "^1.7.5",
    "react-native-gesture-handler": "^1.5.2",
    "react-native-localize": "^1.1.2",
    "react-native-reanimated": "^1.4.0",
    "react-native-screens": "^1.0.0-alpha.23",
    "react-native-swiper": "^1.6.0-rc.3",
    "react-native-tab-view": "^2.11.0",
    "react-navigation": "3.13.0",
    "react-navigation-tabs": "^2.6.2",
    "react-persist": "^1.0.2",
    "react-redux": "^7.0.3",
    "redux": "^4.0.1",
    "redux-devtools-extension": "^2.13.8",
    "redux-persist": "^6.0.0",
    "redux-thunk": "^2.3.0",
    "reselect": "^4.0.0",
    "unorm": "^1.6.0",
    "yup": "^0.27.0"
  }

I found this github issues talking about this topic :

  • https://github.com/facebook/react-native/issues/25923
  • https://github.com/facebook/hermes/issues/78

But no solutions described here were worked for me.

Also found this thread on stackoverflow: React-Native :java.lang.UnsatisfiedLinkError: couldn't find DSO to load: libhermes.so : the error seems to be slightly different from mine, but solutions didn't work.

I'm afraid to release my new version into production and I'm totally stuck. Need fast help :)


回答1:


I solved this issue by generating an apk rather than an aab.

But because of the extra weight generated I'm deeply dissatisfied with this fix, and hope it's a temporary solution only.

Edit

found another solution, I added this in my build.gradle file. I am unsure of the side-effects but at least I stopped having this errors from crashlytics. But it seems I still have issues with some devices.

android {
    defaultConfig {
      // let your old config
        ndk {
            abiFilters "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
       }
    }
}

2nd Edit

Solution 2nd solution make some devices incompatible with my app. A new answer on github written by @AlexandrDobrovolskiy was the right one for me

Forcing soLoader to version 0.82

in build.gradle file:

configurations.all {
     resolutionStrategy {
       force "com.facebook.soloader:soloader:0.8.2"
     }
}


来源:https://stackoverflow.com/questions/60054822/react-native-0-61-5-crashlytics-missing-libhermes-so-soloader-java-com-facebook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!