Skip to content
Guo Ling edited this page Feb 9, 2022 · 6 revisions

FAQ

  • When should I use MMKV?
    If those scenarios are seen familiar to you, you should choose MMKV:

    • Your iOS/Android App needs generic key-value storage;
    • You worry about writing efficiency;
    • Inter-process access causing your Android App ANR.
  • Is Swift supported?
    Yes, MMKV is Swift compatible. For detail usage, see demo.

  • Is Kotlin supported?
    Yes, MMKV works perfectly in Java and Kotlin. For detail usage, see demo.

  • What kind of encryption algorithm does MMKV use?
    MMKV uses AES CFB-128 for encryption and decryption, using OpenSSL's implementation (version 1.1.0i). We choose CFB instead of widely used CBC, mainly because MMKV implements insert/update by an append-only operation. Stream encryption algorithms like CFB are more suitable.

  • What're MMKV's limitations?
    MMKV works perfectly well in most cases, the size and length of keys and values are unlimited. However, since MMKV caches everything in memory if the total size is too big (like 100M+), App may receive a memory warning. And write speed might slow down when a full write-back is needed.

  • What is MMKV's usage of FD(file descriptor)?
    MMKV is backed by a file that is mmapped into memory. MMKV also relies on a metafile to keep track of CRC32 checksum, store encryption IR, and coordinate interprocess operations. So each MMKV instance will use two FDs. If you really worry about it, you can close() an instance when you're pretty sure it's not needed anytime soon.

  • How do I backup MMKV's data (and restore/move to another device)?
    As it's been described above, MMKV is backed by one data file and one metafile. So you have to back up the MMKV data file itself, plus the *.crc metafile.

  • Does MMKV for iOS support multi-process accessing?
    Yes, MMKV for iOS adds multi-process support in v1.1.0.

  • What is Ashmem MMKV in Android, and when should I use it?
    Ashmem MMKV in Android is a memory-only, inter-process sharing key-value storage. It vanishes when all processes of the App exit. It doesn't use any file as backing storage. Thus it's suitable for sharing sensitive information among processes of the same App.

  • I'm having java.lang.UnsatisfiedLinkError on Android devices with API level 19. What is that, and what should I do?
    Some Android devices with API level 19 might have problems when installing/updating APK, aka missing libmmkv.so. There's an open-source project ReLinker that fixes this problem. You can use it to load MMKV by calling MMKV.initialize(String rootDir, LibLoader loader). Example code can be found in mmkvdemo.

  • Can I redirect/turn off MMKV's logging?
    Yes. There's an API added to turn off logging & redirect logging in v1.0.17.

  • Why is my MMKV instance not syncing data cross multi-process?
    It's highly possible that you forget to pass multi-process mode. Note that once an MMKV instance is accessed by multi-process, anywhere else that uses that instance must set the multi-process mode as well.
    The simplest way to diagnose this is to set the multi-process mode to everywhere that access this MMKV instance. Check if it happens or not.

  • Why does my MMKV instance lost data after App restart?
    There are some possibilities:

    1. You forget to set the multi-process mode to open a multi-process MMKV instance. Try setting multi-process mode to everywhere that access this MMKV instance. Check if it happens or not.
    2. The file is corrupted. It happens when there's a sudden shutdown of the device. The OS fails to sync data from mmap memory to the file. You can set a recovery strategy, or call sync() manually when you see fit.
    3. There's some unknown bug in MMKV. Create an issue after you have tried the above methods and failed.
  • Why does MMKV crash on my App?
    There are some possibilities:

    1. You forget to set the multi-process mode to open a multi-process MMKV instance. Try setting multi-process mode to everywhere that access this MMKV instance. Check if it happens or not.
    2. There's some unknown bug in MMKV. Create an issue after you have tried the above method and failed.
Clone this wiki locally