react-native-mmkv: Android Failed Build

Hi, so I’m getting the following error when building:

[38/38] Linking CXX shared library ..\..\..\..\build\intermediates\cmake\debug\obj\armeabi-v7a\libreactnativemmkv.so
FAILED: ../../../../build/intermediates/cmake/debug/obj/armeabi-v7a/libreactnativemmkv.so
cmd.exe /C "cd . && C:\Users\customer\AppData\Local\Android\Sdk\ndk\21.0.6113669\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=armv7-none-linux-androideabi21 --gcc-toolchain=C:/Users/customer/AppData/Local/Android/Sdk/ndk/21.0.6113669/toolchains/llvm/prebuilt/windows-x86_64 --sysroot=C:/Users/customer/AppData/Local/Android/Sdk/ndk/21.0.6113669/toolchains/llvm/prebuilt/windows-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -march=armv7-a -mthumb -Wformat -Werror=format-security  -fexceptions -frtti -std=c++1y -DONANDROID -O0 -fno-limit-debug-info  -Wl,--exclude-libs,libgcc_real.a -Wl,--exclude-libs,libatomic.a -Wl,--build-id -Wl,--fatal-warnings -Wl,--exclude-libs,libunwind.a -Wl,--no-undefined -Qunused-arguments -shared -Wl,-soname,libreactnativemmkv.so -o ..\..\..\..\build\intermediates\cmake\debug\obj\armeabi-v7a\libreactnativemmkv.so CMakeFiles/reactnativemmkv.dir/src/main/cpp/cpp-adapter.cpp.o CMakeFiles/reactnativemmkv.dir/src/main/cpp/MmkvHostObject.cpp.o -LC:/Hannes/chatable-mobile-app/node_modules/react-native-mmkv/android/build/react-native-0.63.4.aar/jni/armeabi-v7a core/libcore.a -llog -lreactnativejni -landroid C:/Users/customer/AppData/Local/Android/Sdk/ndk/21.0.6113669/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/lib/arm-linux-androideabi/libz.a -latomic -lm && cd ."
../../../../src/main/cpp/cpp-adapter.cpp:10: error: undefined reference to 'facebook::jsi::Value::asString(facebook::jsi::Runtime&) const &'
../../../../src/main/cpp/cpp-adapter.cpp:11: error: undefined reference to 'facebook::jsi::Value::~Value()'
../../../../src/main/cpp/cpp-adapter.cpp:11: error: undefined reference to 'facebook::jsi::Value::~Value()'
../../../../src/main/cpp/cpp-adapter.cpp:25: error: undefined reference to 'facebook::jsi::Value::asObject(facebook::jsi::Runtime&) const &'
C:/Hannes/chatable-mobile-app/android/../node_modules/react-native/ReactCommon/jsi\jsi/jsi.h:1241: error: undefined reference to 'facebook::jsi::JSError::JSError(facebook::jsi::Runtime&, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> >)'
C:/Hannes/chatable-mobile-app/android/../node_modules/react-native/ReactCommon/jsi\jsi/jsi.h:940: error: undefined reference to 'facebook::jsi::Value::~Value()'       
C:/Hannes/chatable-mobile-app/android/../node_modules/react-native/ReactCommon/jsi\jsi/jsi-inl.h:112: error: undefined reference to 'facebook::jsi::Value::~Value()'   
C:/Hannes/chatable-mobile-app/android/../node_modules/react-native/ReactCommon/jsi\jsi/jsi-inl.h:112: error: undefined reference to 'facebook::jsi::Value::~Value()'   
C:/Hannes/chatable-mobile-app/android/../node_modules/react-native/ReactCommon/jsi\jsi/jsi.h:966: error: undefined reference to 'facebook::jsi::Value::~Value()'       
../../../../src/main/cpp/MmkvHostObject.cpp:22: error: undefined reference to 'facebook::jsi::HostObject::~HostObject()'
C:/Hannes/chatable-mobile-app/android/../node_modules/react-native/ReactCommon/jsi\jsi/jsi.h:0: error: undefined reference to 'vtable for facebook::jsi::HostObject'   
C:/Users/customer/AppData/Local/Android/Sdk/ndk/21.0.6113669/toolchains/llvm/prebuilt/windows-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin\ld: the vtable symbol may be undefined because the class is missing its key function
../../../../src/main/cpp/MmkvHostObject.cpp:32: error: undefined reference to 'facebook::jsi::HostObject::~HostObject()'
../../../../src/main/cpp/MmkvHostObject.cpp:32: error: undefined reference to 'facebook::jsi::HostObject::~HostObject()'
C:/Hannes/chatable-mobile-app/android/../node_modules/react-native/ReactCommon/jsi\jsi/jsi.h:940: error: undefined reference to 'facebook::jsi::Value::~Value()'       
C:/Hannes/chatable-mobile-app/android/../node_modules/react-native/ReactCommon/jsi\jsi/jsi.h:961: error: undefined reference to 'facebook::jsi::Value::~Value()'       
CMakeFiles/reactnativemmkv.dir/src/main/cpp/MmkvHostObject.cpp.o:MmkvHostObject.cpp:vtable for MmkvHostObject: error: undefined reference to 'facebook::jsi::HostObject::set(facebook::jsi::Runtime&, facebook::jsi::PropNameID const&, facebook::jsi::Value const&)'
CMakeFiles/reactnativemmkv.dir/src/main/cpp/MmkvHostObject.cpp.o:MmkvHostObject.cpp:typeinfo for MmkvHostObject: error: undefined reference to 'typeinfo for facebook::jsi::HostObject'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

