react-native-mmkv-storage icon indicating copy to clipboard operation
react-native-mmkv-storage copied to clipboard

MMKVNative bindings not installed

Open Ronidey opened this issue 3 years ago • 31 comments

I did exactly how you mentioned in the docs but still getting this error: "MMKVNative bindings not installed"

here is my code

import { MMKVLoader, useMMKVStorage } from "react-native-mmkv-storage";

const MMKV = new MMKVLoader().initialize();

const App = () => {
  const [user, setUser] = useMMKVStorage("user", MMKV, "robert"); // robert is the default value

  return (
    <View>
      <Text>{user}</Text>
    </View>
  );
};

Ronidey avatar Jul 11 '22 16:07 Ronidey

You need to rebuild your native part after installing the package

vvscode avatar Jul 14 '22 08:07 vvscode

You need to rebuild your native part after installing the package

I'm new to react-native could you please explain how am i supposed to do that?

Ronidey avatar Jul 14 '22 09:07 Ronidey

is it when you run iOS part? if so - just rebuild your project in the XCode

vvscode avatar Jul 14 '22 09:07 vvscode

Indeed, it happens to me as well. Without debugging, everything is working. But, when I enable react-native debug mode I receive this error message.

cb-eli avatar Jul 14 '22 09:07 cb-eli

i have a same, when i enable debug in react native, but if i release or run it work fine

minh-dai avatar Jul 21 '22 13:07 minh-dai

Figured it out for IOS at least.

Run the NPM iinstall then from the IOS dir run pod repo update then pod install then you have to add some stuff to a couple files. Then if using Expo run expo run:ios.

