Android 개발에 사용할 수 있는 LiteRT 런타임 API는 다음과 같습니다.
CompiledModelAPI: 고성능 추론을 위한 최신 표준으로, CPU/GPU/NPU 전반에서 하드웨어 가속을 간소화합니다. CompiledModel API를 선택해야 하는 이유에 대해 자세히 알아보세요.InterpreterAPI: 하위 호환성을 위해 유지되는 기본 추론 API입니다.
CompiledModel API 시작하기
클래식 ML 모델의 경우 다음 데모 앱을 참고하세요.
- 이미지 세분화 Kotlin 앱: CPU/GPU/NPU 추론
- 이미지 분할 C++ 앱: async 실행을 사용한 CPU/GPU/NPU 추론
생성형 AI 모델의 경우 다음 데모 앱을 참고하세요.
- EmbeddingGemma 시맨틱 유사성 C++ 앱: CPU/GPU/NPU 추론
지원되는 Android 버전 및 API
| LiteRT 버전 | 상태 | 지원되는 API | 최소 SDK 수준 | 최소 NDK 버전 (사용된 경우) | 출시일 |
|---|---|---|---|---|---|
v2.1.0 |
✅ 최신 | CompiledModel Interpreter(CPU만 해당) |
23 (Android 6 Marshmallow) |
r26a |
2025-12-19 |
v2.0.3 |
⚠️ 기존 | CompiledModel |
26 (Android 8 Oreo) |
r26a |
2025-11-08 |
v1.4.1 |
✅ 최신 | Interpreter |
21 (Android 5 Lollipop) |
r26a |
2025-11-07 |
v1.4.0 |
⚠️ 기존 | Interpreter |
26 (Android 8 Oreo) |
r26a |
2025-06-25 |
v1.3.0 |
⚠️ 기존 | Interpreter |
21 (Android 5 Lollipop) |
r26a |
2025-05-19 |
v1.2.0 |
⚠️ 기존 | Interpreter |
21 (Android 5 Lollipop) |
r26a |
2025-03-13 |
중요: 최신 기능 및 보안 업데이트와의 호환성을 위해 종속 항목을 최신 상태로 유지하세요.
CompiledModel API 빠른 시작
Android 프로젝트에 LiteRT Maven 패키지를 추가합니다.
dependencies {
...
implementation `com.google.ai.edge.litert:litert:2.1.0`
}
.tflite 모델을 CompiledModel API와 통합합니다. 다음 코드 스니펫은 Kotlin 및 C++의 기본 구현을 보여줍니다.
Kotlin
// Load model and initialize runtime
val compiledModel = CompiledModel.create(
"/path/to/mymodel.tflite",
CompiledModel.Options(Accelerator.CPU))
// Preallocate input/output buffers
val inputBuffers = compiledModel.createInputBuffers()
val outputBuffers = compiledModel.createOutputBuffers()
// Fill the input buffer
inputBuffers.get(0).writeFloat(input0)
inputBuffers.get(1).writeFloat(input1)
// Invoke
compiledModel.run(inputBuffers, outputBuffers)
// Read the output
val output = outputBuffers.get(0).readFloat()
C++
// Load model and initialize runtime
LITERT_ASSIGN_OR_RETURN(auto env, GetEnvironment());
LITERT_ASSIGN_OR_RETURN(auto options, GetOptions());
LITERT_ASSIGN_OR_RETURN(
auto compiled_model,
CompiledModel::Create(env, "/path/to/mymodel.tflite", options));
// Preallocate input/output buffers
LITERT_ASSIGN_OR_RETURN(auto input_buffers,compiled_model.CreateInputBuffers(signature_index));
LITERT_ASSIGN_OR_RETURN(auto output_buffers,compiled_model.CreateOutputBuffers(signature_index));
// Fill the input buffer
LITERT_ABORT_IF_ERROR(input_buffers[0].Write(input0));
LITERT_ABORT_IF_ERROR(input_buffers[1].Write(input1));
// Invoke
LITERT_ABORT_IF_ERROR(compiled_model.Run(signature_index, input_buffers, output_buffers));
// Read the output
LITERT_ABORT_IF_ERROR(output_buffers[0].Read(output0));