facebook / hermes

A JavaScript engine optimized for running React Native.
https://hermesengine.dev/
MIT License
9.71k stars 622 forks source link

Hermes 0.7.2 : Max heap size was exceeded #1304

Closed atoui-zahreddine closed 7 months ago

atoui-zahreddine commented 7 months ago

Bug Description

Hermes git revision (if applicable): 0.7.2 React Native version: 0.64.4 OS: Android 12 + Platform : arm64-v8a

Steps To Reproduce

  1. Run and navigate through the app,
  2. The crash will occur when there's a large object saved with AsyncStorage

code example:

The Expected Behavior

Google Play Console stack trace :

*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
pid: 0, tid: 22460 >>> com.bumbal <<<

backtrace:
  #00  pc 0x00000000000513c4  /apex/com.android.runtime/lib64/bionic/libc.so (abort+180)
  #01  pc 0x000000000062f7b0  /apex/com.android.art/lib64/libart.so (art::Runtime::Abort(char const*)+728)
  #02  pc 0x0000000000015aa0  /system/lib64/libbase.so (android::base::SetAborter(std::__1::function<void (char const*)>&&)::$_3::__invoke(char const*)+80)
  #03  pc 0x0000000000006e3c  /system/lib64/liblog.so (__android_log_assert+308)
  #04  pc 0x000000000001fa5c  /data/app/~~cwgn15RzPp5nMLby3wkQSQ==/com.bumbal-OphWlg4hSLEWlliGhEphdg==/split_config.arm64_v8a.apk!libhermes-executor-release.so (BuildId: 9cca3cffdd7bbe9e5e818141782ae8c47e56a5b3)
  #05  pc 0x00000000001a1438  /data/app/~~cwgn15RzPp5nMLby3wkQSQ==/com.bumbal-OphWlg4hSLEWlliGhEphdg==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 55f79e163ab95fbb3da9b8db0d7929b488aa23e7)
  #06  pc 0x00000000001a1338  /data/app/~~cwgn15RzPp5nMLby3wkQSQ==/com.bumbal-OphWlg4hSLEWlliGhEphdg==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 55f79e163ab95fbb3da9b8db0d7929b488aa23e7)
  #07  pc 0x0000000000178218  /data/app/~~cwgn15RzPp5nMLby3wkQSQ==/com.bumbal-OphWlg4hSLEWlliGhEphdg==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 55f79e163ab95fbb3da9b8db0d7929b488aa23e7)
  #08  pc 0x0000000000044f08  /data/app/~~cwgn15RzPp5nMLby3wkQSQ==/com.bumbal-OphWlg4hSLEWlliGhEphdg==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 55f79e163ab95fbb3da9b8db0d7929b488aa23e7)
  #09  pc 0x00000000000e424c  /data/app/~~cwgn15RzPp5nMLby3wkQSQ==/com.bumbal-OphWlg4hSLEWlliGhEphdg==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 55f79e163ab95fbb3da9b8db0d7929b488aa23e7)
  #10  pc 0x0000000000051508  /data/app/~~cwgn15RzPp5nMLby3wkQSQ==/com.bumbal-OphWlg4hSLEWlliGhEphdg==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 55f79e163ab95fbb3da9b8db0d7929b488aa23e7)
  #11  pc 0x000000000004f7e8  /data/app/~~cwgn15RzPp5nMLby3wkQSQ==/com.bumbal-OphWlg4hSLEWlliGhEphdg==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 55f79e163ab95fbb3da9b8db0d7929b488aa23e7)
  #12  pc 0x0000000000065eb4  /data/app/~~cwgn15RzPp5nMLby3wkQSQ==/com.bumbal-OphWlg4hSLEWlliGhEphdg==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 55f79e163ab95fbb3da9b8db0d7929b488aa23e7)
  #13  pc 0x00000000000586c4  /data/app/~~cwgn15RzPp5nMLby3wkQSQ==/com.bumbal-OphWlg4hSLEWlliGhEphdg==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 55f79e163ab95fbb3da9b8db0d7929b488aa23e7)
  #14  pc 0x000000000005533c  /data/app/~~cwgn15RzPp5nMLby3wkQSQ==/com.bumbal-OphWlg4hSLEWlliGhEphdg==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 55f79e163ab95fbb3da9b8db0d7929b488aa23e7)
  #15  pc 0x0000000000041a68  /data/app/~~cwgn15RzPp5nMLby3wkQSQ==/com.bumbal-OphWlg4hSLEWlliGhEphdg==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 55f79e163ab95fbb3da9b8db0d7929b488aa23e7)
  #16  pc 0x000000000004138c  /data/app/~~cwgn15RzPp5nMLby3wkQSQ==/com.bumbal-OphWlg4hSLEWlliGhEphdg==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 55f79e163ab95fbb3da9b8db0d7929b488aa23e7)
  #17  pc 0x00000000000541ec  /data/app/~~cwgn15RzPp5nMLby3wkQSQ==/com.bumbal-OphWlg4hSLEWlliGhEphdg==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 55f79e163ab95fbb3da9b8db0d7929b488aa23e7)
  #18  pc 0x0000000000055b5c  /data/app/~~cwgn15RzPp5nMLby3wkQSQ==/com.bumbal-OphWlg4hSLEWlliGhEphdg==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 55f79e163ab95fbb3da9b8db0d7929b488aa23e7)
  #19  pc 0x000000000005533c  /data/app/~~cwgn15RzPp5nMLby3wkQSQ==/com.bumbal-OphWlg4hSLEWlliGhEphdg==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 55f79e163ab95fbb3da9b8db0d7929b488aa23e7)
  #20  pc 0x0000000000041a68  /data/app/~~cwgn15RzPp5nMLby3wkQSQ==/com.bumbal-OphWlg4hSLEWlliGhEphdg==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 55f79e163ab95fbb3da9b8db0d7929b488aa23e7)
  #21  pc 0x0000000000040698  /data/app/~~cwgn15RzPp5nMLby3wkQSQ==/com.bumbal-OphWlg4hSLEWlliGhEphdg==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 55f79e163ab95fbb3da9b8db0d7929b488aa23e7)
  #22  pc 0x00000000000cb778  /data/app/~~cwgn15RzPp5nMLby3wkQSQ==/com.bumbal-OphWlg4hSLEWlliGhEphdg==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 55f79e163ab95fbb3da9b8db0d7929b488aa23e7)
  #23  pc 0x000000000004180c  /data/app/~~cwgn15RzPp5nMLby3wkQSQ==/com.bumbal-OphWlg4hSLEWlliGhEphdg==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 55f79e163ab95fbb3da9b8db0d7929b488aa23e7)
  #24  pc 0x00000000000541d0  /data/app/~~cwgn15RzPp5nMLby3wkQSQ==/com.bumbal-OphWlg4hSLEWlliGhEphdg==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 55f79e163ab95fbb3da9b8db0d7929b488aa23e7)
  #25  pc 0x0000000000055b5c  /data/app/~~cwgn15RzPp5nMLby3wkQSQ==/com.bumbal-OphWlg4hSLEWlliGhEphdg==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 55f79e163ab95fbb3da9b8db0d7929b488aa23e7)
  #26  pc 0x000000000005533c  /data/app/~~cwgn15RzPp5nMLby3wkQSQ==/com.bumbal-OphWlg4hSLEWlliGhEphdg==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 55f79e163ab95fbb3da9b8db0d7929b488aa23e7)
  #27  pc 0x0000000000041a68  /data/app/~~cwgn15RzPp5nMLby3wkQSQ==/com.bumbal-OphWlg4hSLEWlliGhEphdg==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 55f79e163ab95fbb3da9b8db0d7929b488aa23e7)
  #28  pc 0x0000000000040698  /data/app/~~cwgn15RzPp5nMLby3wkQSQ==/com.bumbal-OphWlg4hSLEWlliGhEphdg==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 55f79e163ab95fbb3da9b8db0d7929b488aa23e7)
  #29  pc 0x00000000000cb778  /data/app/~~cwgn15RzPp5nMLby3wkQSQ==/com.bumbal-OphWlg4hSLEWlliGhEphdg==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 55f79e163ab95fbb3da9b8db0d7929b488aa23e7)
  #30  pc 0x000000000004180c  /data/app/~~cwgn15RzPp5nMLby3wkQSQ==/com.bumbal-OphWlg4hSLEWlliGhEphdg==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 55f79e163ab95fbb3da9b8db0d7929b488aa23e7)
  #31  pc 0x00000000000541d0  /data/app/~~cwgn15RzPp5nMLby3wkQSQ==/com.bumbal-OphWlg4hSLEWlliGhEphdg==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 55f79e163ab95fbb3da9b8db0d7929b488aa23e7)
  #32  pc 0x0000000000055b5c  /data/app/~~cwgn15RzPp5nMLby3wkQSQ==/com.bumbal-OphWlg4hSLEWlliGhEphdg==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 55f79e163ab95fbb3da9b8db0d7929b488aa23e7)
  #33  pc 0x000000000005533c  /data/app/~~cwgn15RzPp5nMLby3wkQSQ==/com.bumbal-OphWlg4hSLEWlliGhEphdg==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 55f79e163ab95fbb3da9b8db0d7929b488aa23e7)
  #34  pc 0x0000000000041a68  /data/app/~~cwgn15RzPp5nMLby3wkQSQ==/com.bumbal-OphWlg4hSLEWlliGhEphdg==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 55f79e163ab95fbb3da9b8db0d7929b488aa23e7)
  #35  pc 0x000000000004138c  /data/app/~~cwgn15RzPp5nMLby3wkQSQ==/com.bumbal-OphWlg4hSLEWlliGhEphdg==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 55f79e163ab95fbb3da9b8db0d7929b488aa23e7)
  #36  pc 0x00000000000541ec  /data/app/~~cwgn15RzPp5nMLby3wkQSQ==/com.bumbal-OphWlg4hSLEWlliGhEphdg==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 55f79e163ab95fbb3da9b8db0d7929b488aa23e7)
  #37  pc 0x0000000000055b5c  /data/app/~~cwgn15RzPp5nMLby3wkQSQ==/com.bumbal-OphWlg4hSLEWlliGhEphdg==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 55f79e163ab95fbb3da9b8db0d7929b488aa23e7)
  #38  pc 0x000000000005533c  /data/app/~~cwgn15RzPp5nMLby3wkQSQ==/com.bumbal-OphWlg4hSLEWlliGhEphdg==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 55f79e163ab95fbb3da9b8db0d7929b488aa23e7)
  #39  pc 0x0000000000041a68  /data/app/~~cwgn15RzPp5nMLby3wkQSQ==/com.bumbal-OphWlg4hSLEWlliGhEphdg==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 55f79e163ab95fbb3da9b8db0d7929b488aa23e7)
  #40  pc 0x000000000004138c  /data/app/~~cwgn15RzPp5nMLby3wkQSQ==/com.bumbal-OphWlg4hSLEWlliGhEphdg==/split_config.arm64_v8a.apk!libhermes.so (BuildId: 55f79e163ab95fbb3da9b8db0d7929b488aa23e7)
  #41  pc 0x0000000000030b04  /data/app/~~cwgn15RzPp5nMLby3wkQSQ==/com.bumbal-OphWlg4hSLEWlliGhEphdg==/split_config.arm64_v8a.apk!libhermes.so (facebook::hermes::HermesRuntimeImpl::call(facebook::jsi::Function const&, facebook::jsi::Value const&, facebook::jsi::Value const*, unsigned long)+292) (BuildId: 55f79e163ab95fbb3da9b8db0d7929b488aa23e7)
  #42  pc 0x0000000000023d78  /data/app/~~cwgn15RzPp5nMLby3wkQSQ==/com.bumbal-OphWlg4hSLEWlliGhEphdg==/split_config.arm64_v8a.apk!libhermes-executor-release.so (facebook::jsi::Value facebook::jsi::Function::call<double const&, facebook::jsi::Value>(facebook::jsi::Runtime&, double const&, facebook::jsi::Value&&) const+120) (BuildId: 9cca3cffdd7bbe9e5e818141782ae8c47e56a5b3)
  #43  pc 0x0000000000023bb0  /data/app/~~cwgn15RzPp5nMLby3wkQSQ==/com.bumbal-OphWlg4hSLEWlliGhEphdg==/split_config.arm64_v8a.apk!libhermes-executor-release.so (facebook::react::JSIExecutor::invokeCallback(double, folly::dynamic const&)+164) (BuildId: 9cca3cffdd7bbe9e5e818141782ae8c47e56a5b3)
  #44  pc 0x00000000000a9e24  /data/app/~~cwgn15RzPp5nMLby3wkQSQ==/com.bumbal-OphWlg4hSLEWlliGhEphdg==/split_config.arm64_v8a.apk!libreactnativejni.so (BuildId: 879f1a041363d354f938513fc3587fe15467bcf6)
  #45  pc 0x00000000000aae04  /data/app/~~cwgn15RzPp5nMLby3wkQSQ==/com.bumbal-OphWlg4hSLEWlliGhEphdg==/split_config.arm64_v8a.apk!libreactnativejni.so (BuildId: 879f1a041363d354f938513fc3587fe15467bcf6)
  #46  pc 0x00000000000711b0  /data/app/~~cwgn15RzPp5nMLby3wkQSQ==/com.bumbal-OphWlg4hSLEWlliGhEphdg==/split_config.arm64_v8a.apk!libreactnativejni.so (BuildId: 879f1a041363d354f938513fc3587fe15467bcf6)
  #47  pc 0x0000000000060260  /data/app/~~cwgn15RzPp5nMLby3wkQSQ==/com.bumbal-OphWlg4hSLEWlliGhEphdg==/split_config.arm64_v8a.apk!libreactnativejni.so (facebook::jni::detail::MethodWrapper<void (facebook::react::JNativeRunnable::*)(), &(facebook::react::JNativeRunnable::run()), facebook::react::JNativeRunnable, void>::dispatch(facebook::jni::alias_ref<facebook::jni::detail::JTypeFor<facebook::jni::HybridClass<facebook::react::JNativeRunnable, facebook::react::Runnable>::JavaPart, facebook::react::Runnable, void>::_javaobject*>)+32) (BuildId: 879f1a041363d354f938513fc3587fe15467bcf6)
  #48  pc 0x00000000000601dc  /data/app/~~cwgn15RzPp5nMLby3wkQSQ==/com.bumbal-OphWlg4hSLEWlliGhEphdg==/split_config.arm64_v8a.apk!libreactnativejni.so (facebook::jni::detail::FunctionWrapper<void (*)(facebook::jni::alias_ref<facebook::jni::detail::JTypeFor<facebook::jni::HybridClass<facebook::react::JNativeRunnable, facebook::react::Runnable>::JavaPart, facebook::react::Runnable, void>::_javaobject*>), &(facebook::jni::detail::MethodWrapper<void (facebook::react::JNativeRunnable::*)(), &(facebook::react::JNativeRunnable::run()), facebook::react::JNativeRunnable, void>::dispatch(facebook::jni::alias_ref<facebook::jni::detail::JTypeFor<facebook::jni::HybridClass<facebook::react::JNativeRunnable, facebook::react::Runnable>::JavaPart, facebook::react::Runnable, void>::_javaobject*>)), facebook::jni::detail::JTypeFor<facebook::jni::HybridClass<facebook::react::JNativeRunnable, facebook::react::Runnable>::JavaPart, facebook::react::Runnable, void>::_javaobject*, void>::call(_JNIEnv*, _jobject*)+52) (BuildId: 879f1a041363d354f938513fc3587fe15467bcf6)
  #49  pc 0x000000000012260c  /data/app/~~cwgn15RzPp5nMLby3wkQSQ==/com.bumbal-OphWlg4hSLEWlliGhEphdg==/oat/arm64/base.odex (art_jni_trampoline+92)
  #50  pc 0x000000000078d870  /system/framework/arm64/boot-framework.oat (android.os.Handler.dispatchMessage+80)
  #51  pc 0x00000000001e9944  /data/app/~~cwgn15RzPp5nMLby3wkQSQ==/com.bumbal-OphWlg4hSLEWlliGhEphdg==/oat/arm64/base.odex (com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage+52)
  #52  pc 0x0000000000790b2c  /system/framework/arm64/boot-framework.oat (android.os.Looper.loopOnce+1036)
  #53  pc 0x0000000000790684  /system/framework/arm64/boot-framework.oat (android.os.Looper.loop+516)
  #54  pc 0x00000000001e9b44  /data/app/~~cwgn15RzPp5nMLby3wkQSQ==/com.bumbal-OphWlg4hSLEWlliGhEphdg==/oat/arm64/base.odex (com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run+324)
  #55  pc 0x00000000001bf2ec  /apex/com.android.art/javalib/arm64/boot.oat (java.lang.Thread.run+76)
  #56  pc 0x0000000000218964  /apex/com.android.art/lib64/libart.so (art_quick_invoke_stub+548)
  #57  pc 0x00000000002851f0  /apex/com.android.art/lib64/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+184)
  #58  pc 0x0000000000628a24  /apex/com.android.art/lib64/libart.so (art::JValue art::InvokeVirtualOrInterfaceWithJValues<art::ArtMethod*>(art::ScopedObjectAccessAlreadyRunnable const&, _jobject*, art::ArtMethod*, jvalue const*)+460)
  #59  pc 0x0000000000678488  /apex/com.android.art/lib64/libart.so (art::Thread::CreateCallback(void*)+1184)
  #60  pc 0x00000000000b4b38  /apex/com.android.runtime/lib64/bionic/libc.so (__pthread_start(void*)+264)
  #61  pc 0x0000000000052c60  /apex/com.android.runtime/lib64/bionic/libc.so (__start_thread+64)

