facebook / react-native

A framework for building native applications using React
https://reactnative.dev
MIT License
118.56k stars 24.28k forks source link

[0.60.3] App crash on startup when enabling Hermes (enableHermes: true) #25601

Closed bhaskarGyan closed 5 years ago

bhaskarGyan commented 5 years ago

App is crashing when I enable Hermes in android/app/build.gradle. App is working fine with react-native 0.60.3 with enableHermes: false

Error:

07-12 08:06:59.097 20330-20330/com.reactnativememoryprofile E/SoLoader: couldn't find DSO to load: libjscexecutor.so 07-12 08:06:59.123 20330-20345/com.reactnativememoryprofile E/SoLoader: couldn't find DSO to load: libhermes.so 07-12 08:06:59.124 20330-20345/com.reactnativememoryprofile E/AndroidRuntime: FATAL EXCEPTION: create_react_context Process: com.reactnativememoryprofile, PID: 20330 java.lang.UnsatisfiedLinkError: couldn't find DSO to load: libhermes.so at com.facebook.soloader.SoLoader.doLoadLibraryBySoName(SoLoader.java:738) at com.facebook.soloader.SoLoader.loadLibraryBySoName(SoLoader.java:591) at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:529) at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:484) at com.facebook.hermes.reactexecutor.HermesExecutor.<clinit>(HermesExecutor.java:20) at com.facebook.hermes.reactexecutor.HermesExecutorFactory.create(HermesExecutorFactory.java:27) at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:949) at java.lang.Thread.run(Thread.java:818)

React Native version: System: OS: macOS 10.14.5 CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz Memory: 373.31 MB / 16.00 GB Shell: 3.2.57 - /bin/bash Binaries: Node: 10.15.1 - /usr/local/bin/node Yarn: 1.13.0 - /usr/local/bin/yarn npm: 6.4.1 - /usr/local/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman SDKs: iOS SDK: Platforms: iOS 12.2, macOS 10.14, tvOS 12.2, watchOS 5.2 Android SDK: API Levels: 23, 24, 25, 26, 27, 28 Build Tools: 21.1.2, 23.0.1, 25.0.0, 25.0.1, 25.0.2, 26.0.2, 26.0.3, 27.0.3, 28.0.0, 28.0.2, 28.0.3, 29.0.0 System Images: android-23 | Intel x86 Atom, android-23 | Google APIs Intel x86 Atom, android-23 | Google APIs Intel x86 Atom_64, android-27 | Android TV Intel x86 Atom, android-27 | Intel x86 Atom, android-27 | Intel x86 Atom_64, android-27 | Google APIs Intel x86 Atom, android-27 | Google Play Intel x86 Atom, android-28 | Intel x86 Atom, android-28 | Intel x86 Atom_64, android-28 | Google APIs Intel x86 Atom, android-28 | Google APIs Intel x86 Atom_64, android-28 | Google Play Intel x86 Atom, android-28 | Google Play Intel x86 Atom_64 Android NDK: 20.0.5594570 IDEs: Android Studio: 3.4 AI-183.6156.11.34.5522156 Xcode: 10.2/10E125 - /usr/bin/xcodebuild npmPackages: react: 16.8.6 => 16.8.6 react-native: ^0.60.3 => 0.60.3 npmGlobalPackages: react-native-cli: 2.0.1 react-native-create-library: 3.1.2 react-native-git-upgrade: 0.2.7 m-c02xf2cejg5h:reactNativeMemoryProfi

Steps To Reproduce

  1. Follow the steps mentioned in hermes
  2. react-native run-android --variant release

Describe what you expected to happen: App should not crash

Snack, code example, or link to a repository:

https://github.com/bhaskarGyan/react-native-memory-profile/tree/bug/rn-0.60.3_hermes

IamMasterWayne commented 5 years ago

+1

lucadruda commented 5 years ago