The problem is I’m using Reanimated 2 and WatermelonDB that uses jsi This is how I manually linked them before, will this not work with Mmkv?:

    @Override
    protected JSIModulePackage getJSIModulePackage() {
      return new JSIModulePackage() {
        @Override
        public List<JSIModuleSpec> getJSIModules(final ReactApplicationContext reactApplicationContext,
            final JavaScriptContextHolder jsContext) {
          List<JSIModuleSpec> modules = Arrays.asList();

          modules.addAll(new WatermelonDBJSIPackage().getJSIModules(reactApplicationContext, jsContext));
          modules.addAll(new MmkvModulePackage().getJSIModules(reactApplicationContext, jsContext)); //New
          modules.addAll(new ReanimatedJSIModulePackage().getJSIModules(reactApplicationContext, jsContext));
          return modules;
        }
      };
    }

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 22 (8 by maintainers)

Most upvoted comments

@renanmav adding:

packagingOptions {
        pickFirst 'lib/x86_64/libreactnativejni.so'
        pickFirst 'lib/armeabi-v7a/libreactnativejni.so'
        pickFirst 'lib/arm64-v8a/libreactnativejni.so'
        pickFirst 'lib/x86/libreactnativejni.so'
    }

to android in app/build.gradle fixes the issue for me.

Added react-native-code-push and I started getting this error. I was using version 2.3.3 and build would fail with this error.

C/C++: ninja: error: '../../../../build/react-native-0.68.0.aar/jni/armeabi-v7a/libjsi.so', needed by '../../../../build/intermediates/cxx/RelWithDebInfo/395q2yc5/obj/armeabi-v7a/libreactnativemmkv.so', missing and no known rule to make it

Upgraded to version 2.4.3 and build succeeds, but opening my crashes immediately. This is on react-native 0.68.0. adb logcat shows.