In AppDelegate.mm -

  • (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    [MMKV initializeMMKV:nil];

In AppDelegate.h

#import <MMKV/MMKV.h>

dcassese avatar Jul 21 '22 19:07 dcassese

I am running it in the development mode using expo so, how can i go without building it.

sarojregmi200 avatar Jul 31 '22 15:07 sarojregmi200

I am using Expo as well and I ran Expo Prebuild first. That creates the ios and Android folders etc. Then I did the steps I listed above.

dcassese avatar Jul 31 '22 16:07 dcassese

My application isn't complete yet is it ok to make a prebuild of it ? @dcassese

sarojregmi200 avatar Jul 31 '22 16:07 sarojregmi200

@saroj-regmi yes it's okay.

ammarahm-ed avatar Jul 31 '22 18:07 ammarahm-ed

@saroj-regmi yes it's okay.

What is the solution for android??

Ronidey avatar Aug 01 '22 04:08 Ronidey

In your Android / App folder add this to your build.gradle file implementation 'com.tencent:mmkv-static:1.2.13' under the dependencies section

dcassese avatar Aug 01 '22 16:08 dcassese

I get this error when I try to run tests. Is there a way to work around this?

vkundapur avatar Oct 13 '22 12:10 vkundapur

Screenshot 2022-11-10 at 17 35 58

Hey guys, I get this error on both ios and android when I try to run with the react native debugger. I'm using "react-native": "0.70.5",, "react-native-mmkv-storage": "^0.8.0", and React Native Tools: v1.10.0 , without expo and I still get the error. I have tried both fixes presented by @dcassese but non of them work.

Any progress on this?

DenisFeier avatar Nov 10 '22 15:11 DenisFeier

My test suite is failing with the above error. I even followed all the steps the documentation mentioned to mock the library.

biswanathTewari avatar Jan 18 '23 11:01 biswanathTewari

I have exaclty the same problem wich appeared on Firebase recently :

Capture d’écran, le 2023-05-02 à 15 55 09

It's strange because when i debug it, its working, but i endup having this error when i publish my app in the store.

It's only on Android 13. And i have followed all previous steps.

jchesne avatar May 02 '23 13:05 jchesne

I too am getting this error when mocking via the docs for Jest. For now, my workaround is to just mock what I need in the jest/setup.ts file I have

// setup.ts
jest.mock("react-native-mmkv-storage", () => ({
  MMKVLoader: () => ({
    withInstanceID: () => ({
      initialize: () => ({
        getArray: (arr: any[]) => arr,
      }),
    }),
  }),
}));

CoryWritesCode avatar May 16 '23 15:05 CoryWritesCode

Any movement on this? I get this error when trying to use react-native-debugger and on iOS Simulator -> Shake (Dev menu) -> Debug with Chrome. Would love to be able to debug my app!!

ericchen0121 avatar Jul 19 '23 02:07 ericchen0121

I’ve been waiting on these developers to fix this project for almost 2 years. Our company has long since moved on. I suggest finding another solution.

Granted, could I fix it. Yes. Do I have time to, no. Too many other options

JamesC159 avatar Jul 19 '23 03:07 JamesC159

My mock solution for the error when using Jest with typescript:

jest.mock('react-native-mmkv-storage', () => ({
    MMKVLoader: jest.fn().mockImplementation(() => {
        return {
            setAccessibleIOS: jest.fn().mockReturnThis(),
            withEncryption: jest.fn().mockReturnThis(),
            initialize: jest.fn().mockReturnThis(),
        }
    }),
    IOSAccessibleStates: {
        WHEN_UNLOCKED: 'AccessdfdffdfdsfdfsddsfsibleWhenUnlocked',
        AFTER_FIRST_UNLOCK: 'AccessibleAfterFirstUnlock',
        ALWAYS: 'AccessibleAlways',
        WHEN_PASSCODE_SET_THIS_DEVICE_ONLY: 'AccessibleWhenPasscodeSetThisDeviceOnly',
        WHEN_UNLOCKED_THIS_DEVICE_ONLY: 'AccessibleWhenUnlockedThisDeviceOnly',
        AFTER_FIRST_UNLOCK_THIS_DEVICE_ONLY: 'AccessibleAfterFirstUnlockThisDeviceOnly',
        ALWAYS_THIS_DEVICE_ONLY: 'AccessibleAlwaysThisDeviceOnly',
    },
}))

nazmeln avatar Sep 29 '23 19:09 nazmeln

Looks like this error doesn't have solution yet

Eprince-hub avatar Oct 17 '23 22:10 Eprince-hub

My test suite is failing with the above error. I even followed all the steps the documentation mentioned to mock the library.

This mock works for me. This also addresses the TypeError: storage.getItem is not a function error for redux-persist with react-native-mmk-storage as the storage.

jest.mock('react-native-mmkv-storage', () => ({
  MMKVLoader: jest.fn().mockImplementation(() => {
    return {
      setAccessibleIOS: jest.fn().mockReturnThis(),
      withEncryption: () => ({
        initialize: () => ({
          getItem: async () => jest.fn(),
          setItem: async () => jest.fn(),
        }),
      }),
      initialize: () => ({
        getItem: async () => jest.fn(),
        setItem: async () => jest.fn(),
      }),
      withInstanceID: () => ({
        initialize: () => ({
          getItem: async () => jest.fn(),
          setItem: async () => jest.fn(),
        }),
      }),
    };
  }),
  IOSAccessibleStates: {
    WHEN_UNLOCKED: 'AccessibleWhenUnlocked',
    AFTER_FIRST_UNLOCK: 'AccessibleAfterFirstUnlock',
    ALWAYS: 'AccessibleAlways',
    WHEN_PASSCODE_SET_THIS_DEVICE_ONLY:
      'AccessibleWhenPasscodeSetThisDeviceOnly',
    WHEN_UNLOCKED_THIS_DEVICE_ONLY: 'AccessibleWhenUnlockedThisDeviceOnly',
    AFTER_FIRST_UNLOCK_THIS_DEVICE_ONLY:
      'AccessibleAfterFirstUnlockThisDeviceOnly',
    ALWAYS_THIS_DEVICE_ONLY: 'AccessibleAlwaysThisDeviceOnly',
  },
}));

Courtesy: @nazmeln & @CoryWritesCode

Balthazar33 avatar Dec 28 '23 11:12 Balthazar33

I've also been getting this error with expo managed workflow. Anyone find a fix?

cs-manughian avatar Jan 15 '24 04:01 cs-manughian

I also get this error, BUT only when using Expo Go on my actual iPhone. If I open the iOS simulator on my mac it works completely fine. So, for now I can keep working, but I doubt I can ignore this. Does anyone have any ideas?

ryliecc avatar Jan 17 '24 00:01 ryliecc