I got the same error (couldn't find DSO to load: libhermes.so) even with hermes disabled and without changing any gradle file apparently. After looking at the logcat I saw the initial error few lines above:

dlopen failed: library "libjsc.so" not found

and I guess the hermes error happens because of the fallback. Then after double check my gradle files I found the issue (at least for me)

I had this in my root build.gradle:

maven {
            // Android JSC is installed from npm
            url("$rootDir/../node_modules/jsc-android/dist")
            url("https://jitpack.io")
        }

where I added jitpack because of a 3rd party library requirement.

After changing to this (separate blocks):

maven {
            // Android JSC is installed from npm
            url("$rootDir/../node_modules/jsc-android/dist")
        }
maven {
             url("https://jitpack.io")
        }

The issue is gone and app doesn't crash anymore. So it looks like build succeeds but resulting APK doesn't contain the right 'jsc' libraries, probably because download fails in the maven directive (don't have a real explanation btw).

Ansonmathew commented 4 years ago

Install Hermes Engine. NPM

norbertsongin commented 4 years ago

In react.gradle there are checks like this:

targetName.toLowerCase().contains("release")

So I've decided to just rename my custom target name from alpha to alphaRelease.

mwss1996 commented 4 years ago

In my case I had "hermes-engine" folder instead of "hermesvm" under node_modules so when I changed the folder name to hermes-engine in the app's build.gradle the error was gone (my RN version is 0.61.0)

on RN 0.61.1 this problem seems resolved so i would suggest upgrading your RN version.

This worked for me!

singhamitkumar commented 4 years ago

After enabling Hermes in your project, Please update the Hermes path in "android/app/build.gradle" file. You can see the sample code below.

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

After the update of hermesPath, run your application react-native run-android. Hermes issue has been fixed.

Yushenbo commented 4 years ago

@SourceCipher Yes, it works, these are the bits from my app/build.gradle

project.ext.react = [
    entryFile: "index.android.js",
    enableHermes: false
]

def enableHermes = project.ext.react.get("enableHermes", false);
def jscFlavor = 'org.webkit:android-jsc:+'
def safeExtGet(prop, fallback) {
    rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}

// ... later on ....

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

After that, though I ran into red screen issues connecting to 10.0.2.2:8081, which I solved by modifying AndroidManifest.xml:

<application
     android:usesCleartextTraffic="true"
     ....

hi I follow yours modifications, but there will be a Error "libjsexecutor.so not found", and add this https://github.com/facebook/react-native/issues/25537#issuecomment-509959166 modification, app works fine

juicycleff commented 4 years ago

Should be this as of RN 0.60.4

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

@juicycleff I can confirm that this works with RN 0.61.2 as well.

bitsmanent commented 4 years ago

Thanks @aliozinan !

I'm on RN 0.61.2 and fixed by replacing hermesvm with hermes-engine in android/app/build.gradle, like this:

def hermesPath = "../../node_modules/hermes-engine/android/";

Now everything works properly.

roots-ai commented 4 years ago

In my case I had "hermes-engine" folder instead of "hermesvm" under node_modules so when I changed the folder name to hermes-engine in the app's build.gradle the error was gone (my RN version is 0.61.0)

on RN 0.61.1 this problem seems resolved so i would suggest upgrading your RN version.

Doesn't work.

https://github.com/facebook/react-native/issues/27116

aliozinan commented 4 years ago

In my case I had "hermes-engine" folder instead of "hermesvm" under node_modules so when I changed the folder name to hermes-engine in the app's build.gradle the error was gone (my RN version is 0.61.0) on RN 0.61.1 this problem seems resolved so i would suggest upgrading your RN version.

Doesn't work.

The error you're getting is clearly telling you that a property was being set multiple times in the object definition during the build process.

This issue is about enabling Hermes Engine and building the project successfully by resolving the "DSO not found" error, hence your issue is not related to this one and should be investigated seperately.

So as a result, my solution actually works for the related issue being this one.

Try with 0.60.0 or 0.61.1 versions, apply the solution recommended in the above messages and check if you're able to get a successful build. If you get "DSO not found" error, report here. Finally, remove the reference in your message here to the issue you opened, it's a wrong reference.

MarcoF09 commented 4 years ago

In my side the problem was fixed when I run 'Clean project' and then run again.

Iamniks4 commented 4 years ago

In my case I saw this crash when:

  1. I first build release with enableHermes: false
  2. Change enableHermes: true
  3. Build release

all while

def enableHermes = project.ext.react.get("enableHermes", false);

and

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

were present.

Crash disappears after cleaning the build: cd android && ./gradlew clean

i did the same thing, alongwith "def enableProguardInReleaseBuilds = false" in the same file, but when i pushed my app bundle to play store it is crashing on startup.

nokite commented 4 years ago

For people with more build types (let's call it anotherDebug):


// In dependencies {}:
    debugImplementation files(hermesPath + "hermes-debug.aar")
    anotherDebugImplementation files(hermesPath + "hermes-debug.aar")
    releaseImplementation files(hermesPath + "hermes-release.aar")

// This is where the build types are specified (in buildTypes {}):
        anotherDebug {
            initWith buildTypes.debug
            matchingFallbacks = ['debug'] // For libs that don't have this build type
            // Add stuff that makes anotherDebug necessary for you
        }
maitrungduc1410 commented 4 years ago

For anyone having this issue, this may help.

From React native docs:

Note about Android App Bundles Android app bundles are not yet supported with hermes

That means Hermes is only for .apk. I was really had a headache because my release .aab stucks on splash screen 🤣

Hope this help

Update: Hermes is now supported since RN 0.62 and up

SudoPlz commented 4 years ago

@maitrungduc1410 oh my god, I've been banging my head on the wall for hours with that.

That being said, it now says:

Android app bundles are supported from react-native 0.62.0 and up. so 0.63.2 shouldn't be affected.

StebanDev commented 4 years ago

For people with more build types (let's call it anotherDebug):


// In dependencies {}:
    debugImplementation files(hermesPath + "hermes-debug.aar")
    anotherDebugImplementation files(hermesPath + "hermes-debug.aar")
    releaseImplementation files(hermesPath + "hermes-release.aar")

// This is where the build types are specified (in buildTypes {}):
        anotherDebug {
            initWith buildTypes.debug
            matchingFallbacks = ['debug'] // For libs that don't have this build type
            // Add stuff that makes anotherDebug necessary for you
        }

This solved my issue, thank you @nokite .

77TecShaeer commented 3 years ago

+++

Sheharyar566 commented 3 years ago

I don't have any more than the already present build types, but I did add product flavors and here's my build.gradle... And it is crashing without giving any logs

apply plugin: "com.android.application"

import com.android.build.OutputFile

project.ext.react = [
    entryFile: "index.js",
    enableHermes: true
]

apply from: '../../node_modules/react-native-unimodules/gradle.groovy'
apply from: "../../node_modules/react-native/react.gradle"
apply from: "../../node_modules/expo-updates/scripts/create-manifest-android.gradle"

def enableSeparateBuildPerCPUArchitecture = false

def enableProguardInReleaseBuilds = true

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

def enableHermes = project.ext.react.get("enableHermes", false);

android {
    compileSdkVersion rootProject.ext.compileSdkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        applicationId "com.coolconnect.pax"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 7
        versionName "1.0.7"
        manifestPlaceholders = [appAuthRedirectScheme: 'com.coolconnect.pax']
        resConfigs "en", "es"
    }
    signingConfigs {
        debug {
            storeFile file('debug.keystore')
            storePassword 'android'
            keyAlias 'androiddebugkey'
            keyPassword 'android'
        }
    }
    buildTypes {
        debug {
            signingConfig signingConfigs.debug
        }
        release {
            // Caution! In production, you need to generate your own keystore file.
            // see https://reactnative.dev/docs/signed-apk-android.
            signingConfig signingConfigs.debug
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
            shrinkResources true
        }
    }

    flavorDimensions "Default"

    productFlavors {
        TaxisPlus {
            applicationId 'com.taxisplus.pax'
        }
        CoolConnect {
        }
    }

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

        }
    }
}

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    //noinspection GradleDynamicVersion
    implementation "com.facebook.react:react-native:+"  // From node_modules
    implementation "com.android.support:appcompat-v7:23.0.1"
    implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
    implementation 'com.facebook.android:facebook-android-sdk:[5,6)'
    implementation 'com.google.firebase:firebase-core:16.0.7'

    debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
        exclude group:'com.facebook.fbjni'
    }
    debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
        exclude group:'com.facebook.flipper'
        exclude group:'com.squareup.okhttp3', module:'okhttp'
    }
    debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
        exclude group:'com.facebook.flipper'
    }
    addUnimodulesDependencies()

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