07-10 16:36:14.361  9054  9090 I MMKV    : Loading C++ library...
07-10 16:36:14.365  9054  9090 E ReactNativeJS: Error: Exception in HostFunction: java.lang.UnsatisfiedLinkError: dlopen failed: library "libreactnativemmkv.so" not found, js engine: hermes
07-10 16:36:14.366  9054  9090 E ReactNativeJS: Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication). A frequent cause of the error is that the application entry file path is incorrect.
07-10 16:36:14.366  9054  9090 E ReactNativeJS:       This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native., js engine: hermes
07-10 16:36:14.371  9054  9091 E AndroidRuntime: FATAL EXCEPTION: mqt_native_modules
07-10 16:36:14.371  9054  9091 E AndroidRuntime: Process: com.my_takeouts_delivered, PID: 9054
07-10 16:36:14.371  9054  9091 E AndroidRuntime: com.facebook.react.common.JavascriptException: Error: Exception in HostFunction: java.lang.UnsatisfiedLinkError: dlopen failed: library "libreactnativemmkv.so" not found, js engine: hermes, stack:
07-10 16:36:14.371  9054  9091 E AndroidRuntime: callNativeSyncHook@1:156619
07-10 16:36:14.371  9054  9091 E AndroidRuntime: nonPromiseMethodWrapper@1:153811
07-10 16:36:14.371  9054  9091 E AndroidRuntime: createMMKV@1:2133241
07-10 16:36:14.371  9054  9091 E AndroidRuntime: MMKV@1:2132253
07-10 16:36:14.371  9054  9091 E AndroidRuntime: anonymous@1:2130452
07-10 16:36:14.371  9054  9091 E AndroidRuntime: loadModuleImplementation@1:61272
07-10 16:36:14.371  9054  9091 E AndroidRuntime: guardedLoadModule@1:60821
07-10 16:36:14.371  9054  9091 E AndroidRuntime: metroRequire@1:60449
07-10 16:36:14.371  9054  9091 E AndroidRuntime: anonymous@1:2120893
07-10 16:36:14.371  9054  9091 E AndroidRuntime: loadModuleImplementation@1:61272
07-10 16:36:14.371  9054  9091 E AndroidRuntime: guardedLoadModule@1:60821
07-10 16:36:14.371  9054  9091 E AndroidRuntime: metroRequire@1:60449
07-10 16:36:14.371  9054  9091 E AndroidRuntime: anonymous@1:2117746
07-10 16:36:14.371  9054  9091 E AndroidRuntime: loadModuleImplementation@1:61272
07-10 16:36:14.371  9054  9091 E AndroidRuntime: guardedLoadModule@1:60821
07-10 16:36:14.371  9054  9091 E AndroidRuntime: metroRequire@1:60449
07-10 16:36:14.371  9054  9091 E AndroidRuntime: anonymous@1:1517019
07-10 16:36:14.371  9054  9091 E AndroidRuntime: loadModuleImplementation@1:61272
07-10 16:36:14.371  9054  9091 E AndroidRuntime: guardedLoadModule@1:60821
07-10 16:36:14.371  9054  9091 E AndroidRuntime: metroRequire@1:60449
07-10 16:36:14.371  9054  9091 E AndroidRuntime: anonymous@1:1078792
07-10 16:36:14.371  9054  9091 E AndroidRuntime: loadModuleImplementation@1:61272
07-10 16:36:14.371  9054  9091 E AndroidRuntime: guardedLoadModule@1:60821
07-10 16:36:14.371  9054  9091 E AndroidRuntime: metroRequire@1:60449
07-10 16:36:14.371  9054  9091 E AndroidRuntime: anonymous@1:1077899
07-10 16:36:14.371  9054  9091 E AndroidRuntime: loadModuleImplementation@1:61272
07-10 16:36:14.371  9054  9091 E AndroidRuntime: guardedLoadModule@1:60821
07-10 16:36:14.371  9054  9091 E AndroidRuntime: metroRequire@1:60449
07-10 16:36:14.371  9054  9091 E AndroidRuntime: anonymous@1:882902
07-10 16:36:14.371  9054  9091 E AndroidRuntime: loadModuleImplementation@1:61272
07-10 16:36:14.371  9054  9091 E AndroidRuntime: guardedLoadModule@1:60821
07-10 16:36:14.371  9054  9091 E AndroidRuntime: metroRequire@1:60449
07-10 16:36:14.371  9054  9091 E AndroidRuntime: anonymous@1:572367
07-10 16:36:14.371  9054  9091 E AndroidRuntime: loadModuleImplementation@1:61272
07-10 16:36:14.371  9054  9091 E AndroidRuntime: guardedLoadModule@1:60821
07-10 16:36:14.371  9054  9091 E AndroidRuntime: metroRequire@1:60449
07-10 16:36:14.371  9054  9091 E AndroidRuntime: anonymous@1:67655
07-10 16:36:14.371  9054  9091 E AndroidRuntime: loadModuleImplementation@1:61272
07-10 16:36:14.371  9054  9091 E AndroidRuntime: guardedLoadModule@1:60778
07-10 16:36:14.371  9054  9091 E AndroidRuntime: metroRequire@1:60449
07-10 16:36:14.371  9054  9091 E AndroidRuntime: global@1:60035
07-10 16:36:14.371  9054  9091 E AndroidRuntime:
07-10 16:36:14.371  9054  9091 E AndroidRuntime:        at com.facebook.react.modules.core.ExceptionsManagerModule.reportException(ExceptionsManagerModule.java:72)
07-10 16:36:14.371  9054  9091 E AndroidRuntime:        at java.lang.reflect.Method.invoke(Native Method)
07-10 16:36:14.371  9054  9091 E AndroidRuntime:        at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
07-10 16:36:14.371  9054  9091 E AndroidRuntime:        at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:188)
07-10 16:36:14.371  9054  9091 E AndroidRuntime:        at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
07-10 16:36:14.371  9054  9091 E AndroidRuntime:        at android.os.Handler.handleCallback(Handler.java:938)
07-10 16:36:14.371  9054  9091 E AndroidRuntime:        at android.os.Handler.dispatchMessage(Handler.java:99)
07-10 16:36:14.371  9054  9091 E AndroidRuntime:        at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
07-10 16:36:14.371  9054  9091 E AndroidRuntime:        at android.os.Looper.loop(Looper.java:223)
07-10 16:36:14.371  9054  9091 E AndroidRuntime:        at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:228)
07-10 16:36:14.371  9054  9091 E AndroidRuntime:        at java.lang.Thread.run(Thread.java:923)

I am also getting this error. Is there a fix yet?

@mrousavy yes it is a monorepo. I did manage to create a work around in the build.gradle. I will see if i can have a look at how to make it adaptable.

+1 Facing the same issue on v1.3.1 in a Expo SDK 42 bare project with Reanimated 2 as other JSI package.

@Hannes1 @mrousavy I’ve been having build issues with expo bare as well. I was able to get it to build with the following modification to CMakeLists.txt:

add_library(reactnativemmkv  # <-- Library name
        SHARED
        "${NODE_MODULES_DIR}/react-native/ReactCommon/jsi/jsi/jsi.cpp"
        src/main/cpp/cpp-adapter.cpp
        src/main/cpp/MmkvHostObject.cpp
)

I also had to update the flipper version in my expo app to 0.105.0.

This builds successfully but when I try to use MMKV I get the following error:

[Tue Sep 14 2021 08:00:31.950] ERROR Error: Failed to create a new MMKV instance, the native initializer function does not exist. Is the native MMKV library correctly installed? Make sure to disable any remote debugger (e.g. Chrome) to use JSI!