ammarahm-ed / react-native-mmkv-storage

An ultra fast (0.0002s read/write), small & encrypted mobile key-value storage framework for React Native written in C++ using JSI
https://rnmmkv.now.sh
MIT License
1.54k stars 105 forks source link

MMKVNative bindings not installed #266

Open Ronidey opened 2 years ago

Ronidey commented 2 years ago

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>
  );
};
vvscode commented 2 years ago

You need to rebuild your native part after installing the package

Ronidey commented 2 years ago

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?

vvscode commented 2 years ago

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

cb-eli commented 2 years ago

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.

minh-dai commented 1 year ago

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

dcassese commented 1 year ago

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 -

In AppDelegate.h

#import <MMKV/MMKV.h>

sarojregmi200 commented 1 year ago

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

dcassese commented 1 year ago

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.

sarojregmi200 commented 1 year ago

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

ammarahm-ed commented 1 year ago

@saroj-regmi yes it's okay.

Ronidey commented 1 year ago

@saroj-regmi yes it's okay.

What is the solution for android??

dcassese commented 1 year ago

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

vkundapur commented 1 year ago

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

DenisFeier commented 1 year ago

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?

biswanathTewari commented 1 year ago

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

jchesne commented 1 year ago

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.

CoryWritesCode commented 1 year ago

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,
      }),
    }),
  }),
}));
ericchen0121 commented 12 months ago

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!!

JamesC159 commented 12 months ago

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

nazmeln commented 9 months ago

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',
    },
}))
Eprince-hub commented 9 months ago

Looks like this error doesn't have solution yet

Balthazar33 commented 6 months ago

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

cs-manughian commented 6 months ago

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

ryliecc commented 6 months ago

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?

roshanShendre13 commented 2 months ago

Hi,

I have run app with RN Debugger and getting the following error :

Simulator Screenshot - iPhone 15 Pro Max - 2024-05-10 at 08 54 07