MMKV

React Native’s fastest key/value store.

  • MMKV is an efficient and small mobile key value storage framework developed by wechat. For more information, see Tencent /MMKV
  • React – Native – MMKV is a library that allows you to easily use MMKV in React Native applications. It provides fast and direct binding to native C++ libraries that can be accessed through simple JS apis.

Liverpoolfc.tv: github.com/mrousavy/re…

The installation

 yarn add react-native-mmkv
Copy the code

or

npm install react-native-mmkv
Copy the code
Manual configuration

Add the // Add tag line in mainApplication.java

import com.reactnativemmkv.MmkvModulePackage; // Add import com.facebook.react.bridge.JSIModulePackage; // Add public class MainApplication extends Application implements ReactApplication { private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { @Override public boolean getUseDeveloperSupport() { return BuildConfig.DEBUG; } @Override protected List<ReactPackage> getPackages() { return new PackageList(this).getPackages(); } @Override protected String getJSMainModuleName() { return "index"; } // Add this method here! @Override protected JSIModulePackage getJSIModulePackage() { return new MmkvModulePackage(); }}; / /...Copy the code

Introduce into the project

Import {MMKV} from 'react-native MMKV '// -- const storage = new MMKV() storage.set('user.name', 'Marc') storage.set('user.age', 21) const username = storage.getString('user.name') // 'Marc' const age = storage.getNumber('user.age') // 21Copy the code

run

After the MMKV is installed, run the yarn Android command to start the project. Running the project for the first time takes a long time and requires patience.

ifyarn androidRun failed

For example, react-native- MMKV :downloadxxx FAILED, usually due to network instability, download the corresponding package access timeout, can be replaced with a more stable and faster response site to try.

If the corresponding package link (eg. github.com/react-nativ…) You can download the file directly from the browser. If the file can be downloaded normally, you can run the YARN Android command several times to retry the file. Sometimes, the file can run successfully.

If the problem cannot be solved by running the yarn android command again, run the./gradlew clean command in the Android directory and clear the node_modules directory. Then run the yarn and yarn android commands again.

If that doesn’t work, delete the build folder in /android and /android/app, and then execute YARN Android

PS D:\code\visitapp-rn> yarn Android yarn run v1.22.17 $react-native run-android info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag. Jetifier found 1168 file(s) to forward-jetify. Using 16 workers... info JS server already running. info Installing the app... WARNING:: Please remove usages of `jcenter()` Maven repository from your build scripts and migrate your build to other Maven repositories. This repository is deprecated and it will be shut down in the future. See http://developer.android.com/r/tools/jcenter-end-of-service for more information. Currently detected usages in: project ':react-native-camera', project ':react-native-mmkv', project ':react-native-pager-view', ... > Task :react-native-mmkv:downloadBoost Download https://github.com/react-native-community/boost-for-react-native/releases/download/v1.63.0-0/boost_1_63_0.tar.gz > Task :react-native-mmkv:downloadBoost FAILED 170 actionable tasks: 4 executed, 166 up-to-date FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':react-native-mmkv:downloadBoost'. > javax.net.ssl.SSLException: Read timed out * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. * Get more help at https://help.gradle.org BUILD FAILED in 2m 58s error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081 FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':react-native-mmkv:downloadBoost'. > javax.net.ssl.SSLException: Read timed out * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. * Get more help at https://help.gradle.org BUILD FAILED in 2m 58s at makeError (D:\code\visitapp-rn\node_modules\execa\index.js:174:9) at D:\code\visitapp-rn\node_modules\execa\index.js:278:16 at processTicksAndRejections (node:internal/process/task_queues:96:5) at async runOnAllDevices (D:\code\visitapp-rn\node_modules\@react-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDevices .js:106:5) at async Command.handleAction (D:\code\visitapp-rn\node_modules\@react-native-community\cli\build\index.js:192:9) info Run CLI with --verbose flag for  more details. error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.Copy the code

Pay attention to

The MMKV cannot run in the React-native debugger, and the following error occurs

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!