Skip to content
guoling edited this page Dec 21, 2020 · 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 is MMKV used?
    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 case, the size and length of keys and values is unlimited. However, since MMKV caches everything in memory, if the total size is too big (like 100M+), App may receive memory warning. And write speed might slow down when a full write-back is needed.

  • What is MMKV's usage of FD(file descripter)?
    MMKV is backed by a file which is mmapped into memory. MMKV also relies on a meta file to keep track of CRC32 checksum, storing encryption IR, and coordinating interprocess opetations. 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 meta file. So you have to backup the MMKV data file itself, plus the *.crc meta file.

  • 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 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 opensource 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 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 recover 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