My build.gradle :

apply plugin: "com.android.application"
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'

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 = [
    enableHermes: true,  // clean and rebuild if changing
    bundleInRelease: true,
    resourcesDirRelease: "src/release/res",
]

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

/**
 * 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-intl:+'

/**
 * 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.bumbal"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 160
        versionName "2.2.26"

        // Enabling multidex support.
        multiDexEnabled true

        // for react-native-camera
        missingDimensionStrategy 'react-native-camera', 'general'

        // for react-native-image-crop-picker
        vectorDrawables.useSupportLibrary = true
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
        }
    }
    signingConfigs {    
        release {
            if (project.hasProperty('BB_APP_RELEASE_STORE_FILE')) {
                storeFile file(BB_APP_RELEASE_STORE_FILE)
                storePassword BB_APP_RELEASE_STORE_PASSWORD
                keyAlias BB_APP_RELEASE_KEY_ALIAS
                keyPassword BB_APP_RELEASE_KEY_PASSWORD
            }
        }
    }
    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.release
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }

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

        }
    }

    packagingOptions {
        pickFirst 'lib/x86/libc++_shared.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'
     }
}

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

    implementation 'androidx.work:work-runtime:2.7.1'
    implementation 'androidx.work:work-runtime-ktx:2.7.1'

    implementation "com.google.android.gms:play-services-location:17.0.0"
    api(platform("com.squareup.okhttp3:okhttp-bom:4.8.0"))
    api("com.squareup.okhttp3:okhttp")              // No version!
    api("com.squareup.okhttp3:logging-interceptor") // No version!
    implementation 'com.google.firebase:firebase-analytics:17.5.0'
    implementation 'com.google.firebase:firebase-crashlytics:17.2.1'
    implementation 'com.facebook.soloader:soloader:0.10.4+' // For react-native-camera
    implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"

    implementation "androidx.multidex:multidex:2.0.1"

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

    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 project(':@mauron85_react-native-background-geolocation')
    implementation 'com.github.smtrz:GPSTracker-Android: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 from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
mattbfb commented 7 months ago

Does any of the error information presented (either via the RN app, or adb log) give an indication of the amount of memory being used?

Additionally, I see you're on quite an old version (RN 0.64.4), which makes it trickier to investigate issues. Does this issue still occur on current versions?

atoui-zahreddine commented 7 months ago

Sorry I forgot to mention the error message from google play console :

[split_config.arm64_v8a.apk!libhermes.so] facebook::hermes::HermesRuntimeImpl::call(facebook::jsi::Function const&, facebook::jsi::Value const&, facebook::jsi::Value const*, unsigned long) SIGABRT image

the majority of the crashes happens on Samsung devices .

I couldn't upgrade the project to current versions because It's needs a lot of work on the third party libraries since the project is quite old.

I'm not sure about how I can reproduce the issue, it will very helpful if you guide please.

tmikov commented 7 months ago

This error message indicates that you have attempted to allocate more memory than the configured Hermes GC heap size, so it usually indicates a problem in user code not an engine bug. The heap size is configured using RuntimeConfig/GCConfig.

For Hermes 0.7.2: https://github.com/facebook/hermes/blob/22af9a393845089460afc8322f3c40fb28fc0bce/public/hermes/Public/GCConfig.h#L102

As you can see the default is 512MB, which is probably low these days. However React Native is potentially overwriting the value here: https://github.com/facebook/react-native/blob/0645c38014e8310d8e387dabc860c8c5878beb6e/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/OnLoad.cpp#L45

Which seems to be called from here with 1GB size: https://github.com/facebook/react-native/blob/0645c38014e8310d8e387dabc860c8c5878beb6e/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/HermesExecutorFactory.java#L20

You can try changing these values.

Please, keep in mind that, as our issue template states, we are unable to help debug problems with previous Hermes versions , and we are not experts on React Native, so we can't debug React Native issues at all.

atoui-zahreddine commented 7 months ago

Thanks a lot, this is more then helpful, I'll try to change these values and see if the crash still occurs .

UPDATE : After changing the value to 3gb ( which is unlimited ) the crash is gone

-    this(new RuntimeConfig(1024));
+    this(new RuntimeConfig(3072));

https://github.com/facebook/react-native/blob/0645c38014e8310d8e387dabc860c8c5878beb6e/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/HermesExecutorFactory.java#L20