// 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 from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
apply plugin: 'com.google.gms.google-services'
77TecShaeer commented 3 years ago

Whats this is !?

On Thu, 22 Apr 2021 at 3:24 PM Shehar Yar Khan @.***> wrote:

I don't have any more than the already present build types, but I did add product flavors and here's my build.gradle... And it is crashing without giving any logs ` apply plugin: "com.android.application"

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. If none specified and
  • // "index.android.js" exists, it will be used. Otherwise "index.js" is
  • // default. Can be overridden with ENTRY_FILE environment variable.
  • entryFile: "index.android.js",
  • // https://reactnative.dev/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: true ]

apply from: '../../node_modules/react-native-unimodules/gradle.groovy' apply from: "../../node_modules/react-native/react.gradle" apply from: "../../node_modules/expo-updates/scripts/create-manifest-android.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);

android { compileSdkVersion rootProject.ext.compileSdkVersion

compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 }

defaultConfig { applicationId "com.coolconnect.pax" minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion versionCode 7 versionName "1.0.7" manifestPlaceholders = [appAuthRedirectScheme: 'com.coolconnect.pax'] resConfigs "en", "es" } signingConfigs { debug { storeFile file('debug.keystore') storePassword 'android' keyAlias 'androiddebugkey' keyPassword 'android' } } buildTypes { debug { signingConfig signingConfigs.debug } release { // Caution! In production, you need to generate your own keystore file. // see https://reactnative.dev/docs/signed-apk-android. signingConfig signingConfigs.debug minifyEnabled enableProguardInReleaseBuilds proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" shrinkResources true } }

flavorDimensions "Default"

productFlavors { TaxisPlus { applicationId 'com.taxisplus.pax' } CoolConnect { } }

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

}

}

}

dependencies { implementation fileTree(dir: "libs", include: ["*.jar"]) //noinspection GradleDynamicVersion implementation "com.facebook.react:react-native:+" // From node_modules implementation "com.android.support:appcompat-v7:23.0.1" implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0" implementation 'com.facebook.android:facebook-android-sdk:[5,6)' implementation 'com.google.firebase:firebase-core:16.0.7'

debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") { exclude group:'com.facebook.fbjni' } debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") { exclude group:'com.facebook.flipper' exclude group:'com.squareup.okhttp3', module:'okhttp' } debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") { exclude group:'com.facebook.flipper' } addUnimodulesDependencies()

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

}

// 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 from: @.***/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project) apply plugin: 'com.google.gms.google-services' `

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/facebook/react-native/issues/25601#issuecomment-824838810, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIVHJXYGIF6K5D7C62RRS3TTKAPSXANCNFSM4IB7MAMQ .

Sheharyar566 commented 3 years ago

android/app/build.gradle @77TecShaeer