Skip to content

Commit 7a643ad

Browse files
Align LiteRT integration with AI Edge Gallery setup
1 parent 84d9f3a commit 7a643ad

2 files changed

Lines changed: 4 additions & 14 deletions

File tree

app/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ dependencies {
111111
// MediaPipe GenAI for offline inference (LLM)
112112
implementation("com.google.mediapipe:tasks-genai:0.10.32")
113113
// LiteRT-LM for newer offline .litertlm models (e.g. Gemma 4 E4B it)
114-
implementation("com.google.ai.edge.litertlm:litertlm-android:0.0.0-alpha06")
114+
implementation("com.google.ai.edge.litertlm:litertlm-android:0.10.0")
115115

116116
// Camera Core to potentially fix missing JNI lib issue
117117
implementation("androidx.camera:camera-core:1.4.0")

app/src/main/kotlin/com/google/ai/sample/feature/multimodal/PhotoReasoningViewModel.kt

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ class PhotoReasoningViewModel(
8686

8787
private var llmInference: LlmInference? = null
8888
private var liteRtEngine: Engine? = null
89-
private var liteRtNativeLoaded = false
9089
private val TAG = "PhotoReasoningViewModel"
9190

9291
// WebRTC & Signaling
@@ -344,11 +343,10 @@ class PhotoReasoningViewModel(
344343
"abis=${Build.SUPPORTED_ABIS?.joinToString() ?: "unknown"}, " +
345344
"modelPath=${modelFile.absolutePath}, modelSizeBytes=${modelFile.length()}"
346345
)
347-
ensureLiteRtNativeLoaded()
348346
if (liteRtEngine == null) {
349-
val liteRtBackend = if (backend == InferenceBackend.GPU) Backend.GPU else Backend.CPU
350-
val visionBackend = Backend.CPU
351-
val audioBackend = Backend.CPU
347+
val liteRtBackend = if (backend == InferenceBackend.GPU) Backend.GPU() else Backend.CPU()
348+
val visionBackend = if (currentModel.supportsScreenshot) Backend.GPU() else null
349+
val audioBackend = null
352350
val engineConfig = EngineConfig(
353351
modelPath = modelFile.absolutePath,
354352
backend = liteRtBackend,
@@ -413,14 +411,6 @@ class PhotoReasoningViewModel(
413411
}
414412
}
415413

416-
private fun ensureLiteRtNativeLoaded() {
417-
if (liteRtNativeLoaded) return
418-
419-
System.loadLibrary("litertlm_jni")
420-
421-
liteRtNativeLoaded = true
422-
}
423-
424414
private fun isLiteRtAbiSupported(): Boolean {
425415
val supportedAbis = Build.SUPPORTED_ABIS?.toSet().orEmpty()
426416
return supportedAbis.contains("arm64-v8a") || supportedAbis.contains("x86_64")

0 commit comments

Comments
 (0)