Skip to content

android_setup

guoling edited this page Apr 24, 2024 · 24 revisions

MMKV for Android

MMKV is an efficient, small, easy-to-use mobile key-value storage framework used in the WeChat application. It's currently available on both Android, iOS/macOS, Windows and POSIX.

Getting Started

Prerequisites

  • API level 16 and above are supported.
  • NDK r16b and above (should you choose to build MMKV from source)

Installation

  • Via Maven
    Starting from v1.2.8, MMKV has been migrated to Maven Central. Older versions (<= v1.2.7) are still available on JCenter.

    1. Add the following lines to build.gradle on your app module:

      dependencies {
          implementation 'com.tencent:mmkv:1.3.5'
          // replace "1.3.5" with any available version
      }

      This will cause Gradle to download the AAR package while building your application.

    2. By default, MMKV links libc++ with static library. The libc++ will consume about 2 MB size unpacked if shared linked. If you really care about bundle size and your project already includes libc++_shared.so by other JNI libs. You can use MMKV with shared linking of libc++, by adding this line to your Gradle:

      dependencies {
           implementation 'com.tencent:mmkv-shared:1.3.5'
           // replace "1.3.5" with any available version
      }
  • Build from Source
    Starting from v1.2.9, MMKV no longer supports the armeabi arch officially. If you need to support armeabi, you should build MMKV from the source.

    1. Getting source code from the git repository:

      git clone https://github.com/Tencent/MMKV.git
      cd mmkv
    2. Install the latest Android NDK from Android Studio's SDK Manager.
      Note: Starting from NDK r17, ARMv5 (armeabi) is no longer supported. If you need to support the armeabi arch, you should install NDK r16b instead, and uncomment these lines inside Android/MMKV/mmkv/build.gradle:

      // uncomment this line to support armeabi
      // abiFilters 'armeabi', 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
      ...
      // uncomment this line to support armeabi by using android-ndk-r16b
      // ndkVersion = '16.1.4479499'
    3. Open Android/MMKV project in Android Studio and start building, or you can do it in the terminal:

      cd Android/MMKV
      ./gradlew build
    4. If you are pretty sure that encryption is not needed, you can turn on the preprocess directive MMKV_DISABLE_CRYPT in Core/MMKVPredef.h to save some binary size.

    5. If you are pretty sure that MMKV for Flutter is not needed, you can turn on the preprocess directive MMKV_DISABLE_FLUTTER in Core/MMKVPredef.h to save some binary size.

What's next