Introducing Google AI Edge Portal: Benchmark Edge AI at scale. Sign-up to request access during private preview.

LiteRT v2 (CompiledModel) C++ SDK for Android

You can also use prebuilt LiteRT Maven packages for your Android C++ libraries without building the entire LiteRT source tree. The integration is done with CMake.

The following shows basic steps to use LiteRT CompiledModel API in your C++ NDK code.

Integrate LiteRT C++ SDK

Choose a folder to host LiteRT C++ SDK. We'll refer to it as <litert_cc_sdk_location>.

  1. Download C++ SDK

    You need to prepare the necessary files (CMakeLists.txt, source and header files) from LiteRT C++ SDK zip file under <litert_cc_sdk_location>.

    wgethttps://github.com/google-ai-edge/LiteRT/releases/download/<litert_version>/litert_cc_sdk.zip
    unziplitert_cc_sdk.zip-d<litert_cc_sdk_location>
    
  2. Place libLiteRt.so from the LiteRT Maven package under <litert_cc_sdk_location>.

    cp<path_to_prebuilt_lib>/libLiteRt.so<litert_cc_sdk_location>/litert_cc_sdk/
    
  3. Update your CMakeLists.txt to use LiteRT API.

    add_subdirectory("<litert_cc_sdk_location>""<litert_cc_sdk_location>/build")
    include_directories("<litert_cc_sdk_location>")
    target_link_libraries(${CMAKE_PROJECT_NAME}
    # Use `litert_cc_api` for LiteRT C++ SDK
    litert_cc_api
    android
    log)
    
  4. Update your build.gradle.kts to configure LiteRT C++ SDK.

     externalNativeBuild {
     cmake {
     path = file("<litert_cc_sdk_location>/CMakeLists.txt")
     version = "3.22.1"
     }
     }
    

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025年12月12日 UTC.