Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MMKVNative bindings not installed #266

Open
Ronidey opened this issue Jul 11, 2022 · 25 comments
Open

MMKVNative bindings not installed #266

Ronidey opened this issue Jul 11, 2022 · 25 comments

Comments

@Ronidey
Copy link

Ronidey commented Jul 11, 2022

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
Copy link

vvscode commented Jul 14, 2022

You need to rebuild your native part after installing the package

@Ronidey
Copy link
Author

Ronidey commented Jul 14, 2022

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
Copy link

vvscode commented Jul 14, 2022

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

@cb-eli
Copy link

cb-eli commented Jul 14, 2022

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
Copy link

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

@dcassese
Copy link

dcassese commented Jul 21, 2022

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>

@sarojregmi200
Copy link

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

@dcassese
Copy link

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
Copy link

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

@ammarahm-ed
Copy link
Owner

@saroj-regmi yes it's okay.

@Ronidey
Copy link
Author

Ronidey commented Aug 1, 2022

@saroj-regmi yes it's okay.

What is the solution for android??

@dcassese
Copy link

dcassese commented Aug 1, 2022

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
Copy link

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

@DenisFeier
Copy link

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
Copy link

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

@jchesne
Copy link

jchesne commented May 2, 2023

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
Copy link

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
Copy link

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
Copy link

JamesC159 commented Jul 19, 2023

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
Copy link

nazmeln commented Sep 29, 2023

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
Copy link

Looks like this error doesn't have solution yet

@Balthazar33
Copy link

Balthazar33 commented Dec 28, 2023

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
Copy link

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

@ryliecc
Copy link

ryliecc commented Jan 17, 2024

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests